[PATCH] D80925: Fix compiler crash when trying to parse alignment argument as a constant expression.
Alexey Bataev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 1 08:00:38 PDT 2020
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80925.267613.patch
Type: text/x-patch
Size: 1696 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200601/2abc4222/attachment.bin>
More information about the cfe-commits
mailing list