xbolva00 updated this revision to Diff 167857.

https://reviews.llvm.org/D52750

Files:
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaType.cpp
  test/Sema/integer-overflow.c


Index: test/Sema/integer-overflow.c
===================================================================
--- test/Sema/integer-overflow.c
+++ test/Sema/integer-overflow.c
@@ -172,6 +172,9 @@
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
   (void)f2(0, f0(4608 * 1024 * 1024));
 }
+void check_integer_overflows_in_array_size() {
+  int arr[4608 * 1024 * 1024]; // expected-warning {{overflow in expression; 
result is 536870912 with type 'int'}}
+}
 
 struct s {
   unsigned x;
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2228,6 +2228,9 @@
             << ConstVal.toString(10) << ArraySize->getSourceRange();
         return QualType();
       }
+
+      if (isa<BinaryOperator>(ArraySize))
+        ArraySize->EvaluateForOverflow(Context);
     }
 
     T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14043,6 +14043,7 @@
 
   // Circumvent ICE checking in C++11 to avoid evaluating the expression twice
   // in the non-ICE case.
+
   if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) {
     if (Result)
       *Result = E->EvaluateKnownConstInt(Context);


Index: test/Sema/integer-overflow.c
===================================================================
--- test/Sema/integer-overflow.c
+++ test/Sema/integer-overflow.c
@@ -172,6 +172,9 @@
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
   (void)f2(0, f0(4608 * 1024 * 1024));
 }
+void check_integer_overflows_in_array_size() {
+  int arr[4608 * 1024 * 1024]; // expected-warning {{overflow in expression; result is 536870912 with type 'int'}}
+}
 
 struct s {
   unsigned x;
Index: lib/Sema/SemaType.cpp
===================================================================
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -2228,6 +2228,9 @@
             << ConstVal.toString(10) << ArraySize->getSourceRange();
         return QualType();
       }
+
+      if (isa<BinaryOperator>(ArraySize))
+        ArraySize->EvaluateForOverflow(Context);
     }
 
     T = Context.getConstantArrayType(T, ConstVal, ASM, Quals);
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14043,6 +14043,7 @@
 
   // Circumvent ICE checking in C++11 to avoid evaluating the expression twice
   // in the non-ICE case.
+
   if (!getLangOpts().CPlusPlus11 && E->isIntegerConstantExpr(Context)) {
     if (Result)
       *Result = E->EvaluateKnownConstInt(Context);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to