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

David Majnemer david.majnemer at gmail.com
Mon Jun 23 23:07:34 PDT 2014


Closed by commit rL211568 (authored by @majnemer).

http://reviews.llvm.org/D4250

Files:
  cfe/trunk/lib/AST/ExprConstant.cpp
  cfe/trunk/test/CodeGenCXX/PR19955.cpp
  cfe/trunk/test/SemaCXX/PR19955.cpp

Index: cfe/trunk/lib/AST/ExprConstant.cpp
===================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp
+++ cfe/trunk/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: cfe/trunk/test/SemaCXX/PR19955.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/PR19955.cpp
+++ cfe/trunk/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}}
Index: cfe/trunk/test/CodeGenCXX/PR19955.cpp
===================================================================
--- cfe/trunk/test/CodeGenCXX/PR19955.cpp
+++ cfe/trunk/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.10772.patch
Type: text/x-patch
Size: 1484 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140624/fbbd0b41/attachment.bin>


More information about the cfe-commits mailing list