]> granicus.if.org Git - clang/commitdiff
Fix PR11385: A pointer constant expression which has been cast via an integer is
authorRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 16 Nov 2011 07:18:12 +0000 (07:18 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Wed, 16 Nov 2011 07:18:12 +0000 (07:18 +0000)
not safely derived. Don't allow lvalue-to-rvalue conversions on the result of
dereferencing such a pointer.

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

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

index 1451fd111953437691ddc760146443d00ecd200a..699d81715e3c0ece9b30e7aff1b6061b85b7a89a 100644 (file)
@@ -3197,6 +3197,7 @@ bool IntExprEvaluator::VisitCastExpr(const CastExpr *E) {
       if (Info.Ctx.getTypeSize(DestType) != Info.Ctx.getTypeSize(SrcType))
         return false;
 
+      LV.Designator.setInvalid();
       LV.moveInto(Result);
       return true;
     }
index 632457da0916c9395f0461e4bdd544a882372050..094d1ce716089ed1ccf4f6e285f0728b3b34cb16 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify -triple i686-linux %s
 
 #define EVAL_EXPR(testno, expr) int test##testno = sizeof(struct{char qq[expr];});
 int x;
@@ -105,3 +105,6 @@ int weak_int_test = weak_int; // expected-error {{not a compile-time constant}}
 
 int literalVsNull1 = "foo" == 0;
 int literalVsNull2 = 0 == "foo";
+
+// PR11385.
+int castViaInt[*(int*)(unsigned long)"test"]; // expected-error {{variable length array}}