Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert-fail on C++20 paren-agg-init of array type #92284

Open
AMP999 opened this issue May 15, 2024 · 2 comments · May be fixed by #92299
Open

Assert-fail on C++20 paren-agg-init of array type #92284

AMP999 opened this issue May 15, 2024 · 2 comments · May be fixed by #92299
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@AMP999
Copy link
Contributor

AMP999 commented May 15, 2024

https://godbolt.org/z/bns6MrY9E

using T = int[1];
T a(42);

Compile with -std=c++20. Clang assert-fails with the message "Expression result is not a constant array type":

clang++: /root/llvm-project/clang/lib/AST/ExprConstant.cpp:11423: bool {anonymous}::ArrayExprEvaluator::VisitCXXParenListInitExpr(const clang::CXXParenListInitExpr*): Assertion `dyn_cast<ConstantArrayType>(E->getType()) && "Expression result is not a constant array type"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 <source>
1.	<source>:2:8: current parser token ';'
[...]
 #8 0x000070eef7839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00000000075eeb0d clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::ArrayExprEvaluator, bool>::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#10 0x00000000075eecad EvaluateArray(clang::Expr const*, (anonymous namespace)::LValue const&, clang::APValue&, (anonymous namespace)::EvalInfo&) ExprConstant.cpp:0:0
#11 0x00000000075ba5e1 EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) ExprConstant.cpp:0:0
#12 0x00000000075f7393 clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75f7393)
#13 0x00000000074d1382 clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74d1382)
#14 0x00000000074d16d1 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74d16d1)
#15 0x000000000663d505 clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x663d505)
#16 0x0000000006643dca clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6643dca)
[...]

The same crash happens with these variations, all of which are accepted without complaint by GCC:

using Ta = int[2]; Ta a(42);
using Tb = int[2]; Tb b(42,43);
using Tc = int[]; Tc c(42);
using Td = int[]; Td d(42,43);
@EugeneZelenko EugeneZelenko added c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels May 15, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 15, 2024

@llvm/issue-subscribers-clang-frontend

Author: Amirreza Ashouri (AMP999)

https://godbolt.org/z/bns6MrY9E
using T = int[1];
T a(42);

Compile with -std=c++20. Clang assert-fails with the message "Expression result is not a constant array type":

clang++: /root/llvm-project/clang/lib/AST/ExprConstant.cpp:11423: bool {anonymous}::ArrayExprEvaluator::VisitCXXParenListInitExpr(const clang::CXXParenListInitExpr*): Assertion `dyn_cast&lt;ConstantArrayType&gt;(E-&gt;getType()) &amp;&amp; "Expression result is not a constant array type"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 &lt;source&gt;
1.	&lt;source&gt;:2:8: current parser token ';'
[...]
 #<!-- -->8 0x000070eef7839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #<!-- -->9 0x00000000075eeb0d clang::StmtVisitorBase&lt;llvm::make_const_ptr, (anonymous namespace)::ArrayExprEvaluator, bool&gt;::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#<!-- -->10 0x00000000075eecad EvaluateArray(clang::Expr const*, (anonymous namespace)::LValue const&amp;, clang::APValue&amp;, (anonymous namespace)::EvalInfo&amp;) ExprConstant.cpp:0:0
#<!-- -->11 0x00000000075ba5e1 EvaluateInPlace(clang::APValue&amp;, (anonymous namespace)::EvalInfo&amp;, (anonymous namespace)::LValue const&amp;, clang::Expr const*, bool) ExprConstant.cpp:0:0
#<!-- -->12 0x00000000075f7393 clang::Expr::EvaluateAsInitializer(clang::APValue&amp;, clang::ASTContext const&amp;, clang::VarDecl const*, llvm::SmallVectorImpl&lt;std::pair&lt;clang::SourceLocation, clang::PartialDiagnostic&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75f7393)
#<!-- -->13 0x00000000074d1382 clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl&lt;std::pair&lt;clang::SourceLocation, clang::PartialDiagnostic&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74d1382)
#<!-- -->14 0x00000000074d16d1 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl&lt;std::pair&lt;clang::SourceLocation, clang::PartialDiagnostic&gt;&gt;&amp;) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74d16d1)
#<!-- -->15 0x000000000663d505 clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x663d505)
#<!-- -->16 0x0000000006643dca clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6643dca)
[...]

The same crash happens with these variations, all of which are accepted without complaint by GCC:

using Ta = int[2]; Ta a(42);
using Tb = int[2]; Tb b(42,43);
using Tc = int[]; Tc c(42);
using Td = int[]; Td d(42,43);

@llvmbot
Copy link
Collaborator

llvmbot commented May 15, 2024

@llvm/issue-subscribers-c-20

Author: Amirreza Ashouri (AMP999)

https://godbolt.org/z/bns6MrY9E
using T = int[1];
T a(42);

Compile with -std=c++20. Clang assert-fails with the message "Expression result is not a constant array type":

clang++: /root/llvm-project/clang/lib/AST/ExprConstant.cpp:11423: bool {anonymous}::ArrayExprEvaluator::VisitCXXParenListInitExpr(const clang::CXXParenListInitExpr*): Assertion `dyn_cast&lt;ConstantArrayType&gt;(E-&gt;getType()) &amp;&amp; "Expression result is not a constant array type"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 &lt;source&gt;
1.	&lt;source&gt;:2:8: current parser token ';'
[...]
 #<!-- -->8 0x000070eef7839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #<!-- -->9 0x00000000075eeb0d clang::StmtVisitorBase&lt;llvm::make_const_ptr, (anonymous namespace)::ArrayExprEvaluator, bool&gt;::Visit(clang::Stmt const*) ExprConstant.cpp:0:0
#<!-- -->10 0x00000000075eecad EvaluateArray(clang::Expr const*, (anonymous namespace)::LValue const&amp;, clang::APValue&amp;, (anonymous namespace)::EvalInfo&amp;) ExprConstant.cpp:0:0
#<!-- -->11 0x00000000075ba5e1 EvaluateInPlace(clang::APValue&amp;, (anonymous namespace)::EvalInfo&amp;, (anonymous namespace)::LValue const&amp;, clang::Expr const*, bool) ExprConstant.cpp:0:0
#<!-- -->12 0x00000000075f7393 clang::Expr::EvaluateAsInitializer(clang::APValue&amp;, clang::ASTContext const&amp;, clang::VarDecl const*, llvm::SmallVectorImpl&lt;std::pair&lt;clang::SourceLocation, clang::PartialDiagnostic&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x75f7393)
#<!-- -->13 0x00000000074d1382 clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl&lt;std::pair&lt;clang::SourceLocation, clang::PartialDiagnostic&gt;&gt;&amp;, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74d1382)
#<!-- -->14 0x00000000074d16d1 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl&lt;std::pair&lt;clang::SourceLocation, clang::PartialDiagnostic&gt;&gt;&amp;) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x74d16d1)
#<!-- -->15 0x000000000663d505 clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x663d505)
#<!-- -->16 0x0000000006643dca clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6643dca)
[...]

The same crash happens with these variations, all of which are accepted without complaint by GCC:

using Ta = int[2]; Ta a(42);
using Tb = int[2]; Tb b(42,43);
using Tc = int[]; Tc c(42);
using Td = int[]; Td d(42,43);

MitalAshok added a commit to MitalAshok/llvm-project that referenced this issue May 15, 2024
MitalAshok added a commit to MitalAshok/llvm-project that referenced this issue May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants