From: Richard Smith Date: Wed, 16 Nov 2011 07:18:12 +0000 (+0000) Subject: Fix PR11385: A pointer constant expression which has been cast via an integer is X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b755a9da095d2f2f04444797f1e1a9511693815b;p=clang Fix PR11385: A pointer constant expression which has been cast via an integer is 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 --- diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 1451fd1119..699d81715e 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -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; } diff --git a/test/Sema/const-eval.c b/test/Sema/const-eval.c index 632457da09..094d1ce716 100644 --- a/test/Sema/const-eval.c +++ b/test/Sema/const-eval.c @@ -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}}