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,


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,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to