summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorReid Kleckner <reid@kleckner.net>2013-05-20 14:02:37 +0000
committerReid Kleckner <reid@kleckner.net>2013-05-20 14:02:37 +0000
commitb144d366934f3160ff4b1341db47dd15cd2a8c18 (patch)
treeec4ef604035da6ce9174caa61e33a732c8a23d7e /clang/test
parent95935c5de142edf90273dc76ebafb7d09561821e (diff)
downloadbcm5719-llvm-b144d366934f3160ff4b1341db47dd15cd2a8c18.tar.gz
bcm5719-llvm-b144d366934f3160ff4b1341db47dd15cd2a8c18.zip
Implement __declspec(selectany) under -fms-extensions
selectany only applies to externally visible global variables. It has the effect of making the data weak_odr. The MSDN docs suggest that unused definitions can only be dropped at linktime, so Clang uses weak instead of linkonce. MSVC optimizes away references to constant selectany data, so it must assume that there is only one definition, hence weak_odr. Reviewers: espindola Differential Revision: http://llvm-reviews.chandlerc.com/D814 llvm-svn: 182266
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CodeGen/ms-declspecs.c5
-rw-r--r--clang/test/SemaCXX/attr-selectany.cpp33
2 files changed, 38 insertions, 0 deletions
diff --git a/clang/test/CodeGen/ms-declspecs.c b/clang/test/CodeGen/ms-declspecs.c
index 26bdc58ebb7..5dc7787b8fb 100644
--- a/clang/test/CodeGen/ms-declspecs.c
+++ b/clang/test/CodeGen/ms-declspecs.c
@@ -1,5 +1,10 @@
// RUN: %clang_cc1 -triple i386-pc-win32 %s -emit-llvm -fms-compatibility -o - | FileCheck %s
+__declspec(selectany) int x1 = 1;
+const __declspec(selectany) int x2 = 2;
+// CHECK: @x1 = weak_odr global i32 1, align 4
+// CHECK: @x2 = weak_odr constant i32 2, align 4
+
struct __declspec(align(16)) S {
char x;
};
diff --git a/clang/test/SemaCXX/attr-selectany.cpp b/clang/test/SemaCXX/attr-selectany.cpp
new file mode 100644
index 00000000000..0f9776dbf5d
--- /dev/null
+++ b/clang/test/SemaCXX/attr-selectany.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
+// MSVC produces similar diagnostics.
+
+__declspec(selectany) void foo() { } // expected-error{{'selectany' can only be applied to data items with external linkage}}
+
+__declspec(selectany) int x1 = 1;
+
+const __declspec(selectany) int x2 = 2; // expected-error{{'selectany' can only be applied to data items with external linkage}}
+
+extern const __declspec(selectany) int x3 = 3;
+
+extern const int x4;
+const __declspec(selectany) int x4 = 4;
+
+// MSDN says this is incorrect, but MSVC doesn't diagnose it.
+extern __declspec(selectany) int x5;
+
+static __declspec(selectany) int x6 = 2; // expected-error{{'selectany' can only be applied to data items with external linkage}}
+
+// FIXME: MSVC accepts this and makes x7 externally visible and comdat, but keep
+// it as internal and not weak/linkonce.
+static int x7; // expected-note{{previous definition}}
+extern __declspec(selectany) int x7; // expected-warning{{attribute declaration must precede definition}}
+
+int asdf() { return x7; }
+
+class X {
+ public:
+ X(int i) { i++; };
+ int i;
+};
+
+__declspec(selectany) X x(1);
OpenPOWER on IntegriCloud