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

clang crashes at -O0 on x86_64-linux-gnu #111626

Open
bi6c opened this issue Oct 9, 2024 · 0 comments
Open

clang crashes at -O0 on x86_64-linux-gnu #111626

bi6c opened this issue Oct 9, 2024 · 0 comments
Labels
compiler-rt:asan Address sanitizer crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@bi6c
Copy link

bi6c commented Oct 9, 2024

Compiler Explorer: https://godbolt.org/z/74WYz7xW6

<source>:6:25: warning: implicit conversion from 'unsigned int' to 'char' changes value from 3735928559 to -17 [-Wconstant-conversion]
    6 |     *shouldnotcompile = 0xDEADBEEF; // Force compiler error/warning with unaligned memory write attempt, to make it easier for testers and authors.
      |                       ~ ^~~~~~~~~~
LLVM ERROR: out of memory
Allocation 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-trunk/bin/clang -gdwarf-4 -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 -fsanitize=undefined -fsanitize=address -O0 <source>
1.	<eof> parser at end of file
2.	Optimizer
3.	Running pass "asan<>" on module "<source>"
 #0 0x00000000039400a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/clang+0x39400a8)
 #1 0x000000000393e214 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+0x393e214)
 #2 0x0000000003890678 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007ff1e6842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007ff1e68969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007ff1e6842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007ff1e68287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000000000389ae80 out_of_memory_new_handler() ErrorHandling.cpp:0:0
 #8 0x00000000038bce3d llvm::SmallVectorBase<unsigned long>::grow_pod(void*, unsigned long, unsigned long) (/opt/compiler-explorer/clang-trunk/bin/clang+0x38bce3d)
 #9 0x0000000003980274 llvm::GetShadowBytes(llvm::SmallVectorImpl<llvm::ASanStackVariableDescription> const&, llvm::ASanStackFrameLayout const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3980274)
#10 0x0000000003980316 llvm::GetShadowBytesAfterScope(llvm::SmallVectorImpl<llvm::ASanStackVariableDescription> const&, llvm::ASanStackFrameLayout const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3980316)
#11 0x00000000035ec629 (anonymous namespace)::FunctionStackPoisoner::processStaticAllocas() AddressSanitizer.cpp:0:0
#12 0x00000000035efba3 (anonymous namespace)::FunctionStackPoisoner::runOnFunction() AddressSanitizer.cpp:0:0
#13 0x00000000035f2c33 (anonymous namespace)::AddressSanitizer::instrumentFunction(llvm::Function&, llvm::TargetLibraryInfo const*) AddressSanitizer.cpp:0:0
#14 0x00000000035f4855 llvm::AddressSanitizerPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x35f4855)
#15 0x0000000003bc901e llvm::detail::PassModel<llvm::Module, llvm::AddressSanitizerPass, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3bc901e)
#16 0x0000000003313137 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3313137)
#17 0x0000000003bd85eb (anonymous namespace)::EmitAssemblyHelper::RunOptimizationPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&, clang::BackendConsumer*) BackendUtil.cpp:0:0
#18 0x0000000003bdb91f clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3bdb91f)
#19 0x000000000425c554 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x425c554)
#20 0x0000000006228cfc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/clang+0x6228cfc)
#21 0x000000000425cc75 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk/bin/clang+0x425cc75)
#22 0x0000000004524651 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk/bin/clang+0x4524651)
#23 0x00000000044a429b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x44a429b)
#24 0x0000000004608bb3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk/bin/clang+0x4608bb3)
#25 0x0000000000ce032c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk/bin/clang+0xce032c)
#26 0x0000000000cd8d8d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x00000000042a5419 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
#28 0x0000000003890aa3 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-trunk/bin/clang+0x3890aa3)
#29 0x00000000042a5639 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
#30 0x000000000426c87d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-trunk/bin/clang+0x426c87d)
#31 0x000000000426d87d 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+0x426d87d)
#32 0x00000000042772cc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-trunk/bin/clang+0x42772cc)
#33 0x0000000000cdd081 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk/bin/clang+0xcdd081)
#34 0x0000000000bb0634 main (/opt/compiler-explorer/clang-trunk/bin/clang+0xbb0634)
#35 0x00007ff1e6829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#36 0x00007ff1e6829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#37 0x0000000000cd882e _start (/opt/compiler-explorer/clang-trunk/bin/clang+0xcd882e)
clang: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134

Code:

#include <stdio.h>

__attribute__((always_inline))
inline void fail() {
    char* shouldnotcompile = (char*)-512;
    *shouldnotcompile = 0xDEADBEEF; // Force compiler error/warning with unaligned memory write attempt, to make it easier for testers and authors.
}

int main(int argc, char** argv) {
    (void)(argc); // Eliminate \'argc unused\' warning.

    void* arr = __builtin_alloca((sizeof(char) * -1024) + 512); // Cause "argument to ‘__builtin_alloca’ is too large" error with some compilers for educational purposes and create unaligned/offset memory layout (warning).

    char *victim;

#ifdef __LITTLE_ENDIAN__
    victim = ((char*) arr) + 1; // Set a pointer just before our aligned data structure, forcing the possibility of stack alignment warnings.
#else
    victim = ((char*) arr);
#endif
    fail();

    printf("I didn\'t expect to reach this line.\n"); // Only used for error analysis if above warning/error-prone section doesn\'t generate desired effect in compiler messages (should never be executed anyway).

    return 0;
}
@github-actions github-actions bot added the clang Clang issues not falling into any other category label Oct 9, 2024
@EugeneZelenko EugeneZelenko added compiler-rt:asan Address sanitizer crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-rt:asan Address sanitizer crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

2 participants