[PATCH] D22931: Add __declspec code_seg support
Andrew Artz via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 28 12:58:25 PDT 2016
kbdsmoke created this revision.
kbdsmoke added a subscriber: cfe-commits.
kbdsmoke set the repository for this revision to rL LLVM.
clang does not support this by default. By default, if you want to utilize __declspec to assign a SectionAttr to a function, you should use __declspec allocate.
However, this is not valid under MSVC. It works under clang (whether or not that is acceptable should be the subject of another patch request)
To avoid a lot of headaches for everyone here's my solution. Double __declspec in Attr.td works fine, it seems, and so the fix was fairly trivial. I also patch some code to verify code_seg is only ever used on FunctionDecls.
Reason being, without it technically code_seg on variables and so on would be valid.
Repository:
rL LLVM
https://reviews.llvm.org/D22931
Files:
include/clang/Basic/Attr.td
lib/Sema/SemaDeclAttr.cpp
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -2656,6 +2656,10 @@
return;
}
+ // code_seg only ever applies to functions.
+ if (Attr.getName()->getName() == "code_seg" && !isa<FunctionDecl>(D))
+ S.Diag(LiteralLoc, diag::err_attribute_wrong_decl_type) << Attr.getName()->getName() << 0;
+
unsigned Index = Attr.getAttributeSpellingListIndex();
SectionAttr *NewAttr = S.mergeSectionAttr(D, Attr.getRange(), Str, Index);
if (NewAttr)
Index: include/clang/Basic/Attr.td
===================================================================
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -1397,7 +1397,7 @@
}
def Section : InheritableAttr {
- let Spellings = [GCC<"section">, Declspec<"allocate">];
+ let Spellings = [GCC<"section">, Declspec<"allocate">, Declspec<"code_seg">];
let Args = [StringArgument<"Name">];
let Subjects = SubjectList<[Function, GlobalVar,
ObjCMethod, ObjCProperty], ErrorDiag,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22931.65974.patch
Type: text/x-patch
Size: 1102 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160728/12fae84c/attachment.bin>
More information about the cfe-commits
mailing list