<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/112137>112137</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang++] Assertion `!VD->mightBeUsableInConstantExpressions(Info.Ctx)' failed.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:frontend,
crash-on-invalid,
clang:frontend:fuzzer
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
yijan4845
</td>
</tr>
</table>
<pre>
**This testcase is generated by a fuzzer.**
Compiler Explorer: [https://godbolt.org/z/5T1EYWxcv](https://godbolt.org/z/5T1EYWxcv)
This invalid code will crash on Clang Assertion Trunk. It seems that this goes back to clang-11:
```cpp
struct S {
static const int sdm = sdm = 42;
};
extern S *s;
constexpr int e4 = s->sdm;
```
Stack dump:
```
clang++: /root/llvm-project/clang/lib/AST/ExprConstant.cpp:3079: bool evaluateVarDeclInit({anonymous}::EvalInfo&, const clang::Expr*, const clang::VarDecl*, {anonymous}::CallStackFrame*, clang::APValue*&, const {anonymous}::LValue*): Assertion `!VD->mightBeUsableInConstantExpressions(Info.Ctx)' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-11.0.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-10.2.0 -fcolor-diagnostics -fno-crash-diagnostics -O3 <source>
1. <source>:5:26: current parser token ';'
#0 0x00005942a8e23f7e llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x31d6f7e)
#1 0x00005942a8e21d54 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x31d4d54)
#2 0x00005942a8e21fd1 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x31d4fd1)
#3 0x00005942a8d8d9b8 CrashRecoverySignalHandler(int) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x31409b8)
#4 0x00007f5383a42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#5 0x00007f5383a969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#6 0x00007f5383a42476 raise (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#7 0x00007f5383a287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#8 0x00007f5383a2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#9 0x00007f5383a39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#10 0x00005942aba82f02 (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5e35f02)
#11 0x00005942aba838da findCompleteObject((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::AccessKinds, (anonymous namespace)::LValue const&, clang::QualType) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5e368da)
#12 0x00005942abaa68d7 handleLValueToRValueConversion((anonymous namespace)::EvalInfo&, clang::Expr const*, clang::QualType, (anonymous namespace)::LValue const&, clang::APValue&, bool) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5e598d7)
#13 0x00005942abadb0e5 (anonymous namespace)::IntExprEvaluator::VisitCastExpr(clang::CastExpr const*) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5e8e0e5)
#14 0x00005942abaadc3e clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous namespace)::IntExprEvaluator, bool>::Visit(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5e60c3e)
#15 0x00005942aba9cf9e Evaluate(clang::APValue&, (anonymous namespace)::EvalInfo&, clang::Expr const*) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5e4ff9e)
#16 0x00005942abab53e2 EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5e683e2)
#17 0x00005942ababff34 clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic> >&) const (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5e72f34)
#18 0x00005942ab9cac6a clang::VarDecl::evaluateValue(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic> >&) const (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5d7dc6a)
#19 0x00005942aafb5f5a clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5368f5a)
#20 0x00005942aafb7634 clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x536a634)
#21 0x00005942aad686eb clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x511b6eb)
#22 0x00005942aad7b9ec clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x512e9ec)
#23 0x00005942aad52576 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5105576)
#24 0x00005942aad52c11 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.0) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x5105c11)
#25 0x00005942aad572a7 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (.localalias) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x510a2a7)
#26 0x00005942aad57c78 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x510ac78)
#27 0x00005942aad4c9e9 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x50ff9e9)
#28 0x00005942a9dddd38 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x4190d38)
#29 0x00005942a970ae79 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x3abde79)
#30 0x00005942a96c1846 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x3a74846)
#31 0x00005942a97df790 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x3b92790)
#32 0x00005942a6b92c5c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0xf45c5c)
#33 0x00005942a6b8fd98 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0xf42d98)
#34 0x00005942a9581219 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const::'lambda'()>(long) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x3934219)
#35 0x00005942a8d8db3c llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x3140b3c)
#36 0x00005942a9581b36 clang::driver::CC1Command::Execute(llvm::ArrayRef<llvm::Optional<llvm::StringRef> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, bool*) const (.part.0) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x3934b36)
#37 0x00005942a955910c clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x390c10c)
#38 0x00005942a9559a46 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x390ca46)
#39 0x00005942a9562d49 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0x3915d49)
#40 0x00005942a6adc599 main (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0xe8f599)
#41 0x00007f5383a29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#42 0x00007f5383a29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#43 0x00005942a6b8f8ee _start (/opt/compiler-explorer/clang-assertions-11.0.0/bin/clang+++0xf428ee)
clang-11: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 254
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzkWklv4zj2_zTKhbAhkVoPOThO0v_0v4CqqWSqMSeDIp9sdsmihqTSTn36ASl5oeykK-ioDzNAENtc3vLj41tIUq3FugG4DpKbILm9op3ZSHX9In6nTZzHyVUp-ct1gBcBXjxthEYGtG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