Issue 173688
Summary Clang trunk asserts: Expr::EvaluateAsInt called on value-dependent _expression_ during CodeGen constant folding
Labels clang
Assignees
Reporter Theaamadu
    ## Compiler Explorer: https://godbolt.org/z/T7qaxnKxa

- clang start crashing on `Trunk`
- generated by fuzzer

## Console
```console
clang: /root/llvm-project/llvm/tools/clang/lib/AST/ExprConstant.cpp:20522: 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 <source>
1.	<source>:188:1: current parser token 'extern'
2.	<source>:146:1: LLVM IR generation of declaration 'foo'
3.	<source>:146:1: Generating code for declaration 'foo'
 #0 0x00000000042ecab8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42ecab8)
 #1 0x00000000042e9ee4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x42e9ee4)
 #2 0x000000000422ec88 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007d8234642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007d82346969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007d8234642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007d82346287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007d823462871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007d8234639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000007d14192 (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x7d14192)
#10 0x0000000004867b12 clang::CodeGen::CodeGenFunction::ConstantFoldsToSimpleInteger(clang::Expr const*, bool&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4867b12)
#11 0x00000000047fe71c clang::CodeGen::CodeGenFunction::EmitIfStmt(clang::IfStmt const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47fe71c)
#12 0x00000000047f6ff1 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47f6ff1)
#13 0x00000000047ff42b clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x47ff42b)
#14 0x000000000486746e clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x486746e)
#15 0x00000000048788c4 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48788c4)
#16 0x00000000048e67b0 clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48e67b0)
#17 0x00000000048e1454 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48e1454)
#18 0x00000000048e1c33 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x48e1c33)
#19 0x00000000048ed1c3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#20 0x0000000004c509d9 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#21 0x0000000004c41504 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c41504)
#22 0x0000000006a08db4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x6a08db4)
#23 0x0000000004c4dde8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c4dde8)
#24 0x0000000004f446e5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4f446e5)
#25 0x0000000004ec497e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4ec497e)
#26 0x000000000503ea6d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x503ea6d)
#27 0x0000000000de5b4c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xde5b4c)
#28 0x0000000000ddc59a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#29 0x0000000000ddc71d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#30 0x0000000004cc0739 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#31 0x000000000422f124 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x422f124)
#32 0x0000000004cc0d4f clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#33 0x0000000004c81832 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c81832)
#34 0x0000000004c827de clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c827de)
#35 0x0000000004c89c35 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0x4c89c35)
#36 0x0000000000de1f41 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xde1f41)
#37 0x0000000000c8cf94 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xc8cf94)
#38 0x00007d8234629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#39 0x00007d8234629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#40 0x0000000000ddc035 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+0xddc035)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```

## Code
```c
struct
tree_base
{
unsigned
code
:
16
;
unsigned
side_effects_flag
:
1
;
unsigned
constant_flag
:
1
;
unsigned
addressable_flag
:
1
;
unsigned
volatile_flag
:
1
;
unsigned
readonly_flag
:
1
;
unsigned
unsigned_flag
:
1
;
unsigned
asm_written_flag
:
1
;
unsigned
nowarning_flag
:
1
;
unsigned
used_flag
:
1
;
unsigned
nothrow_flag
:
1
;
unsigned
static_flag
:
1
;
unsigned
public_flag
:
1
;
unsigned
private_flag
:
1
;
unsigned
protected_flag
:
1
;
unsigned
deprecated_flag
:
1
;
unsigned
invariant_flag
:
1
;
unsigned
lang_flag_0
:
1
;
unsigned
lang_flag_1
:
1
;
unsigned
lang_flag_2
:
1
;
unsigned
lang_flag_3
:
1
;
unsigned
lang_flag_4
:
1
;
unsigned
lang_flag_5
:
1
;
unsigned
lang_flag_6
:
1
;
unsigned
visited
:
1
;
unsigned
spare1
:
16
;
unsigned
spare2
:
8
;
unsigned
long
a
;
}
;
int
foo
(
struct
tree_base
*
rhs
)
{
if
(
(
{
const
struct
tree_base
*
__t
=
(
rhs
)
;
int
;
}
)
->
readonly_flag
&&
(
rhs
)
->
static_flag
)
return
1
;
return
0
;
}
extern
void
abort
(
void
)
;
int
main
(
)
{
struct
tree_base
t
;
t
.
readonly_flag
=
t
.
static_flag
=
0
;
if
(
foo
(
&
t
)
)
abort
(
)
;
return
0
;
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to