aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDeclAttr.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2012-05-13 02:42:42 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2012-05-13 02:42:42 +0000
commit420efd83934ee78f04d73880e2ed1b7fdef3328c (patch)
treecaddd838d5a5203bfe2cc2115c049543eb5c2998 /lib/Sema/SemaDeclAttr.cpp
parent6565b8ac9fd63e94e0a9c513fe8a9be206405f2b (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/SemaDeclAttr.cpp')
-rw-r--r--lib/Sema/SemaDeclAttr.cpp20
1 files changed, 17 insertions, 3 deletions
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());
}