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

David Majnemer david.majnemer at gmail.com
Mon Jun 23 14:43:49 PDT 2014


  - Add a SemaCXX test for constexpr + dllimport

http://reviews.llvm.org/D4250

Files:
  lib/AST/ExprConstant.cpp
  test/CodeGenCXX/PR19955.cpp
  test/SemaCXX/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"
Index: test/SemaCXX/PR19955.cpp
===================================================================
--- /dev/null
+++ 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}}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4250.10766.patch
Type: text/x-patch
Size: 1361 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140623/99d2366b/attachment.bin>


More information about the cfe-commits mailing list