[PATCH] AST: Address of dllimport variables isn't constant

David Majnemer david.majnemer at gmail.com
Mon Jun 23 00:05:51 PDT 2014


Hi rnk, rsmith,

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.

http://reviews.llvm.org/D4250

Files:
  lib/AST/ExprConstant.cpp
  test/CodeGenCXX/PR19955.cpp

Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -4390,6 +4390,9 @@
       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);
   }
 
Index: test/CodeGenCXX/PR19955.cpp
===================================================================
--- /dev/null
+++ 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"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4250.10738.patch
Type: text/x-patch
Size: 1006 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140623/ffbadba7/attachment.bin>


More information about the cfe-commits mailing list