]> granicus.if.org Git - clang/commitdiff
Handle expressions with non-literal types like ignored expressions if we are supposed...
authorNick Lewycky <nicholas@mxc.ca>
Mon, 1 May 2017 02:03:23 +0000 (02:03 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Mon, 1 May 2017 02:03:23 +0000 (02:03 +0000)
Also fix a crash casting a derived nullptr to a virtual base.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@301785 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/ExprConstant.cpp
test/Sema/integer-overflow.c
test/SemaCXX/constant-expression-cxx11.cpp

index 75bb0cac51b83c2c041f9492da61dcc5ab1d343b..c99ccb6f1fe1aa58645129a0e606be40cd888d7f 100644 (file)
@@ -2169,6 +2169,9 @@ static bool HandleLValueBase(EvalInfo &Info, const Expr *E, LValue &Obj,
   if (!Base->isVirtual())
     return HandleLValueDirectBase(Info, E, Obj, DerivedDecl, BaseDecl);
 
+  if (!Obj.checkNullPointer(Info, E, CSK_Base))
+    return false;
+
   SubobjectDesignator &D = Obj.Designator;
   if (D.Invalid)
     return false;
@@ -9913,8 +9916,11 @@ static bool EvaluateAsRValue(EvalInfo &Info, const Expr *E, APValue &Result) {
   if (E->getType().isNull())
     return false;
 
-  if (!CheckLiteralType(Info, E))
+  if (!CheckLiteralType(Info, E)) {
+    if (Info.noteFailure())
+      EvaluateIgnoredValue(Info, E);
     return false;
+  }
 
   if (!::Evaluate(Result, Info, E))
     return false;
index 62ee33e3d181961ccff27f1a4fedbbad9ec44505..2f5747dd0bf8f456086ec600295a97adef241b0c 100644 (file)
@@ -149,16 +149,16 @@ uint64_t check_integer_overflows(int i) {
 
 // expected-warning@+2 {{overflow in expression; result is 536870912 with type 'int'}}
   uint64_t *b;
-  uint64_t b2 = b[4608 * 1024 * 1024] + 1;
+  (void)b[4608 * 1024 * 1024] + 1;
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
-  int j1 = i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024);
+  (void)(i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024));
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
-  int j2 = -(4608 * 1024 * 1024);
+  (void)(-(4608 * 1024 * 1024));
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
-  uint64_t j3 = b[4608 * 1024 * 1024];
+  (void)b[4608 * 1024 * 1024];
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
   return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));
index 4abbc8e9284796a4058f08ac64382e861ce801d1..2a5e80adf89aecbc805ea7b54f923c9c0713695a 100644 (file)
@@ -60,6 +60,10 @@ namespace DerivedToVBaseCast {
   static_assert((U*)&d == w, "");
   static_assert((U*)&d == x, "");
 
+  // expected-error@+2 {{constexpr variable 'a' must be initialized by a constant expression}}
+  // expected-warning@+1 {{binding dereferenced null pointer to reference has undefined behavior}}
+  constexpr A &a = *((B*)0);  // expected-note {{cannot access base class of null pointer}}
+
   struct X {};
   struct Y1 : virtual X {};
   struct Y2 : X {};