ABataev created this revision. ABataev added reviewers: rjmccall, rsmith. Herald added a project: clang.
Clang crashes when trying to finish function body. MaybeODRUseExprs is not empty because of const static data member parsed in outer evaluation context, upon call for isTypeIdInParens() function. It builds annot_primary_expr, later parsed in ParseConstantExpression() in inner constant expression evaluation context. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D80925 Files: clang/lib/Parse/ParseDecl.cpp clang/test/AST/alignas_maybe_odr_cleanup.cpp Index: clang/test/AST/alignas_maybe_odr_cleanup.cpp =================================================================== --- /dev/null +++ clang/test/AST/alignas_maybe_odr_cleanup.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only %s -ast-dump | FileCheck %s + +struct FOO { + static const int vec_align_bytes = 32; + void foo() { + double a alignas(vec_align_bytes); + ; + } +}; + +// CHECK: AlignedAttr {{.*}} alignas +// CHECK: ConstantExpr {{.+}} 'int' Int: 32 +// CHECK: ImplicitCastExpr {{.*}} 'int' <LValueToRValue> +// CHECK: DeclRefExpr {{.*}} 'const int' lvalue Var {{.*}} 'vec_align_bytes' 'const int' non_odr_use_constant +// CHECK: NullStmt Index: clang/lib/Parse/ParseDecl.cpp =================================================================== --- clang/lib/Parse/ParseDecl.cpp +++ clang/lib/Parse/ParseDecl.cpp @@ -2827,6 +2827,8 @@ /// [C++0x] assignment-expression ...[opt] ExprResult Parser::ParseAlignArgument(SourceLocation Start, SourceLocation &EllipsisLoc) { + EnterExpressionEvaluationContext ConstantEvaluated( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult ER; if (isTypeIdInParens()) { SourceLocation TypeLoc = Tok.getLocation(); @@ -2834,8 +2836,9 @@ SourceRange TypeRange(Start, Tok.getLocation()); ER = Actions.ActOnUnaryExprOrTypeTraitExpr(TypeLoc, UETT_AlignOf, true, Ty.getAsOpaquePtr(), TypeRange); - } else - ER = ParseConstantExpression(); + } else { + ER = ParseConstantExpressionInExprEvalContext(); + } if (getLangOpts().CPlusPlus11) TryConsumeToken(tok::ellipsis, EllipsisLoc);
Index: clang/test/AST/alignas_maybe_odr_cleanup.cpp =================================================================== --- /dev/null +++ clang/test/AST/alignas_maybe_odr_cleanup.cpp @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -fsyntax-only %s -ast-dump | FileCheck %s + +struct FOO { + static const int vec_align_bytes = 32; + void foo() { + double a alignas(vec_align_bytes); + ; + } +}; + +// CHECK: AlignedAttr {{.*}} alignas +// CHECK: ConstantExpr {{.+}} 'int' Int: 32 +// CHECK: ImplicitCastExpr {{.*}} 'int' <LValueToRValue> +// CHECK: DeclRefExpr {{.*}} 'const int' lvalue Var {{.*}} 'vec_align_bytes' 'const int' non_odr_use_constant +// CHECK: NullStmt Index: clang/lib/Parse/ParseDecl.cpp =================================================================== --- clang/lib/Parse/ParseDecl.cpp +++ clang/lib/Parse/ParseDecl.cpp @@ -2827,6 +2827,8 @@ /// [C++0x] assignment-expression ...[opt] ExprResult Parser::ParseAlignArgument(SourceLocation Start, SourceLocation &EllipsisLoc) { + EnterExpressionEvaluationContext ConstantEvaluated( + Actions, Sema::ExpressionEvaluationContext::ConstantEvaluated); ExprResult ER; if (isTypeIdInParens()) { SourceLocation TypeLoc = Tok.getLocation(); @@ -2834,8 +2836,9 @@ SourceRange TypeRange(Start, Tok.getLocation()); ER = Actions.ActOnUnaryExprOrTypeTraitExpr(TypeLoc, UETT_AlignOf, true, Ty.getAsOpaquePtr(), TypeRange); - } else - ER = ParseConstantExpression(); + } else { + ER = ParseConstantExpressionInExprEvalContext(); + } if (getLangOpts().CPlusPlus11) TryConsumeToken(tok::ellipsis, EllipsisLoc);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits