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

Richard Smith richard at metafoo.co.uk
Fri Jun 27 08:34:21 PDT 2014


On Mon, Jun 23, 2014 at 10:59 PM, David Majnemer <david.majnemer at gmail.com>
wrote:

> 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);
>

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.)

     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}}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140627/02713cd2/attachment.html>


More information about the cfe-commits mailing list