r201468 - [Sema] Fix assertion hit while trying to do constant evaluation for a dependent expression

Argyrios Kyrtzidis akyrtzi at gmail.com
Wed Feb 19 20:06:58 PST 2014


On Feb 19, 2014, at 7:26 PM, Richard Smith <richard at metafoo.co.uk> wrote:

> On Sat, Feb 15, 2014 at 10:53 AM, Argyrios Kyrtzidis <akyrtzi at gmail.com> wrote:
> Author: akirtzidis
> Date: Sat Feb 15 12:53:57 2014
> New Revision: 201468
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=201468&view=rev
> Log:
> [Sema] Fix assertion hit while trying to do constant evaluation for a dependent expression
> inside a GNU statement expression.
> 
> rdar://16064952
> 
> Modified:
>     cfe/trunk/lib/AST/ExprConstant.cpp
>     cfe/trunk/test/SemaCXX/constant-expression.cpp
> 
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=201468&r1=201467&r2=201468&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Sat Feb 15 12:53:57 2014
> @@ -8028,6 +8028,8 @@ static bool Evaluate(APValue &Result, Ev
>  /// an object can indirectly refer to subobjects which were initialized earlier.
>  static bool EvaluateInPlace(APValue &Result, EvalInfo &Info, const LValue &This,
>                              const Expr *E, bool AllowNonLiteralTypes) {
> +  if (E->isTypeDependent() || E->isValueDependent())
> +    return false;
> 
> It's the responsibility of the caller of the evaluator to check that the expression isn't value-dependent, not of the evaluator itself (the answer in such a case isn't that the expression is non-constant, it's that the question isn't meaningful). This should be an assert, and the check should be elsewhere. (Also, checking isValueDependent should be sufficient.)

In r201753, thanks for reviewing!

> 
>    if (!AllowNonLiteralTypes && !CheckLiteralType(Info, E, &This))
>      return false;
> 
> 
> Modified: cfe/trunk/test/SemaCXX/constant-expression.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression.cpp?rev=201468&r1=201467&r2=201468&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/constant-expression.cpp (original)
> +++ cfe/trunk/test/SemaCXX/constant-expression.cpp Sat Feb 15 12:53:57 2014
> @@ -133,3 +133,11 @@ namespace test4 {
>    // equivalent to "const int x = 42;" as per C++03 8.5/p13.
>    typedef A<i> Ai; // ok
>  }
> +
> +// rdar://16064952
> +namespace rdar16064952 {
> +  template < typename T > void fn1() {
> +   T b;
> +   unsigned w = ({int a = b.val[sizeof(0)]; 0; }); // expected-warning {{use of GNU statement expression extension}}
> +  }
> +}
> 
> 
> _______________________________________________
> 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/20140219/ba1dcf37/attachment.html>


More information about the cfe-commits mailing list