summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Majnemer <david.majnemer@gmail.com>2014-06-24 05:59:13 +0000
committerDavid Majnemer <david.majnemer@gmail.com>2014-06-24 05:59:13 +0000
commit99ea974909aecf110b60b2d273f7cec97ebc0f11 (patch)
tree1bb2efd3945e6b353633a2fd4ab6105a73e9f21c
parentb5db1b77d8fa80c507665d4c5c3217b0e972d3ed (diff)
downloadclang-99ea974909aecf110b60b2d273f7cec97ebc0f11.tar.gz
clang-99ea974909aecf110b60b2d273f7cec97ebc0f11.tar.bz2
clang-99ea974909aecf110b60b2d273f7cec97ebc0f11.tar.xz
AST: Address of dllimport variables isn't constant
The address of dllimport variables isn't something that can be meaningfully used in a constexpr context and isn't suitable for evaluation at load-time. They require loads from memory to properly evaluate. This fixes PR19955. Differential Revision: http://reviews.llvm.org/D4250 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@211568 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/ExprConstant.cpp3
-rw-r--r--test/CodeGenCXX/PR19955.cpp10
-rw-r--r--test/SemaCXX/PR19955.cpp4
3 files changed, 17 insertions, 0 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp
index c77d5e888a..d25ecd043d 100644
--- a/lib/AST/ExprConstant.cpp
+++ b/lib/AST/ExprConstant.cpp
@@ -4390,6 +4390,9 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
Result.set(VD, Frame->Index);
return true;
}
+ // The address of __declspec(dllimport) variables aren't constant.
+ if (VD->hasAttr<DLLImportAttr>())
+ return ZeroInitialization(E);
return Success(VD);
}
diff --git a/test/CodeGenCXX/PR19955.cpp b/test/CodeGenCXX/PR19955.cpp
new file mode 100644
index 0000000000..7d54ac3899
--- /dev/null
+++ b/test/CodeGenCXX/PR19955.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple i686-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s | FileCheck %s
+
+extern int __declspec(dllimport) x;
+extern long long y;
+// CHECK-DAG: @"\01?y@@3_JA" = global i64 0
+long long y = (long long)&x;
+
+// CHECK-LABEL: @"\01??__Ey@@YAXXZ"
+// CHECK-DAG: @"\01?y@@3_JA"
diff --git a/test/SemaCXX/PR19955.cpp b/test/SemaCXX/PR19955.cpp
new file mode 100644
index 0000000000..81fa70d7f5
--- /dev/null
+++ b/test/SemaCXX/PR19955.cpp
@@ -0,0 +1,4 @@
+// RUN: %clang_cc1 -triple i686-win32 -verify -std=c++11 %s
+
+extern int __attribute__((dllimport)) y;
+constexpr int *x = &y; // expected-error {{must be initialized by a constant expression}}