[PATCH] D33852: Enable __declspec(selectany) on linux

Piotr Padlewski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 4 06:31:57 PDT 2017


Prazek updated this revision to Diff 101352.
Prazek added a comment.

- Fixes


https://reviews.llvm.org/D33852

Files:
  include/clang/Basic/Attr.td
  test/Sema/attr-selectany-not-supported.c
  test/Sema/attr-selectany.c
  test/SemaCXX/attr-selectany.cpp
  utils/TableGen/ClangAttrEmitter.cpp


Index: utils/TableGen/ClangAttrEmitter.cpp
===================================================================
--- utils/TableGen/ClangAttrEmitter.cpp
+++ utils/TableGen/ClangAttrEmitter.cpp
@@ -2659,6 +2659,23 @@
     }
     Test += ")";
   }
+
+  // If one or more CXX ABIs are specified, check those as well.
+  if (!R->isValueUnset("ObjectFormats")) {
+    Test += " && (";
+    std::vector<StringRef> ObjectFormats =
+        R->getValueAsListOfStrings("ObjectFormats");
+    for (auto I = ObjectFormats.begin(), E = ObjectFormats.end(); I != E; ++I) {
+      StringRef Part = *I;
+      Test += "T.getObjectFormat() == llvm::Triple::";
+      Test += Part;
+      if (I + 1 != E)
+        Test += " || ";
+      if (FnName)
+        *FnName += Part;
+    }
+    Test += ")";
+  }
 }
 
 static void GenerateHasAttrSpellingStringSwitch(
Index: test/SemaCXX/attr-selectany.cpp
===================================================================
--- test/SemaCXX/attr-selectany.cpp
+++ test/SemaCXX/attr-selectany.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fms-compatibility -fms-extensions -fsyntax-only -verify -std=c++11 %s
+
 // MSVC produces similar diagnostics.
 
 __declspec(selectany) void foo() { } // expected-error{{'selectany' can only be applied to data items with external linkage}}
Index: test/Sema/attr-selectany.c
===================================================================
--- test/Sema/attr-selectany.c
+++ test/Sema/attr-selectany.c
@@ -1,5 +1,6 @@
 // RUN: %clang_cc1 -triple x86_64-win32 -fdeclspec -verify %s
 // RUN: %clang_cc1 -triple x86_64-mingw32 -verify %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -verify -fdeclspec %s
 
 extern __declspec(selectany) const int x1 = 1; // no warning, const means we need extern in C++
 
Index: test/Sema/attr-selectany-not-supported.c
===================================================================
--- /dev/null
+++ test/Sema/attr-selectany-not-supported.c
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple x86_64-win32-macho -verify -fdeclspec %s
+
+// selectany is not supported for macho object files.
+__declspec(selectany) int x1; // expected-warning{{__declspec attribute 'selectany' is not supported}}
Index: include/clang/Basic/Attr.td
===================================================================
--- include/clang/Basic/Attr.td
+++ include/clang/Basic/Attr.td
@@ -261,6 +261,7 @@
   list<string> Arches = arches;
   list<string> OSes;
   list<string> CXXABIs;
+  list<string> ObjectFormats;
 }
 def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
 def TargetAVR : TargetArch<["avr"]>;
@@ -274,6 +275,10 @@
 def TargetMicrosoftCXXABI : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
   let CXXABIs = ["Microsoft"];
 }
+def TargetWindowsAndLinux : TargetArch<["x86", "x86_64", "arm", "thumb"]> {
+  let OSes = ["Win32", "Linux"];
+  let ObjectFormats = ["COFF", "ELF"];
+}
 
 // Attribute subject match rules that are used for #pragma clang attribute.
 //
@@ -2413,7 +2418,7 @@
   let Documentation = [DLLImportDocs];
 }
 
-def SelectAny : InheritableAttr, TargetSpecificAttr<TargetWindows> {
+def SelectAny : InheritableAttr, TargetSpecificAttr<TargetWindowsAndLinux> {
   let Spellings = [Declspec<"selectany">, GCC<"selectany">];
   let Documentation = [Undocumented];
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33852.101352.patch
Type: text/x-patch
Size: 3423 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170604/d579c1d9/attachment-0001.bin>


More information about the cfe-commits mailing list