summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2014-06-25 22:19:48 +0000
committerHans Wennborg <hans@hanshq.net>2014-06-25 22:19:48 +0000
commit7a08bd78a5be9410fa910961f001e157f68f2e6f (patch)
tree320b485d5c50cea95dba1bcd3fc6130a451b3035 /test
parent85fb905d517e07b0322fee8236e7b3314fb799aa (diff)
downloadclang-7a08bd78a5be9410fa910961f001e157f68f2e6f.tar.gz
clang-7a08bd78a5be9410fa910961f001e157f68f2e6f.tar.bz2
clang-7a08bd78a5be9410fa910961f001e157f68f2e6f.tar.xz
Don't allow dllimport variables in constant initializers
This is a follow-up to David's r211677. For the following code, we would end up referring to 'foo' in the initializer for 'arr', and then fail to link, because 'foo' is dllimport and needs to be accessed through the __imp_?foo. __declspec(dllimport) extern const char foo[]; const char* f() { static const char* const arr[] = { foo }; return arr[0]; } Differential Revision: http://reviews.llvm.org/D4299 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211736 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/CodeGenCXX/dllimport.cpp8
-rw-r--r--test/Parser/MicrosoftExtensions.cpp2
-rw-r--r--test/SemaCXX/PR19955.cpp2
3 files changed, 10 insertions, 2 deletions
diff --git a/test/CodeGenCXX/dllimport.cpp b/test/CodeGenCXX/dllimport.cpp
index 63b119277e..d15eea24f2 100644
--- a/test/CodeGenCXX/dllimport.cpp
+++ b/test/CodeGenCXX/dllimport.cpp
@@ -94,6 +94,14 @@ inline int __declspec(dllimport) inlineStaticLocalsFunc() {
};
USE(inlineStaticLocalsFunc);
+// The address of a dllimport global cannot be used in constant initialization.
+// M32-DAG: @"\01?arr@?0??initializationFunc@@YAPAHXZ@4QBQAHB" = internal global [1 x i32*] zeroinitializer
+// GNU-DAG: @_ZZ18initializationFuncvE3arr = internal global [1 x i32*] zeroinitializer
+int *initializationFunc() {
+ static int *const arr[] = {&ExternGlobalDecl};
+ return arr[0];
+}
+USE(initializationFunc);
//===----------------------------------------------------------------------===//
diff --git a/test/Parser/MicrosoftExtensions.cpp b/test/Parser/MicrosoftExtensions.cpp
index 7f3ef6d903..076de7cd78 100644
--- a/test/Parser/MicrosoftExtensions.cpp
+++ b/test/Parser/MicrosoftExtensions.cpp
@@ -118,7 +118,7 @@ typedef COM_CLASS_TEMPLATE_REF<struct_with_uuid, __uuidof(struct_with_uuid)> COM
COM_CLASS_TEMPLATE_REF<int, __uuidof(struct_with_uuid)> good_template_arg;
-COM_CLASS_TEMPLATE<int, __uuidof(struct_with_uuid)> bad_template_arg; // expected-error {{non-type template argument of type 'const _GUID' is not a constant expression}}
+COM_CLASS_TEMPLATE<int, __uuidof(struct_with_uuid)> bad_template_arg; // expected-error {{non-type template argument of type 'const _GUID' cannot be converted to a value of type 'const GUID *' (aka 'const _GUID *')}}
namespace PR16911 {
struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;
diff --git a/test/SemaCXX/PR19955.cpp b/test/SemaCXX/PR19955.cpp
index 4596e5a459..fb1d74631b 100644
--- a/test/SemaCXX/PR19955.cpp
+++ b/test/SemaCXX/PR19955.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple i686-win32 -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple i686-win32 -fms-compatibility -verify -std=c++11 %s
extern int __attribute__((dllimport)) var;
constexpr int *varp = &var; // expected-error {{must be initialized by a constant expression}}