Prevent shift with negative operands

Shifts with negative operands are undefined behavior

Test: aidl_parser_fuzzer negative_left_shift && atest aidl_unittests
aidl_integration_test
Bug: 168792643

Change-Id: Ifba0e3bcdaa25adc463c35f916ef5e9051bf82f8
diff --git a/aidl_const_expressions.cpp b/aidl_const_expressions.cpp
index 48980f5..a3f45bc 100644
--- a/aidl_const_expressions.cpp
+++ b/aidl_const_expressions.cpp
@@ -101,14 +101,14 @@
   T operator==(T o) { return mValue == o; }
   T operator!=(T o) { return mValue != o; }
   T operator>>(T o) {
-    if (o < 0 || o > static_cast<T>(sizeof(T) * 8)) {
+    if (o < 0 || o > static_cast<T>(sizeof(T) * 8) || mValue < 0) {
       mOverflowed = true;
       return 0;
     }
     return mValue >> o;
   }
   T operator<<(T o) {
-    if (o < 0 || o > static_cast<T>(sizeof(T) * 8)) {
+    if (o < 0 || o > static_cast<T>(sizeof(T) * 8) || mValue < 0) {
       mOverflowed = true;
       return 0;
     }