llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

GlobalOpt crash with opaque-pointers

Open sks75220 opened this issue 4 years ago • 2 comments

We are seeing a new crash since commit 702d5de43, as listed below.

As suggested in the commit message, the crash indeed goes away with "-Xclang -no-opaque-pointers".

That recent commit simply enabled opaque-pointers by default. The bug has existed all the way back since 90ec6dff860, but it needed "-mllvm -opaque-pointers" at that point.

$ cat af.c
__attribute__((constructor)) void art(int args) {}

$ clang -c -O2 af.c
clang: /home/sunil/CLANG-GIT/llvm-project/llvm/include/llvm/ADT/SmallVector.h:277: const T& llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::operator[](llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type) const [with T = llvm::Constant*; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::const_reference = llvm::Constant* const&; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type = long unsigned int]: Assertion `idx < size()' 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: /home/sunil/CLANG-GIT/llvm-project/build/bin/clang -c -O2 af.c
1.      <eof> parser at end of file
2.      Optimizer
#0 0x000056370bc0fe84 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
#1 0x000056370bc0dc0c llvm::sys::CleanupOnSignal(unsigned long) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x3c3ac0c)
#2 0x000056370bb3d678 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007fc5e2f233c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x143c0)
#4 0x00007fc5e29c003b raise /build/glibc-sMfBJT/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
#5 0x00007fc5e299f859 abort /build/glibc-sMfBJT/glibc-2.31/stdlib/abort.c:81:7
#6 0x00007fc5e299f729 get_sysdep_segment_value /build/glibc-sMfBJT/glibc-2.31/intl/loadmsgcat.c:509:8
#7 0x00007fc5e299f729 _nl_load_domain /build/glibc-sMfBJT/glibc-2.31/intl/loadmsgcat.c:970:34
#8 0x00007fc5e29b1006 (/lib/x86_64-linux-gnu/libc.so.6+0x34006)
#9 0x000056370bc959ff llvm::Evaluator::EvaluateFunction(llvm::Function*, llvm::Constant*&, llvm::SmallVectorImpl<llvm::Constant*> const&) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x3cc29ff)
#10 0x000056370b3c8f4d EvaluateStaticConstructor(llvm::Function*, llvm::DataLayout const&, llvm::TargetLibraryInfo*) GlobalOpt.cpp:0:0
#11 0x000056370bc7ea61 llvm::optimizeGlobalCtorsList(llvm::Module&, llvm::function_ref<bool (llvm::Function*)>) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x3caba61)
#12 0x000056370b3d06cf optimizeGlobalsInModule(llvm::Module&, llvm::DataLayout const&, llvm::function_ref<llvm::TargetLibraryInfo& (llvm::Function&)>, llvm::function_ref<llvm::TargetTransformInfo& (llvm::Function&)>, llvm::function_ref<llvm::BlockFrequencyInfo& (llvm::Function&)>, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>) GlobalOpt.cpp:0:0
#13 0x000056370b3d1f3a llvm::GlobalOptPass::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x33fef3a)
#14 0x000056370ceb3946 llvm::detail::PassModel<llvm::Module, llvm::GlobalOptPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x4ee0946)
#15 0x000056370b28832f llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x32b532f)
#16 0x000056370bf9d99f (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> >&) (.constprop.0) BackendUtil.cpp:0:0
#17 0x000056370bfa03e2 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x3fcd3e2)
#18 0x000056370ce48df3 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x4e75df3)
#19 0x000056370dc13bf9 clang::ParseAST(clang::Sema&, bool, bool) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x5c40bf9)
#20 0x000056370ce47798 clang::CodeGenAction::ExecuteAction() (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x4e74798)
#21 0x000056370c7159b9 clang::FrontendAction::Execute() (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x47429b9)
#22 0x000056370c6a122e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x46ce22e)
#23 0x000056370c7f45e3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x48215e3)
#24 0x0000563709220a81 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x124da81)
#25 0x000056370921ce58 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#26 0x000056370c518539 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) Job.cpp:0:0
#27 0x000056370bb3d7fc llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x3b6a7fc)
#28 0x000056370c518c4f 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) Job.cpp:0:0
#29 0x000056370c4e726b clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&) const (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x451426b)
#30 0x000056370c4e7d79 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) const (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x4514d79)
#31 0x000056370c4f1c49 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*> >&) (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x451ec49)
#32 0x000056370917225a main (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x119f25a)
#33 0x00007fc5e29a10b3 __libc_start_main /build/glibc-sMfBJT/glibc-2.31/csu/../csu/libc-start.c:342:3
#34 0x000056370921c9ce _start (/home/sunil/CLANG-GIT/llvm-project/build/bin/clang+0x12499ce)
clang-15: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 15.0.0 (https://github.com/llvm/llvm-project.git 702d5de4380b1e1554e5b90863093c3a57f76f70)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/sunil/CLANG-GIT/llvm-project/build/bin
clang-15: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-15: note: diagnostic msg: /tmp/af-ad9102.c
clang-15: note: diagnostic msg: /tmp/af-ad9102.sh
-----------------------------------------------------------------------------------------------------------------------------------------

Files attached for reference. af-ad9102.zip

sks75220 avatar Apr 27 '22 16:04 sks75220

reduce:

$ cat /tmp/a.ll
@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @art, ptr null }]

define void @art(i32 %args) {
entry:
  ret void
}
$ opt -passes=globalopt -disable-output /tmp/a.ll
crash...

aeubanks avatar Apr 27 '22 20:04 aeubanks

https://reviews.llvm.org/D124553

aeubanks avatar Apr 27 '22 20:04 aeubanks