llvm / llvm/llvm-project

[Clang] Assertion `!isValueDependent() && "Expression evaluator can't be called on a dependent expression."` failed since 17.0

Open
#175,423 5 comments 0 reactions 0 assignees View on GitHub
clang:frontend confirmed crash-on-valid generated by fuzzer regression:17
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

***Generated by fuzzer.***
Clang trunk crashed and goes back to 17.0.
Compiler Explorer: https://godbolt.org/z/j14GaeWPr

## Program
```cpp
#include
template void FuncTemplate() { T; }
template struct Container {
static void Execute() {
if (std::is_same_v)
;
static int InternalVar;
FuncTemplate;
}
};
int main() { Container::Execute; }
```

## Stack Dump
```bash
clang++: /root/llvm-project/llvm/tools/clang/lib/AST/ExprConstant.cpp:20560: bool clang::Expr::EvaluateAsInt(clang::Expr::EvalResult&, const clang::ASTContext&, clang::Expr::SideEffectsKind, bool) const: Assertion `!isValueDependent() && "Expression evaluator can't be called on a dependent expression."' 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++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -w
1. parser at end of file
2. Per-file LLVM IR generation
3. :4:15: Generating code for declaration 'Container::Execute'
#0 0x0000000004309158 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4309158)
#1 0x0000000004306584 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4306584)
#2 0x00000000042492d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x000074b121842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x000074b1218969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#5 0x000074b121842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#6 0x000074b1218287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#7 0x000074b12182871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#8 0x000074b121839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#9 0x0000000007d505e2 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7d505e2)
#10 0x0000000004884bf2 clang::CodeGen::CodeGenFunction::ConstantFoldsToSimpleInteger(clang::Expr const*, bool&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4884bf2)
#11 0x000000000481b90c clang::CodeGen::CodeGenFunction::EmitIfStmt(clang::IfStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x481b90c)
#12 0x0000000004814151 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4814151)
#13 0x000000000481c63b clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x481c63b)
#14 0x0000000004884546 clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4884546)
#15 0x0000000004895b04 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4895b04)
#16 0x0000000004903880 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4903880)
#17 0x00000000048fe4f4 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48fe4f4)
#18 0x000000000490bbac clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x490bbac)
#19 0x000000000490bac8 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x490bac8)
#20 0x000000000490bac8 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x490bac8)
#21 0x000000000490f843 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x490f843)
#22 0x0000000004c6de6e (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#23 0x0000000004c6b885 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c6b885)
#24 0x0000000006a3df1c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a3df1c)
#25 0x0000000004c6c068 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c6c068)
#26 0x0000000004f65455 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f65455)
#27 0x0000000004ee528e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ee528e)
#28 0x000000000505fafd clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x505fafd)
#29 0x0000000000de89de cc1_main(llvm::ArrayRef, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde89de)
#30 0x0000000000ddf3aa ExecuteCC1Tool(llvm::SmallVectorImpl&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr) driver.cpp:0:0
#31 0x0000000000ddf52d int llvm::function_ref&)>::callback_fn&)>(long, llvm::SmallVectorImpl&) driver.cpp:0:0
#32 0x0000000004cdf0a9 void llvm::function_ref::callback_fn>, std::__cxx11::basic_string, std::allocator>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#33 0x0000000004249774 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4249774)
#34 0x0000000004cdf6bf clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__cxx11::basic_string, std::allocator>*, bool*) const (.part.0) Job.cpp:0:0
#35 0x0000000004ca0052 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca0052)
#36 0x0000000004ca0ffe clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca0ffe)
#37 0x0000000004ca8455 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca8455)
#38 0x0000000000de4d51 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xde4d51)
#39 0x0000000000c8f044 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc8f044)
#40 0x000074b121829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#41 0x000074b121829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#42 0x0000000000ddee45 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddee45)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the assertion with the provided C++ program and inspect clang/lib/AST/ExprConstant.cpp around Expr::EvaluateAsInt, then follow CodeGenFunction::ConstantFoldsToSimpleInteger and EmitIfStmt. Determine why a value-dependent expression reaches the evaluator, add a regression test for the reproducer, and verify Clang no longer aborts when compiling it.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.