<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jun 23, 2014 at 10:59 PM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: majnemer<br>
Date: Tue Jun 24 00:59:13 2014<br>
New Revision: 211568<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=211568&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=211568&view=rev</a><br>
Log:<br>
AST: Address of dllimport variables isn't constant<br>
<br>
The address of dllimport variables isn't something that can be<br>
meaningfully used in a constexpr context and isn't suitable for<br>
evaluation at load-time.  They require loads from memory to properly<br>
evaluate.<br>
<br>
This fixes PR19955.<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D4250" target="_blank">http://reviews.llvm.org/D4250</a><br>
<br>
Added:<br>
    cfe/trunk/test/CodeGenCXX/PR19955.cpp<br>
    cfe/trunk/test/SemaCXX/PR19955.cpp<br>
Modified:<br>
    cfe/trunk/lib/AST/ExprConstant.cpp<br>
<br>
Modified: cfe/trunk/lib/AST/ExprConstant.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=211568&r1=211567&r2=211568&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=211568&r1=211567&r2=211568&view=diff</a><br>

==============================================================================<br>
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)<br>
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Jun 24 00:59:13 2014<br>
@@ -4390,6 +4390,9 @@ bool LValueExprEvaluator::VisitVarDecl(c<br>
       Result.set(VD, Frame->Index);<br>
       return true;<br>
     }<br>
+    // The address of __declspec(dllimport) variables aren't constant.<br>
+    if (VD->hasAttr<DLLImportAttr>())<br>
+      return ZeroInitialization(E);<br></blockquote><div><br></div><div>This seems weird; there is no such thing as zero-initialization of an lvalue. Just use 'Error(E)' instead? (Or, better, provide a note explaining why it's non-constant.)</div>
<div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
     return Success(VD);<br>
   }<br>
<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/PR19955.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR19955.cpp?rev=211568&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/PR19955.cpp?rev=211568&view=auto</a><br>

==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/PR19955.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/PR19955.cpp Tue Jun 24 00:59:13 2014<br>
@@ -0,0 +1,10 @@<br>
+// RUN: %clang_cc1 -triple i686-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s | FileCheck %s<br>
+// RUN: %clang_cc1 -triple x86_64-windows-msvc -fno-rtti -emit-llvm -std=c++1y -O0 -o - %s | FileCheck %s<br>
+<br>
+extern int __declspec(dllimport) x;<br>
+extern long long y;<br>
+// CHECK-DAG: @"\01?y@@3_JA" = global i64 0<br>
+long long y = (long long)&x;<br>
+<br>
+// CHECK-LABEL: @"\01??__Ey@@YAXXZ"<br>
+// CHECK-DAG: @"\01?y@@3_JA"<br>
<br>
Added: cfe/trunk/test/SemaCXX/PR19955.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR19955.cpp?rev=211568&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/PR19955.cpp?rev=211568&view=auto</a><br>

==============================================================================<br>
--- cfe/trunk/test/SemaCXX/PR19955.cpp (added)<br>
+++ cfe/trunk/test/SemaCXX/PR19955.cpp Tue Jun 24 00:59:13 2014<br>
@@ -0,0 +1,4 @@<br>
+// RUN: %clang_cc1 -triple i686-win32 -verify -std=c++11 %s<br>
+<br>
+extern int __attribute__((dllimport)) y;<br>
+constexpr int *x = &y; // expected-error {{must be initialized by a constant expression}}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>