| Issue |
233762
|
| Summary |
[clang][bytecode] Possible use-after-free during constant evaluation by ByteCode
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
GKxxUCAS
|
The following code crashes on Clang 22, 23 and trunk when compiled with environment variable `MALLOC_PERTURB_=165` and options `-std=c++20 -fexperimental-new-constant-interpreter`:
```cpp
constexpr void f(long* p) { *p = 9; }
struct x {
long a;
short b;
constexpr void z() { f(&a); }
constexpr void y() {
char g[8192];
{
1 || (0 ?: 0);
short *p = &b, q;
}
}
};
consteval long h() {
x p;
p.y();
p.z();
return p.a;
}
int a = h();
```
The output:
```
<source>:9:15: warning: use of logical '||' with constant operand [-Wconstant-logical-operand]
9 | 1 || (0 ?: 0);
| ^ ~~~~~~~~
<source>:9:15: note: use '|' for a bitwise operation
9 | 1 || (0 ?: 0);
| ^~
| |
<source>:9:15: warning: _expression_ result unused [-Wunused-value]
9 | 1 || (0 ?: 0);
| ~ ^ ~~~~~~~~
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-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 -std=c++20 -fexperimental-new-constant-interpreter <source>
1. <source>:20:12: current parser token ';'
#0 0x0000000003dee908 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3dee908)
#1 0x0000000003dec5ec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3dec5ec)
#2 0x0000000003d29d00 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007b3bdba45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x0000000007b09193 clang::interp::Block::removePointer(clang::interp::Pointer*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x7b09193)
#5 0x0000000007b1099c clang::interp::InterpState::~InterpState() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x7b1099c)
#6 0x00000000078ac631 clang::interp::Context::evaluateAsRValue(clang::interp::EvalSettings const&, clang::Expr const*, clang::APValue&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x78ac631)
#7 0x000000000781b76b clang::Expr::EvaluateAsRValue(clang::Expr::EvalResult&, clang::ASTContext const&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x781b76b)
#8 0x00000000067320f1 TryGetExprRange(clang::ASTContext&, clang::Expr const*, unsigned int, bool, bool) SemaChecking.cpp:0:0
#9 0x0000000006788ebc clang::Sema::CheckImplicitConversion(clang::Expr*, clang::QualType, clang::SourceLocation, bool*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6788ebc)
#10 0x000000000678c5e2 AnalyzeImplicitConversions(clang::Sema&, clang::Expr*, clang::SourceLocation, bool) (.constprop.0) SemaChecking.cpp:0:0
#11 0x000000000678f38d clang::Sema::CheckCompletedExpr(clang::Expr*, clang::SourceLocation, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x678f38d)
#12 0x0000000006b330ad clang::Sema::ActOnFinishFullExpr(clang::Expr*, clang::SourceLocation, bool, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x6b330ad)
#13 0x00000000068f0bb6 clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x68f0bb6)
#14 0x00000000064fa708 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x64fa708)
#15 0x000000000651230c clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x651230c)
#16 0x00000000064b8417 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x64b8417)
#17 0x00000000064b8b87 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x64b8b87)
#18 0x00000000064c42a4 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x64c42a4)
#19 0x00000000064c51d7 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x64c51d7)
#20 0x000000000649e7ea clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x649e7ea)
#21 0x00000000047baa4d clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x47baa4d)
#22 0x0000000004ae7741 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4ae7741)
#23 0x0000000004a79d15 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4a79d15)
#24 0x0000000004bbc3d3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x4bbc3d3)
#25 0x0000000000db8d78 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xdb8d78)
#26 0x0000000000db0c9b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#27 0x0000000000db0d43 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
#28 0x00000000048356a9 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
#29 0x0000000003d2a093 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x3d2a093)
#30 0x00000000048360ed 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
#31 0x00000000047f6082 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x47f6082)
#32 0x00000000047fa3c5 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+++0x47fa3c5)
#33 0x000000000480683c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0x480683c)
#34 0x0000000000db57a1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+++0xdb57a1)
#35 0x0000000000d29d63 main (/opt/compiler-explorer/clang-trunk/bin/clang+++0xd29d63)
#36 0x00007b3bdba2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#37 0x00007b3bdba2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#38 0x0000000000db0745 _start (/opt/compiler-explorer/clang-trunk/bin/clang+++0xdb0745)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Program terminated with signal SIGSEGV (11)
Compiler returned: 139
```
[godbolt](https://godbolt.org/z/j9rh84cjd)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs