Index: include/clang/Basic/Attr.td =================================================================== --- include/clang/Basic/Attr.td +++ include/clang/Basic/Attr.td @@ -261,6 +261,7 @@ list Arches = arches; list OSes; list CXXABIs; + list 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 { +def SelectAny : InheritableAttr, TargetSpecificAttr { let Spellings = [Declspec<"selectany">, GCC<"selectany">]; let Documentation = [Undocumented]; } 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: 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/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: 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 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(