Author: andersca Date: Sun Nov 23 22:41:22 2008 New Revision: 59939 URL: http://llvm.org/viewvc/llvm-project?rev=59939&view=rev Log: The address of a variable is only constant if the variable has global storage.
Modified: cfe/trunk/lib/AST/ExprConstant.cpp cfe/trunk/test/Sema/const-eval.c Modified: cfe/trunk/lib/AST/ExprConstant.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=59939&r1=59938&r2=59939&view=diff ============================================================================== --- cfe/trunk/lib/AST/ExprConstant.cpp (original) +++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Nov 23 22:41:22 2008 @@ -121,7 +121,7 @@ } APValue VisitParenExpr(ParenExpr *E) { return Visit(E->getSubExpr()); } - APValue VisitDeclRefExpr(DeclRefExpr *E) { return APValue(E, 0); } + APValue VisitDeclRefExpr(DeclRefExpr *E); APValue VisitPredefinedExpr(PredefinedExpr *E) { return APValue(E, 0); } APValue VisitCompoundLiteralExpr(CompoundLiteralExpr *E); APValue VisitMemberExpr(MemberExpr *E); @@ -135,6 +135,14 @@ return Result.isLValue(); } +APValue LValueExprEvaluator::VisitDeclRefExpr(DeclRefExpr *E) +{ + if (!E->hasGlobalStorage()) + return APValue(); + + return APValue(E, 0); +} + APValue LValueExprEvaluator::VisitCompoundLiteralExpr(CompoundLiteralExpr *E) { if (E->isFileScope()) return APValue(E, 0); Modified: cfe/trunk/test/Sema/const-eval.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/const-eval.c?rev=59939&r1=59938&r2=59939&view=diff ============================================================================== --- cfe/trunk/test/Sema/const-eval.c (original) +++ cfe/trunk/test/Sema/const-eval.c Sun Nov 23 22:41:22 2008 @@ -20,3 +20,9 @@ unsigned int l_19 = 1; EVAL_EXPR(14, (1 ^ l_19) && 1); // expected-error {{fields must have a constant size}} + +void f() +{ + int a; + EVAL_EXPR(15, (_Bool)&a); // expected-error {{fields must have a constant size}} +} _______________________________________________ cfe-commits mailing list cfe-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits