diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2012-05-13 02:42:42 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2012-05-13 02:42:42 +0000 |
commit | 9869c3a10fdb7cfa77f61e7dfcb571b137eb2569 (patch) | |
tree | 9997e2b2a169f8784c3d41fdac80748a424b90d2 /clang/lib/Sema/SemaDeclAttr.cpp | |
parent | bac0fdbd0b294229952ab62ebc96ede7dd4541a6 (diff) | |
download | bcm5719-llvm-9869c3a10fdb7cfa77f61e7dfcb571b137eb2569.tar.gz bcm5719-llvm-9869c3a10fdb7cfa77f61e7dfcb571b137eb2569.zip |
Produce a warning for mismatched section attributes. Completest pr9356.
llvm-svn: 156727
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 7c290f76eea..947fe7af918 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2286,6 +2286,22 @@ static void handleReqdWorkGroupSize(Sema &S, Decl *D, WGSize[2])); } +bool Sema::mergeSectionAttr(Decl *D, SourceRange Range, bool Inherited, + StringRef Name) { + if (SectionAttr *ExistingAttr = D->getAttr<SectionAttr>()) { + if (ExistingAttr->getName() == Name) + return false; + Diag(ExistingAttr->getLocation(), diag::warn_mismatched_section); + Diag(Range.getBegin(), diag::note_previous_attribute); + return false; + } + SectionAttr *Attr = ::new (Context) SectionAttr(Range, Context, Name); + if (Inherited) + Attr->setInherited(true); + D->addAttr(Attr); + return true; +} + static void handleSectionAttr(Sema &S, Decl *D, const AttributeList &Attr) { // Attribute has no arguments. if (!checkAttributeNumArgs(S, Attr, 1)) @@ -2313,9 +2329,7 @@ static void handleSectionAttr(Sema &S, Decl *D, const AttributeList &Attr) { S.Diag(SE->getLocStart(), diag::err_attribute_section_local_variable); return; } - - D->addAttr(::new (S.Context) SectionAttr(Attr.getRange(), S.Context, - SE->getString())); + S.mergeSectionAttr(D, Attr.getRange(), false, SE->getString()); } |