r211568 - AST: Address of dllimport variables isn't constant

David Majnemer david.majnemer at gmail.com
Mon Jun 23 22:59:14 PDT 2014


Author: majnemer
Date: Tue Jun 24 00:59:13 2014
New Revision: 211568

URL: http://llvm.org/viewvc/llvm-project?rev=211568&view=rev
Log:
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

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

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=211568&r1=211567&r2=211568&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Jun 24 00:59:13 2014
@@ -4390,6 +4390,9 @@ bool LValueExprEvaluator::VisitVarDecl(c
       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);
   }
 

Added: cfe/trunk/test/CodeGenCXX/PR19955.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR19955.cpp?rev=211568&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/PR19955.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/PR19955.cpp Tue Jun 24 00:59:13 2014
@@ -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"

Added: cfe/trunk/test/SemaCXX/PR19955.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR19955.cpp?rev=211568&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/PR19955.cpp (added)
+++ cfe/trunk/test/SemaCXX/PR19955.cpp Tue Jun 24 00:59:13 2014
@@ -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}}





More information about the cfe-commits mailing list