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 | 420efd83934ee78f04d73880e2ed1b7fdef3328c (patch) | |
tree | caddd838d5a5203bfe2cc2115c049543eb5c2998 /lib/Sema | |
parent | 6565b8ac9fd63e94e0a9c513fe8a9be206405f2b (diff) |
Produce a warning for mismatched section attributes. Completest pr9356.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156727 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema')
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaDeclAttr.cpp | 20 |
2 files changed, 20 insertions, 3 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 64caf2bacc..9828c180b1 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1678,6 +1678,9 @@ bool Sema::mergeDeclAttribute(Decl *D, InheritableAttr *Attr) { return mergeFormatAttr(D, FA->getRange(), true, FA->getType(), FA->getFormatIdx(), FA->getFirstArg()); + if (SectionAttr *SA = dyn_cast<SectionAttr>(Attr)) + return mergeSectionAttr(D, SA->getRange(), true, SA->getName()); + if (!DeclHasAttr(D, Attr)) { InheritableAttr *NewAttr = cast<InheritableAttr>(Attr->clone(Context)); NewAttr->setInherited(true); diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 7c290f76ee..947fe7af91 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/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()); } |