diff options
author | Erich Keane <erich.keane@intel.com> | 2018-05-16 13:57:17 +0000 |
---|---|---|
committer | Erich Keane <erich.keane@intel.com> | 2018-05-16 13:57:17 +0000 |
commit | 64144eb194c8eecbc5e7763c1c7c059fb4395861 (patch) | |
tree | 51ff23b3866929d62bdd31e271d6e90d936436e0 /clang/lib/Sema/SemaDeclAttr.cpp | |
parent | 091069c91e8a0fa173df7895502558f645fb7b9c (diff) | |
download | bcm5719-llvm-64144eb194c8eecbc5e7763c1c7c059fb4395861.tar.gz bcm5719-llvm-64144eb194c8eecbc5e7763c1c7c059fb4395861.zip |
Add support for __declspec(code_seg("segname"))
Add support for __declspec(code_seg("segname"))
This patch is built on the existing support for #pragma code_seg. The code_seg
declspec is allowed on functions and classes. The attribute enables the
placement of code into separate named segments, including compiler-generated
members and template instantiations.
For more information, please see the following:
https://msdn.microsoft.com/en-us/library/dn636922.aspx
A new CodeSeg attribute is used instead of adding a new spelling to the existing
Section attribute since they don’t apply to the same Subjects. Section
attributes are also added for the code_seg declspec since they are used for
#pragma code_seg. No CodeSeg attributes are added to the AST.
The patch is written to match with the Microsoft compiler’s behavior even where
that behavior is a little complicated (see https://reviews.llvm.org/D22931, the
Microsoft feedback page is no longer available since MS has removed the page).
That code is in getImplicitSectionAttrFromClass routine.
Diagnostics messages are added to match with the Microsoft compiler for code-seg
attribute mismatches on base and derived classes and virtual overrides.
Differential Revision: https://reviews.llvm.org/D43352
llvm-svn: 332470
Diffstat (limited to 'clang/lib/Sema/SemaDeclAttr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDeclAttr.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index e4532a7e678..7e64b2369b3 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2853,6 +2853,13 @@ static void handleVecTypeHint(Sema &S, Decl *D, const AttributeList &AL) { SectionAttr *Sema::mergeSectionAttr(Decl *D, SourceRange Range, StringRef Name, unsigned AttrSpellingListIndex) { + // Explicit or partial specializations do not inherit + // the code_seg attribute from the primary template. + if (const auto *FD = dyn_cast<FunctionDecl>(D)){ + if (FD->isFunctionTemplateSpecialization()) + return nullptr; + } + if (SectionAttr *ExistingAttr = D->getAttr<SectionAttr>()) { if (ExistingAttr->getName() == Name) return nullptr; @@ -2942,6 +2949,27 @@ static void handleTargetAttr(Sema &S, Decl *D, const AttributeList &AL) { D->addAttr(NewAttr); } +static void handleCodeSegAttr(Sema &S, Decl *D, const AttributeList &AL) { + StringRef Str; + SourceLocation LiteralLoc; + if (!S.checkStringLiteralArgumentAttr(AL, 0, Str, &LiteralLoc)) + return; + if (!S.checkSectionName(LiteralLoc, Str)) + return; + if (const auto *ExistingAttr = D->getAttr<SectionAttr>()) { + if (!ExistingAttr->isImplicit()) { + S.Diag(AL.getLoc(), + ExistingAttr->getName() == Str + ? diag::warn_duplicate_codeseg_attribute + : diag::err_conflicting_codeseg_attribute); + return; + } + D->dropAttr<SectionAttr>(); + } + D->addAttr(::new (S.Context) SectionAttr( + AL.getRange(), S.Context, Str, AL.getAttributeSpellingListIndex())); +} + static void handleCleanupAttr(Sema &S, Decl *D, const AttributeList &AL) { Expr *E = AL.getArgAsExpr(0); SourceLocation Loc = E->getExprLoc(); @@ -6297,6 +6325,9 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, case AttributeList::AT_Uuid: handleUuidAttr(S, D, AL); break; + case AttributeList::AT_CodeSeg: + handleCodeSegAttr(S, D, AL); + break; case AttributeList::AT_MSInheritance: handleMSInheritanceAttr(S, D, AL); break; |