[cfe-commits] r51361 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/Sema/init.c
Eli Friedman
eli.friedman at gmail.com
Tue May 20 20:39:12 PDT 2008
Author: efriedma
Date: Tue May 20 22:39:11 2008
New Revision: 51361
URL: http://llvm.org/viewvc/llvm-project?rev=51361&view=rev
Log:
Fix a couple of bugs found by Neil Booth in the const-ness checking.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/init.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=51361&r1=51360&r2=51361&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue May 20 22:39:11 2008
@@ -1004,8 +1004,13 @@
return cast<CompoundLiteralExpr>(Init)->isFileScope();
case Expr::DeclRefExprClass: {
const Decl *D = cast<DeclRefExpr>(Init)->getDecl();
- if (const VarDecl *VD = dyn_cast<VarDecl>(D))
- return VD->hasGlobalStorage();
+ if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
+ if (VD->hasGlobalStorage())
+ return false;
+ Diag(Init->getExprLoc(),
+ diag::err_init_element_not_constant, Init->getSourceRange());
+ return true;
+ }
if (isa<FunctionDecl>(D))
return false;
Diag(Init->getExprLoc(),
@@ -1032,7 +1037,7 @@
// C99 6.6p9
if (Exp->getOpcode() == UnaryOperator::Deref)
- return CheckAddressConstantExpressionLValue(Exp->getSubExpr());
+ return CheckAddressConstantExpression(Exp->getSubExpr());
Diag(Init->getExprLoc(),
diag::err_init_element_not_constant, Init->getSourceRange());
Modified: cfe/trunk/test/Sema/init.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/init.c?rev=51361&r1=51360&r2=51361&view=diff
==============================================================================
--- cfe/trunk/test/Sema/init.c (original)
+++ cfe/trunk/test/Sema/init.c Tue May 20 22:39:11 2008
@@ -30,3 +30,15 @@
{"OPEN", 1, &cdiff_cmd_open }
};
+// PR2348
+static struct { int z; } s[2];
+int *t = &(*s).z;
+
+// PR2349
+short *a2(void)
+{
+ short int b;
+ static short *bp = &b; // expected-error {{initializer element is not constant}}
+
+ return bp;
+}
More information about the cfe-commits
mailing list