]> granicus.if.org Git - clang/commitdiff
The address of a variable is only constant if the variable has global storage.
authorAnders Carlsson <andersca@mac.com>
Mon, 24 Nov 2008 04:41:22 +0000 (04:41 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 24 Nov 2008 04:41:22 +0000 (04:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59939 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7b927f462882cf0e5be05f50d5d746b5ee9cd958..6cdbc80afa7ab67f784d0b149e384985e5ed3682 100644 (file)
@@ -121,7 +121,7 @@ public:
   }
 
   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 @@ static bool EvaluateLValue(const Expr* E, APValue& Result, EvalInfo &Info) {
   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);
index 67c27d40f218899eab76107b13e9910a964a5e61..e3d63ca94fb3808dffc20a366b21ac83819391de 100644 (file)
@@ -20,3 +20,9 @@ EVAL_EXPR(13, x || 3.0)
 
 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}}
+}