forked from OSchip/llvm-project
Fix a couple of bugs found by Neil Booth in the const-ness checking.
llvm-svn: 51361
This commit is contained in:
parent
bcfa2d75d7
commit
86346ede95
|
@ -1004,8 +1004,13 @@ bool Sema::CheckAddressConstantExpressionLValue(const Expr* Init) {
|
|||
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 @@ bool Sema::CheckAddressConstantExpressionLValue(const Expr* Init) {
|
|||
|
||||
// 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());
|
||||
|
|
|
@ -30,3 +30,15 @@ struct cdiff_cmd commands[] = {
|
|||
{"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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue