diff options
| author | Chris Lattner <sabre@nondot.org> | 2010-10-10 18:16:20 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2010-10-10 18:16:20 +0000 |
| commit | 88fdea8ad9b7b8e695320732b61a028014e49184 (patch) | |
| tree | 2def806accec3e352dea438df6badfb40ac2015b /clang/lib/Sema/SemaDecl.cpp | |
| parent | 001b29ccc1ee5d0a884c90f30a9660f1f4b360cf (diff) | |
| download | bcm5719-llvm-88fdea8ad9b7b8e695320732b61a028014e49184.tar.gz bcm5719-llvm-88fdea8ad9b7b8e695320732b61a028014e49184.zip | |
fix PR8217, a silent miscompilation of invalid code.
llvm-svn: 116166
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 8efd49580f0..424e6d19a46 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1591,7 +1591,6 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) { /// no declarator (e.g. "struct foo;") is parsed. Decl *Sema::ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS) { - // FIXME: Error on auto/register at file scope // FIXME: Error on inline/virtual/explicit // FIXME: Warn on useless __thread // FIXME: Warn on useless const/volatile @@ -2686,7 +2685,7 @@ static void SetNestedNameSpecifier(DeclaratorDecl *DD, Declarator &D) { } NamedDecl* -Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, +Sema::ActOnVariableDeclarator(Scope *S, Declarator &D, DeclContext *DC, QualType R, TypeSourceInfo *TInfo, LookupResult &Previous, MultiTemplateParamsArg TemplateParamLists, @@ -2821,7 +2820,7 @@ Sema::ActOnVariableDeclarator(Scope* S, Declarator& D, DeclContext* DC, ProcessDeclAttributes(S, NewVD, D); // Handle GNU asm-label extension (encoded as an attribute). - if (Expr *E = (Expr*) D.getAsmLabel()) { + if (Expr *E = (Expr*)D.getAsmLabel()) { // The parser guarantees this is a string. StringLiteral *SE = cast<StringLiteral>(E); NewVD->addAttr(::new (Context) AsmLabelAttr(SE->getStrTokenLoc(0), @@ -2991,7 +2990,7 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, // This includes arrays of objects with address space qualifiers, but not // automatic variables that point to other address spaces. // ISO/IEC TR 18037 S5.1.2 - if (NewVD->hasLocalStorage() && (T.getAddressSpace() != 0)) { + if (NewVD->hasLocalStorage() && T.getAddressSpace() != 0) { Diag(NewVD->getLocation(), diag::err_as_qualified_auto_decl); return NewVD->setInvalidDecl(); } @@ -2999,7 +2998,7 @@ void Sema::CheckVariableDeclaration(VarDecl *NewVD, if (NewVD->hasLocalStorage() && T.isObjCGCWeak() && !NewVD->hasAttr<BlocksAttr>()) Diag(NewVD->getLocation(), diag::warn_attribute_weak_on_local); - + bool isVM = T->isVariablyModifiedType(); if (isVM || NewVD->hasAttr<CleanupAttr>() || NewVD->hasAttr<BlocksAttr>()) @@ -4326,6 +4325,17 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init, bool DirectInit) { Init->setType(DclT); } + + // If this variable is a local declaration with record type, make sure it + // doesn't have a flexible member initialization. We only support this as a + // global/static definition. + if (VDecl->hasLocalStorage()) + if (const RecordType *RT = VDecl->getType()->getAs<RecordType>()) + if (RT->getDecl()->hasFlexibleArrayMember() && isa<InitListExpr>(Init)) { + Diag(VDecl->getLocation(), diag::err_nonstatic_flexible_variable); + VDecl->setInvalidDecl(); + } + // Check any implicit conversions within the expression. CheckImplicitConversions(Init, VDecl->getLocation()); |

