]> granicus.if.org Git - clang/commitdiff
[AST] Don't crash when comparing incomplete object
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 29 Aug 2015 08:32:55 +0000 (08:32 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 29 Aug 2015 08:32:55 +0000 (08:32 +0000)
We cannot tell if an object is past-the-end if its type is incomplete.
Zero sized objects satisfy past-the-end criteria and our object might
turn out to be such an object.

This fixes PR24622.

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

lib/AST/ExprConstant.cpp
test/Sema/const-eval.c

index 6350ff1d8408c02ff8dc1671d22be123e8964c59..8aea10d516e9ae790eb40b8d1138692b502be39f 100644 (file)
@@ -6602,9 +6602,15 @@ static bool isOnePastTheEndOfCompleteObject(const ASTContext &Ctx,
       !LV.getLValueDesignator().isOnePastTheEnd())
     return false;
 
+  // A pointer to an incomplete type might be past-the-end if the type's size is
+  // zero.  We cannot tell because the type is incomplete.
+  QualType Ty = getType(LV.getLValueBase());
+  if (Ty->isIncompleteType())
+    return true;
+
   // We're a past-the-end pointer if we point to the byte after the object,
   // no matter what our type or path is.
-  auto Size = Ctx.getTypeSizeInChars(getType(LV.getLValueBase()));
+  auto Size = Ctx.getTypeSizeInChars(Ty);
   return LV.getLValueOffset() == Size;
 }
 
index 317173a43bba67c68ce1aacf157f81cce86e902a..bfb58bc573e1e4abea4d97f395a63ee152848ccb 100644 (file)
@@ -133,3 +133,7 @@ EVAL_EXPR(51, 0 != (float)1e99)
 
 // PR21945
 void PR21945() { int i = (({}), 0l); }
+
+void PR24622();
+struct PR24622 {} pr24622;
+EVAL_EXPR(52, &pr24622 == (void *)&PR24622); // expected-error {{must have a constant size}}