[cfe-commits] r162835 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/init.c
Richard Smith
richard at metafoo.co.uk
Wed Aug 29 02:05:34 PDT 2012
On Wed, Aug 29, 2012 at 1:44 AM, Hans Wennborg <hans at hanshq.net> wrote:
> Author: hans
> Date: Wed Aug 29 03:44:49 2012
> New Revision: 162835
>
> URL: http://llvm.org/viewvc/llvm-project?rev=162835&view=rev
> Log:
> The address of a TLS var is not compile-time constant (PR13720)
>
> This makes Clang produce an error for code such as:
>
> __thread int x;
> int *p = &x;
>
> The lvalue of a thread-local variable cannot be evaluated at compile
> time.
>
> Modified:
> cfe/trunk/lib/AST/ExprConstant.cpp
> cfe/trunk/test/Sema/init.c
>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=162835&r1=162834&r2=162835&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Aug 29 03:44:49 2012
> @@ -2832,6 +2832,8 @@
> }
>
> bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
> + if (VD->isThreadSpecified())
> + return false;
>
That should be 'return Error(E);' (constant expression evaluation shouldn't
fail without producing a diagnostic). As a testcase, we should reject this:
__thread int n;
constexpr int &f() { return n; }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120829/1523364e/attachment.html>
More information about the cfe-commits
mailing list