diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Parse/AttributeList.cpp | 5 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 21 |
3 files changed, 30 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 7b939e29706..7192e9db2f2 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -259,6 +259,9 @@ static void SetGlobalValueAttributes(const Decl *D, // should not be munged. GV->setName("\01" + ALA->getLabel()); } + + if (const SectionAttr *SA = D->getAttr<SectionAttr>()) + GV->setSection(SA->getName()); } void CodeGenModule::SetFunctionAttributes(const Decl *D, @@ -653,6 +656,9 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { } } + if (const SectionAttr *SA = D->getAttr<SectionAttr>()) + GV->setSection(SA->getName()); + // Emit global variable debug information. CGDebugInfo *DI = getDebugInfo(); if(DI) { diff --git a/clang/lib/Parse/AttributeList.cpp b/clang/lib/Parse/AttributeList.cpp index 954e93e056a..c540da74f15 100644 --- a/clang/lib/Parse/AttributeList.cpp +++ b/clang/lib/Parse/AttributeList.cpp @@ -69,11 +69,12 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) { break; case 7: if (!memcmp(Str, "aligned", 7)) return AT_aligned; - if (!memcmp(Str, "nothrow", 7)) return AT_nothrow; + if (!memcmp(Str, "cleanup", 7)) return AT_cleanup; if (!memcmp(Str, "nonnull", 7)) return AT_nonnull; + if (!memcmp(Str, "nothrow", 7)) return AT_nothrow; if (!memcmp(Str, "objc_gc", 7)) return AT_objc_gc; + if (!memcmp(Str, "section", 7)) return AT_section; if (!memcmp(Str, "stdcall", 7)) return AT_stdcall; - if (!memcmp(Str, "cleanup", 7)) return AT_cleanup; break; case 8: if (!memcmp(Str, "annotate", 8)) return AT_annotate; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index b4e3dd99ac7..c27df2bdeb1 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -784,6 +784,26 @@ static void HandleDLLExportAttr(Decl *d, const AttributeList &Attr, Sema &S) { d->addAttr(new DLLExportAttr()); } +static void HandleSectionAttr(Decl *d, const AttributeList &Attr, Sema &S) { + // Attribute has no arguments. + if (Attr.getNumArgs() != 1) { + S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1; + return; + } + + // Make sure that there is a string literal as the sections's single + // argument. + StringLiteral *SE = + dyn_cast<StringLiteral>(static_cast<Expr *>(Attr.getArg(0))); + if (!SE) { + // FIXME + S.Diag(Attr.getLoc(), diag::err_attribute_annotate_no_string); + return; + } + d->addAttr(new SectionAttr(std::string(SE->getStrData(), + SE->getByteLength()))); +} + static void HandleStdCallAttr(Decl *d, const AttributeList &Attr, Sema &S) { // Attribute has no arguments. if (Attr.getNumArgs() != 0) { @@ -1306,6 +1326,7 @@ static void ProcessDeclAttribute(Decl *D, const AttributeList &Attr, Sema &S) { case AttributeList::AT_noreturn: HandleNoReturnAttr (D, Attr, S); break; case AttributeList::AT_nothrow: HandleNothrowAttr (D, Attr, S); break; case AttributeList::AT_packed: HandlePackedAttr (D, Attr, S); break; + case AttributeList::AT_section: HandleSectionAttr (D, Attr, S); break; case AttributeList::AT_stdcall: HandleStdCallAttr (D, Attr, S); break; case AttributeList::AT_unavailable: HandleUnavailableAttr(D, Attr, S); break; case AttributeList::AT_unused: HandleUnusedAttr (D, Attr, S); break; |