Abe Skolnik via llvm-dev
2016-Aug-04 18:27 UTC
[llvm-dev] help please: how to sort the contents of a "SymbolTableListTraits<GlobalVariable>"?
Dear sir, Thanks for your reply. I apologize for taking a few days to reply.> Crashed how?Please see the below.> Have you turned on ASan?Not yet, but thanks for the suggestion. I guess I will try to rebuild my modified Clang+LLVM with addr. san. and see what happens.> I recommend attaching a minimal reproduction...Well, since I`m hacking on LLVM itself, this is not 100% trivial. I will explain. The first hurdle I had to overcome was the fact that the "GlobalVariable" class had an explicitly-deleted copy ctor and no move ctor. I dealt with this by writing a copy ctor; I`ll paste that in below. A perhaps-important point is that I don`t know _why_ the "GlobalVariable" class had an explicitly-deleted copy ctor and no move ctor. As an experiment, I moved forward with the hypothesis that this was simply because neither was needed at the time and the default [i.e. compiler-inserted] copy ctor would have been wrong. I hope the one _I_ wrote is _right_. ;-)> I assume you can reproduce this in a unit test?Well, it doesn`t take a long program-under-compilation to make this fail. As before, I will paste something in after my sign-off. Regards, Abe ----- added near the end of "OptimizeGlobalVars" in "llvm/lib/Transforms/IPO/GlobalOpt.cpp", amongst many other things I added to that routine ----- struct GV_alignment_comparator { bool operator()(const GlobalVariable& L, const GlobalVariable& R) { return L.getAlignment() < R.getAlignment(); } }; if (unsorted) { M.getGlobalList().sort( GV_alignment_comparator() ); Changed = true; } ----- added to "llvm/lib/IR/Globals.cpp" [and commented out the relevant deletion in "llvm/include/llvm/IR/GlobalVariable.h"] ----- GlobalVariable::GlobalVariable(const GlobalVariable& GV) : GlobalVariable( GV.getValueType(), GV.isConstant(), GV.getLinkage() ) { // copy ctor copyAttributesFrom(&GV); } main_with_3_globals.c --------------------- int foo; char bar; long baz; int main(){return foo;} ----- error dump from compiler driver -----> ../build_003/bin/clang main_with_3_globals.c -O3Abe was here: max. profitable alignment: 16 Abe was here: found a global value that DOES have a name [“foo”], with alignment 4, no named section [double-check: should be empty string: “”], which is a pointer to a NON-array and with pointee type getTypeStoreSize -> 4 Abe was here: found a global value that DOES have a name [“bar”], with alignment 1, no named section [double-check: should be empty string: “”], which is a pointer to a NON-array and with pointee type getTypeStoreSize -> 1 Abe was here: found a global value that DOES have a name [“baz”], with alignment 8, no named section [double-check: should be empty string: “”], which is a pointer to a NON-array and with pointee type getTypeStoreSize -> 8 ===== Abe was here: the globals above are NOT in ascending-alignment order. ====0 clang-3.9 0x0000000002853ebc llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60 1 clang-3.9 0x00000000028543a9 2 clang-3.9 0x0000000002852a83 llvm::sys::RunSignalHandlers() + 131 3 clang-3.9 0x00000000028546f4 4 libpthread.so.0 0x00007fc595318330 5 clang-3.9 0x00000000027fbe12 llvm::StringMapImpl::LookupBucketFor(llvm::StringRef) + 466 6 clang-3.9 0x0000000002320fa4 7 clang-3.9 0x0000000002320a10 llvm::ValueSymbolTable::reinsertValue(llvm::Value*) + 112 8 clang-3.9 0x00000000022f0551 llvm::SymbolTableListTraits<llvm::GlobalVariable>::transferNodesFromList(llvm::SymbolTableListTraits<llvm::GlobalVariable>&, llvm::ilist_iterator<llvm::GlobalVariable>, llvm::ilist_iterator<llvm::GlobalVariable>) + 273 9 clang-3.9 0x00000000023b1fd9 10 clang-3.9 0x00000000023b1c45 11 clang-3.9 0x00000000023a8e40 12 clang-3.9 0x000000000239e77c 13 clang-3.9 0x000000000239d88e 14 clang-3.9 0x00000000023a9f8c 15 clang-3.9 0x00000000022ac02a 16 clang-3.9 0x00000000022abb56 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 342 17 clang-3.9 0x00000000022ac541 llvm::legacy::PassManager::run(llvm::Module&) + 33 18 clang-3.9 0x0000000002adf7c5 19 clang-3.9 0x0000000002adeda6 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) + 150 20 clang-3.9 0x00000000035d622f 21 clang-3.9 0x0000000004259504 clang::ParseAST(clang::Sema&, bool, bool) + 820 22 clang-3.9 0x00000000030f011a clang::ASTFrontendAction::ExecuteAction() + 314 23 clang-3.9 0x00000000035d4bf5 clang::CodeGenAction::ExecuteAction() + 2357 24 clang-3.9 0x00000000030efc00 clang::FrontendAction::Execute() + 112 25 clang-3.9 0x0000000003094c81 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1025 26 clang-3.9 0x0000000003241ba1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1473 27 clang-3.9 0x0000000000c33bc8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 920 28 clang-3.9 0x0000000000c27c2a 29 clang-3.9 0x0000000000c26ae2 main + 2642 30 libc.so.6 0x00007fc593e80f45 __libc_start_main + 245 31 clang-3.9 0x0000000000c25f44 Stack dump: 0. Program arguments: /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name main_with_3_globals.c -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -momit-leaf-frame-pointer -dwarf-column-info -debugger-tuning=gdb -resource-dir /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0 -internal-isystem /usr/local/include -internal-isystem /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -fdebug-compilation-dir /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp -ferror-limit 19 -fmessage-length 144 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /tmp/main_with_3_globals-cef92e.o -x c main_with_3_globals.c 1. <eof> parser at end of file 2. Per-module optimization passes 3. Running pass 'Global Variable Optimizer' on module 'main_with_3_globals.c'. clang-3.9: error: unable to execute command: Segmentation fault clang-3.9: error: clang frontend command failed due to signal (use -v to see invocation) clang version 3.9.0 Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp/../build_003/bin clang-3.9: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. clang-3.9: note: diagnostic msg: ******************** PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-3.9: note: diagnostic msg: /tmp/main_with_3_globals-841619.c clang-3.9: note: diagnostic msg: /tmp/main_with_3_globals-841619.sh clang-3.9: note: diagnostic msg: ******************** GDB backtrace from the "-cc1" part of another run of the same-as-the-preceding compilation attempt -------------------------------------------------------------------------------------------------- Program received signal SIGSEGV, Segmentation fault. 0x00000000027fbe12 in llvm::StringMapImpl::LookupBucketFor (this=0x82f00e8, Name=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Support/StringMap.cpp:102 102 } else if (LLVM_LIKELY(HashTable[BucketNo] == FullHashValue)) { (gdb) bt #0 0x00000000027fbe12 in llvm::StringMapImpl::LookupBucketFor (this=0x82f00e8, Name=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Support/StringMap.cpp:102 #1 0x0000000002320fa4 in llvm::StringMap<llvm::Value*, llvm::MallocAllocator>::insert (this=0x82f00e8, KeyValue=0x8312cb0) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/StringMap.h:345 #2 0x0000000002320a10 in llvm::ValueSymbolTable::reinsertValue (this=0x82f00e8, V=0x830cfd8) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/ValueSymbolTable.cpp:59 #3 0x00000000022f0551 in llvm::SymbolTableListTraits<llvm::GlobalVariable>::transferNodesFromList (this=0x7fffffffabd8, L2=..., first=..., last=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/SymbolTableListTraitsImpl.h:102 #4 0x00000000023b1fd9 in llvm::iplist<llvm::GlobalVariable, llvm::SymbolTableListTraits<llvm::GlobalVariable> >::transfer ( this=0x7fffffffabd8, position=..., L2=..., first=..., last=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:532 #5 0x00000000023b1c45 in llvm::iplist<llvm::GlobalVariable, llvm::SymbolTableListTraits<llvm::GlobalVariable> >::splice (this=0x7fffffffabd8, where=..., L2=..., first=..., last=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:587 #6 0x00000000023a8e40 in llvm::iplist<llvm::GlobalVariable, llvm::SymbolTableListTraits<llvm::GlobalVariable> >::sort<OptimizeGlobalVars(llvm::Module&, llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>, llvm::SmallSet<llvm::Comdat const*, 8u, std::less<llvm::Comdat const*> >&)::GV_alignment_comparator>(OptimizeGlobalVars(llvm::Module&, llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>, llvm::SmallSet<llvm::Comdat const*, 8u, std::less<llvm::Comdat const*> >&)::GV_alignment_comparator) ( this=0x82b1f98, comp=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:632 #7 0x000000000239e77c in OptimizeGlobalVars(llvm::Module&, llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>, llvm::SmallSet<llvm::Comdat const*, 8u, std::less<llvm::Comdat const*> >&) (M=..., TLI=0x8293860, LookupDomTree=..., NotDiscardableComdats=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2199 #8 0x000000000239d88e in optimizeGlobalsInModule(llvm::Module&, llvm::DataLayout const&, llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>) (M=..., DL=..., TLI=0x8293860, LookupDomTree=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2655 #9 0x00000000023a9f8c in (anonymous namespace)::GlobalOptLegacyPass::runOnModule (this=0x8294f10, M=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2705 #10 0x00000000022ac02a in (anonymous namespace)::MPPassManager::runOnModule (this=0x831de40, M=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1603 #11 0x00000000022abb56 in llvm::legacy::PassManagerImpl::run (this=0x83237d0, M=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1706 #12 0x00000000022ac541 in llvm::legacy::PassManager::run (this=0x7fffffffb500, M=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1737 #13 0x0000000002adf7c5 in (anonymous namespace)::EmitAssemblyHelper::EmitAssembly (this=0x7fffffffb7a8, Action=clang::Backend_EmitObj, OS=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/BackendUtil.cpp:734 #14 0x0000000002adeda6 in clang::EmitBackendOutput (Diags=..., CGOpts=..., TOpts=..., LOpts=..., TDesc=..., M=0x82b1f90, Action=clang::Backend_EmitObj, OS=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/BackendUtil.cpp:751 #15 0x00000000035d622f in clang::BackendConsumer::HandleTranslationUnit (this=0x82b1a80, C=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/CodeGenAction.cpp:179 #16 0x0000000004259504 in clang::ParseAST (S=..., PrintStats=false, SkipFunctionBodies=false) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Parse/ParseAST.cpp:167 #17 0x00000000030f011a in clang::ASTFrontendAction::ExecuteAction (this=0x8297f20) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/FrontendAction.cpp:556 #18 0x00000000035d4bf5 in clang::CodeGenAction::ExecuteAction (this=0x8297f20) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/CodeGenAction.cpp:853 #19 0x00000000030efc00 in clang::FrontendAction::Execute (this=0x8297f20) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/FrontendAction.cpp:457 #20 0x0000000003094c81 in clang::CompilerInstance::ExecuteAction (this=0x827df40, Act=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/CompilerInstance.cpp:867 #21 0x0000000003241ba1 in clang::ExecuteCompilerInvocation (Clang=0x827df40) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/FrontendTool/ExecuteCompilerInvocation.cpp:241 #22 0x0000000000c33bc8 in cc1_main (Argv=..., Argv0=0x7fffffffe3f9 "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp/clang", MainAddr=0xc26010 <GetExecutablePath(char const*, bool)>) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/cc1_main.cpp:116 #23 0x0000000000c27c2a in ExecuteCC1Tool (argv=..., Tool=...) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/driver.cpp:301 #24 0x0000000000c26ae2 in main (argc_=52, argv_=0x7fffffffdfb8) at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/driver.cpp:382 ----- /tmp/main_with_3_globals-841619.c ----- # 1 "<built-in>" # 1 "main_with_3_globals.c" int foo; char bar; long baz; int main(){return foo;} ----- /tmp/main_with_3_globals-841619.sh ----- # Crash reproducer for clang version 3.9.0 # Driver args: "main_with_3_globals.c" "-O3" # Original command: "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-main-file-name" "main_with_3_globals.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-momit-leaf-frame-pointer" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-O3" "-fdebug-compilation-dir" "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp" "-ferror-limit" "19" "-fmessage-length" "144" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-o" "/tmp/main_with_3_globals-cef92e.o" "-x" "c" "main_with_3_globals.c" "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-main-file-name" "main_with_3_globals.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-momit-leaf-frame-pointer" "-dwarf-column-info" "-debugger-tuning=gdb" "-O3" "-ferror-limit" "19" "-fmessage-length" "144" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-x" "c" "main_with_3_globals-841619.c" [the previous 3 sections, i.e. error dump + preprocessed C code + shell code: much the same with an AArch64 target, using "-target aarch64-gnu-linux" and containing the output line "Target: aarch64--linux-gnu"]
David Majnemer via llvm-dev
2016-Aug-04 18:33 UTC
[llvm-dev] help please: how to sort the contents of a "SymbolTableListTraits<GlobalVariable>"?
On Thu, Aug 4, 2016 at 11:27 AM, Abe Skolnik via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Dear sir, > > Thanks for your reply. I apologize for taking a few days to reply. > > > Crashed how? >> > > Please see the below. > > > Have you turned on ASan? >> > > Not yet, but thanks for the suggestion. I guess I will try to rebuild my > modified Clang+LLVM with addr. san. and see what happens. > > > I recommend attaching a minimal reproduction... >> > > Well, since I`m hacking on LLVM itself, this is not 100% trivial. I will > explain. > > The first hurdle I had to overcome was the fact that the "GlobalVariable" > class had an explicitly-deleted copy ctor and no move ctor. I dealt with > this by writing a copy ctor; I`ll paste that in below. > > A perhaps-important point is that I don`t know _why_ the "GlobalVariable" > class had an explicitly-deleted copy ctor and no move ctor. As an > experiment, I moved forward with the hypothesis that this was simply > because neither was needed at the time and the default [i.e. > compiler-inserted] copy ctor would have been wrong. I hope the one _I_ > wrote is _right_. ;-)You should never be copying or moving around Values. An llvm::Value (which GlobalVariable is a subtype of) should exist only in the heap. We play games where use lists are allocated before the object which will not work at all with stack based allocations.> > > > I assume you can reproduce this in a unit test? >> > > Well, it doesn`t take a long program-under-compilation to make this fail. > As before, I will paste something in after my sign-off. > > > Regards, > > Abe > > > > > > ----- added near the end of "OptimizeGlobalVars" in > "llvm/lib/Transforms/IPO/GlobalOpt.cpp", amongst many other things I > added to that routine ----- > > struct GV_alignment_comparator { > bool operator()(const GlobalVariable& L, const GlobalVariable& R) { > return L.getAlignment() < R.getAlignment(); > } > }; > > if (unsorted) { > M.getGlobalList().sort( GV_alignment_comparator() ); > Changed = true; > } > > > > ----- added to "llvm/lib/IR/Globals.cpp" [and commented out the relevant > deletion in "llvm/include/llvm/IR/GlobalVariable.h"] ----- > > GlobalVariable::GlobalVariable(const GlobalVariable& GV) : > GlobalVariable( GV.getValueType(), GV.isConstant(), GV.getLinkage() ) { // > copy ctor > copyAttributesFrom(&GV); > } > > > > > > main_with_3_globals.c > --------------------- > > int foo; > char bar; > long baz; > > int main(){return foo;} > > > > > > > > > > > ----- error dump from compiler driver ----- > > ../build_003/bin/clang main_with_3_globals.c -O3 >> > > Abe was here: max. profitable alignment: 16 > > Abe was here: found a global value that DOES have a name [“foo”], > with alignment 4, > no named section [double-check: should be empty string: “”], > which is a pointer to a NON-array > and with pointee type getTypeStoreSize -> 4 > > Abe was here: found a global value that DOES have a name [“bar”], > with alignment 1, > no named section [double-check: should be empty string: “”], > which is a pointer to a NON-array > and with pointee type getTypeStoreSize -> 1 > > Abe was here: found a global value that DOES have a name [“baz”], > with alignment 8, > no named section [double-check: should be empty string: “”], > which is a pointer to a NON-array > and with pointee type getTypeStoreSize -> 8 > > ===== Abe was here: the globals above are NOT in ascending-alignment > order. ====> 0 clang-3.9 0x0000000002853ebc llvm::sys::PrintStackTrace(llvm::raw_ostream&) > + 60 > 1 clang-3.9 0x00000000028543a9 > 2 clang-3.9 0x0000000002852a83 llvm::sys::RunSignalHandlers() + 131 > 3 clang-3.9 0x00000000028546f4 > 4 libpthread.so.0 0x00007fc595318330 > 5 clang-3.9 0x00000000027fbe12 llvm::StringMapImpl::LookupBucketFor(llvm::StringRef) > + 466 > 6 clang-3.9 0x0000000002320fa4 > 7 clang-3.9 0x0000000002320a10 llvm::ValueSymbolTable::reinsertValue(llvm::Value*) > + 112 > 8 clang-3.9 0x00000000022f0551 llvm::SymbolTableListTraits<ll > vm::GlobalVariable>::transferNodesFromList(llvm::SymbolTable > ListTraits<llvm::GlobalVariable>&, llvm::ilist_iterator<llvm::GlobalVariable>, > llvm::ilist_iterator<llvm::GlobalVariable>) + 273 > 9 clang-3.9 0x00000000023b1fd9 > 10 clang-3.9 0x00000000023b1c45 > 11 clang-3.9 0x00000000023a8e40 > 12 clang-3.9 0x000000000239e77c > 13 clang-3.9 0x000000000239d88e > 14 clang-3.9 0x00000000023a9f8c > 15 clang-3.9 0x00000000022ac02a > 16 clang-3.9 0x00000000022abb56 llvm::legacy::PassManagerImpl::run(llvm::Module&) > + 342 > 17 clang-3.9 0x00000000022ac541 llvm::legacy::PassManager::run(llvm::Module&) > + 33 > 18 clang-3.9 0x0000000002adf7c5 > 19 clang-3.9 0x0000000002adeda6 clang::EmitBackendOutput(clang::DiagnosticsEngine&, > clang::CodeGenOptions const&, clang::TargetOptions const&, > clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, > clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, > std::default_delete<llvm::raw_pwrite_stream> >) + 150 > 20 clang-3.9 0x00000000035d622f > 21 clang-3.9 0x0000000004259504 clang::ParseAST(clang::Sema&, bool, > bool) + 820 > 22 clang-3.9 0x00000000030f011a clang::ASTFrontendAction::ExecuteAction() > + 314 > 23 clang-3.9 0x00000000035d4bf5 clang::CodeGenAction::ExecuteAction() > + 2357 > 24 clang-3.9 0x00000000030efc00 clang::FrontendAction::Execute() + > 112 > 25 clang-3.9 0x0000000003094c81 clang::CompilerInstance::Execu > teAction(clang::FrontendAction&) + 1025 > 26 clang-3.9 0x0000000003241ba1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) > + 1473 > 27 clang-3.9 0x0000000000c33bc8 cc1_main(llvm::ArrayRef<char > const*>, char const*, void*) + 920 > 28 clang-3.9 0x0000000000c27c2a > 29 clang-3.9 0x0000000000c26ae2 main + 2642 > 30 libc.so.6 0x00007fc593e80f45 __libc_start_main + 245 > 31 clang-3.9 0x0000000000c25f44 > Stack dump: > 0. Program arguments: /work/Abe/non-backup-worthy/bu > ild_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9 > -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free > -main-file-name main_with_3_globals.c -mrelocation-model static > -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases > -munwind-tables -fuse-init-array -target-cpu x86-64 > -momit-leaf-frame-pointer -dwarf-column-info -debugger-tuning=gdb > -resource-dir /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0 > -internal-isystem /usr/local/include -internal-isystem > /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0/include > -internal-externc-isystem /usr/include/x86_64-linux-gnu > -internal-externc-isystem /include -internal-externc-isystem /usr/include > -O3 -fdebug-compilation-dir /work/Abe/non-backup-worthy/bu > ild_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp > -ferror-limit 19 -fmessage-length 144 -fobjc-runtime=gcc > -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops > -vectorize-slp -o /tmp/main_with_3_globals-cef92e.o -x c > main_with_3_globals.c > 1. <eof> parser at end of file > 2. Per-module optimization passes > 3. Running pass 'Global Variable Optimizer' on module > 'main_with_3_globals.c'. > clang-3.9: error: unable to execute command: Segmentation fault > clang-3.9: error: clang frontend command failed due to signal (use -v to > see invocation) > clang version 3.9.0 > Target: x86_64-unknown-linux-gnu > Thread model: posix > InstalledDir: /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/tmp/../build_003/bin > clang-3.9: note: diagnostic msg: PLEASE submit a bug report to > http://llvm.org/bugs/ and include the crash backtrace, preprocessed > source, and associated run script. > clang-3.9: note: diagnostic msg: > ******************** > > PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: > Preprocessed source(s) and associated run script(s) are located at: > clang-3.9: note: diagnostic msg: /tmp/main_with_3_globals-841619.c > clang-3.9: note: diagnostic msg: /tmp/main_with_3_globals-841619.sh > clang-3.9: note: diagnostic msg: > > ******************** > > > > > GDB backtrace from the "-cc1" part of another run of the > same-as-the-preceding compilation attempt > ------------------------------------------------------------ > -------------------------------------- > > Program received signal SIGSEGV, Segmentation fault. > 0x00000000027fbe12 in llvm::StringMapImpl::LookupBucketFor > (this=0x82f00e8, Name=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/lib/Support/StringMap.cpp:102 > 102 } else if (LLVM_LIKELY(HashTable[BucketNo] == FullHashValue)) > { > (gdb) bt > #0 0x00000000027fbe12 in llvm::StringMapImpl::LookupBucketFor > (this=0x82f00e8, Name=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/lib/Support/StringMap.cpp:102 > #1 0x0000000002320fa4 in llvm::StringMap<llvm::Value*, > llvm::MallocAllocator>::insert (this=0x82f00e8, KeyValue=0x8312cb0) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/StringMap.h:345 > #2 0x0000000002320a10 in llvm::ValueSymbolTable::reinsertValue > (this=0x82f00e8, V=0x830cfd8) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/lib/IR/ValueSymbolTable.cpp:59 > #3 0x00000000022f0551 in llvm::SymbolTableListTraits<ll > vm::GlobalVariable>::transferNodesFromList (this=0x7fffffffabd8, L2=..., > first=..., > last=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/lib/IR/SymbolTableListTraitsImpl.h:102 > #4 0x00000000023b1fd9 in llvm::iplist<llvm::GlobalVariable, > llvm::SymbolTableListTraits<llvm::GlobalVariable> >::transfer ( > this=0x7fffffffabd8, position=..., L2=..., first=..., last=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:532 > #5 0x00000000023b1c45 in llvm::iplist<llvm::GlobalVariable, > llvm::SymbolTableListTraits<llvm::GlobalVariable> >::splice > (this=0x7fffffffabd8, > where=..., L2=..., first=..., last=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:587 > #6 0x00000000023a8e40 in llvm::iplist<llvm::GlobalVariable, > llvm::SymbolTableListTraits<llvm::GlobalVariable> > >::sort<OptimizeGlobalVars(llvm::Module&, llvm::TargetLibraryInfo*, > llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>, > llvm::SmallSet<llvm::Comdat const*, 8u, std::less<llvm::Comdat const*> > >&)::GV_alignment_comparator>(OptimizeGlobalVars(llvm::Module&, > llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& > (llvm::Function&)>, llvm::SmallSet<llvm::Comdat const*, 8u, > std::less<llvm::Comdat const*> >&)::GV_alignment_comparator) ( > this=0x82b1f98, comp=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:632 > #7 0x000000000239e77c in OptimizeGlobalVars(llvm::Module&, > llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& > (llvm::Function&)>, llvm::SmallSet<llvm::Comdat const*, 8u, > std::less<llvm::Comdat const*> >&) (M=..., TLI=0x8293860, LookupDomTree=..., > NotDiscardableComdats=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2199 > #8 0x000000000239d88e in optimizeGlobalsInModule(llvm::Module&, > llvm::DataLayout const&, llvm::TargetLibraryInfo*, > llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>) (M=..., > DL=..., TLI=0x8293860, LookupDomTree=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2655 > #9 0x00000000023a9f8c in (anonymous namespace)::GlobalOptLegacyPass::runOnModule > (this=0x8294f10, M=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2705 > #10 0x00000000022ac02a in (anonymous namespace)::MPPassManager::runOnModule > (this=0x831de40, M=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1603 > #11 0x00000000022abb56 in llvm::legacy::PassManagerImpl::run > (this=0x83237d0, M=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1706 > #12 0x00000000022ac541 in llvm::legacy::PassManager::run > (this=0x7fffffffb500, M=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1737 > #13 0x0000000002adf7c5 in (anonymous namespace)::EmitAssemblyHelper::EmitAssembly > (this=0x7fffffffb7a8, Action=clang::Backend_EmitObj, OS=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/BackendUtil.cpp:734 > #14 0x0000000002adeda6 in clang::EmitBackendOutput (Diags=..., CGOpts=..., > TOpts=..., LOpts=..., TDesc=..., M=0x82b1f90, > Action=clang::Backend_EmitObj, OS=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/BackendUtil.cpp:751 > #15 0x00000000035d622f in clang::BackendConsumer::HandleTranslationUnit > (this=0x82b1a80, C=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/CodeG > enAction.cpp:179 > #16 0x0000000004259504 in clang::ParseAST (S=..., PrintStats=false, > SkipFunctionBodies=false) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Parse/ParseAST.cpp:167 > #17 0x00000000030f011a in clang::ASTFrontendAction::ExecuteAction > (this=0x8297f20) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/Fron > tendAction.cpp:556 > #18 0x00000000035d4bf5 in clang::CodeGenAction::ExecuteAction > (this=0x8297f20) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/CodeG > enAction.cpp:853 > #19 0x00000000030efc00 in clang::FrontendAction::Execute (this=0x8297f20) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/Fron > tendAction.cpp:457 > #20 0x0000000003094c81 in clang::CompilerInstance::ExecuteAction > (this=0x827df40, Act=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/Comp > ilerInstance.cpp:867 > #21 0x0000000003241ba1 in clang::ExecuteCompilerInvocation > (Clang=0x827df40) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/FrontendTool/ > ExecuteCompilerInvocation.cpp:241 > #22 0x0000000000c33bc8 in cc1_main (Argv=..., > Argv0=0x7fffffffe3f9 "/work/Abe/non-backup-worthy/b > uild_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp/clang", > MainAddr=0xc26010 <GetExecutablePath(char const*, bool)>) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/cc1_main.cpp:116 > #23 0x0000000000c27c2a in ExecuteCC1Tool (argv=..., Tool=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/driver.cpp:301 > #24 0x0000000000c26ae2 in main (argc_=52, argv_=0x7fffffffdfb8) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07 > -17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/driver.cpp:382 > > > > > > > > > ----- /tmp/main_with_3_globals-841619.c ----- > > # 1 "<built-in>" > # 1 "main_with_3_globals.c" > int foo; > char bar; > long baz; > > int main(){return foo;} > > > > ----- /tmp/main_with_3_globals-841619.sh ----- > > # Crash reproducer for clang version 3.9.0 > # Driver args: "main_with_3_globals.c" "-O3" > # Original command: "/work/Abe/non-backup-worthy/b > uild_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9" > "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-disable-free" > "-main-file-name" "main_with_3_globals.c" "-mrelocation-model" "static" > "-mthread-model" "posix" "-fmath-errno" "-masm-verbose" > "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" > "x86-64" "-momit-leaf-frame-pointer" "-dwarf-column-info" > "-debugger-tuning=gdb" "-resource-dir" "/work/Abe/non-backup-worthy/b > uild_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/b > uild_003/bin/../lib/clang/3.9.0" "-internal-isystem" "/usr/local/include" > "-internal-isystem" "/work/Abe/non-backup-worthy/b > uild_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/b > uild_003/bin/../lib/clang/3.9.0/include" "-internal-externc-isystem" > "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" > "-internal-externc-isystem" "/usr/include" "-O3" "-fdebug-compilation-dir" > "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-0 > 7-17-22-54-42-1cb1a4c-master/tmp" "-ferror-limit" "19" "-fmessage-length" > "144" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" > "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-o" > "/tmp/main_with_3_globals-cef92e.o" "-x" "c" "main_with_3_globals.c" > > "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-0 > 7-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9" "-cc1" "-triple" > "x86_64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-main-file-name" > "main_with_3_globals.c" "-mrelocation-model" "static" "-mthread-model" > "posix" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" > "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" > "-momit-leaf-frame-pointer" "-dwarf-column-info" "-debugger-tuning=gdb" > "-O3" "-ferror-limit" "19" "-fmessage-length" "144" "-fobjc-runtime=gcc" > "-fdiagnostics-show-option" "-fcolor-diagnostics" "-vectorize-loops" > "-vectorize-slp" "-x" "c" "main_with_3_globals-841619.c" > > > > > > > [the previous 3 sections, i.e. error dump + preprocessed C code + shell > code: much the same with an AArch64 target, using "-target > aarch64-gnu-linux" and containing the output line "Target: > aarch64--linux-gnu"] > > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160804/aa38ed58/attachment-0001.html>
Abe Skolnik via llvm-dev
2016-Aug-04 18:41 UTC
[llvm-dev] help please: how to sort the contents of a "SymbolTableListTraits<GlobalVariable>"?
On 08/04/2016 01:33 PM, David Majnemer wrote:> You should never be copying or moving around Values.Why not? Is that because of this thing you also wrote in the same message: "use lists are allocated before the object"?> An llvm::Value (which GlobalVariable is a subtype of) should exist only in the heap.Trying to sort a container of such objects doesn`t require me to contradict that advice. The code I have added only uses "GlobalVariable" via pointers and references, with the possible exception of the newly-added copy ctor. Thanks for your reply. Regards, Abe
Mehdi Amini via llvm-dev
2016-Aug-04 19:13 UTC
[llvm-dev] help please: how to sort the contents of a "SymbolTableListTraits<GlobalVariable>"?
> On Aug 4, 2016, at 11:27 AM, Abe Skolnik via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > Dear sir, > > Thanks for your reply. I apologize for taking a few days to reply. > > >> Crashed how? > > Please see the below. > > >> Have you turned on ASan? > > Not yet, but thanks for the suggestion. I guess I will try to rebuild my modified Clang+LLVM with addr. san. and see what happens. > > >> I recommend attaching a minimal reproduction... > > Well, since I`m hacking on LLVM itself, this is not 100% trivial. I will explain. > > The first hurdle I had to overcome was the fact that the "GlobalVariable" class had an explicitly-deleted copy ctor and no move ctor. I dealt with this by writing a copy ctor; I`ll paste that in below. > > A perhaps-important point is that I don`t know _why_ the "GlobalVariable" class had an explicitly-deleted copy ctor and no move ctor. As an experiment, I moved forward with the hypothesis that this was simply because neither was needed at the time and the default [i.e. compiler-inserted] copy ctor would have been wrong. I hope the one _I_ wrote is _right_. ;-) > > >> I assume you can reproduce this in a unit test? > > Well, it doesn`t take a long program-under-compilation to make this fail. As before, I will paste something in after my sign-off. > > > Regards, > > Abe > > > > > > ----- added near the end of "OptimizeGlobalVars" in "llvm/lib/Transforms/IPO/GlobalOpt.cpp", amongst many other things I added to that routine ----- > > struct GV_alignment_comparator { > bool operator()(const GlobalVariable& L, const GlobalVariable& R) { > return L.getAlignment() < R.getAlignment(); > } > }; > > if (unsorted) { > M.getGlobalList().sort( GV_alignment_comparator() );The issue is that the “sort” method of iplist is delegating a bunch of things to SymbolTableListTraits, and the later makes some assumption that are broken in this case. The offending path is: 1) iplist:sort() wANTS to split the list in two 2) it creates a new empty list, and tries to splice a subpart of the existing list into the new one: // Split the list into two. iplist RightHalf; RightHalf.splice(RightHalf.begin(), *this, Center, end()); 3) split will call back into: SymbolTableListTraits::transferNodesFromList. Unfortunately this assumes that the list is owned by a Module (see SymbolTableListTraits ::getListOwner()) This obviously breaks badly in this case. Note: I don’t know why you needed a copy/move ctor for global value, I was able to build with your “patch” to GlobalOpt.cpp without changing anything else. — Mehdi> Changed = true; > } > > > > ----- added to "llvm/lib/IR/Globals.cpp" [and commented out the relevant deletion in "llvm/include/llvm/IR/GlobalVariable.h"] ----- > > GlobalVariable::GlobalVariable(const GlobalVariable& GV) : GlobalVariable( GV.getValueType(), GV.isConstant(), GV.getLinkage() ) { // copy ctor > copyAttributesFrom(&GV); > } > > > > > > main_with_3_globals.c > --------------------- > > int foo; > char bar; > long baz; > > int main(){return foo;} > > > > > > > > > > > ----- error dump from compiler driver ----- > >> ../build_003/bin/clang main_with_3_globals.c -O3 > > Abe was here: max. profitable alignment: 16 > > Abe was here: found a global value that DOES have a name [“foo”], > with alignment 4, > no named section [double-check: should be empty string: “”], > which is a pointer to a NON-array > and with pointee type getTypeStoreSize -> 4 > > Abe was here: found a global value that DOES have a name [“bar”], > with alignment 1, > no named section [double-check: should be empty string: “”], > which is a pointer to a NON-array > and with pointee type getTypeStoreSize -> 1 > > Abe was here: found a global value that DOES have a name [“baz”], > with alignment 8, > no named section [double-check: should be empty string: “”], > which is a pointer to a NON-array > and with pointee type getTypeStoreSize -> 8 > > ===== Abe was here: the globals above are NOT in ascending-alignment order. ====> 0 clang-3.9 0x0000000002853ebc llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 60 > 1 clang-3.9 0x00000000028543a9 > 2 clang-3.9 0x0000000002852a83 llvm::sys::RunSignalHandlers() + 131 > 3 clang-3.9 0x00000000028546f4 > 4 libpthread.so.0 0x00007fc595318330 > 5 clang-3.9 0x00000000027fbe12 llvm::StringMapImpl::LookupBucketFor(llvm::StringRef) + 466 > 6 clang-3.9 0x0000000002320fa4 > 7 clang-3.9 0x0000000002320a10 llvm::ValueSymbolTable::reinsertValue(llvm::Value*) + 112 > 8 clang-3.9 0x00000000022f0551 llvm::SymbolTableListTraits<llvm::GlobalVariable>::transferNodesFromList(llvm::SymbolTableListTraits<llvm::GlobalVariable>&, llvm::ilist_iterator<llvm::GlobalVariable>, llvm::ilist_iterator<llvm::GlobalVariable>) + 273 > 9 clang-3.9 0x00000000023b1fd9 > 10 clang-3.9 0x00000000023b1c45 > 11 clang-3.9 0x00000000023a8e40 > 12 clang-3.9 0x000000000239e77c > 13 clang-3.9 0x000000000239d88e > 14 clang-3.9 0x00000000023a9f8c > 15 clang-3.9 0x00000000022ac02a > 16 clang-3.9 0x00000000022abb56 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 342 > 17 clang-3.9 0x00000000022ac541 llvm::legacy::PassManager::run(llvm::Module&) + 33 > 18 clang-3.9 0x0000000002adf7c5 > 19 clang-3.9 0x0000000002adeda6 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) + 150 > 20 clang-3.9 0x00000000035d622f > 21 clang-3.9 0x0000000004259504 clang::ParseAST(clang::Sema&, bool, bool) + 820 > 22 clang-3.9 0x00000000030f011a clang::ASTFrontendAction::ExecuteAction() + 314 > 23 clang-3.9 0x00000000035d4bf5 clang::CodeGenAction::ExecuteAction() + 2357 > 24 clang-3.9 0x00000000030efc00 clang::FrontendAction::Execute() + 112 > 25 clang-3.9 0x0000000003094c81 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 1025 > 26 clang-3.9 0x0000000003241ba1 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1473 > 27 clang-3.9 0x0000000000c33bc8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 920 > 28 clang-3.9 0x0000000000c27c2a > 29 clang-3.9 0x0000000000c26ae2 main + 2642 > 30 libc.so.6 0x00007fc593e80f45 __libc_start_main + 245 > 31 clang-3.9 0x0000000000c25f44 > Stack dump: > 0. Program arguments: /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name main_with_3_globals.c -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -momit-leaf-frame-pointer -dwarf-column-info -debugger-tuning=gdb -resource-dir /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0 -internal-isystem /usr/local/include -internal-isystem /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -fdebug-compilation-dir /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp -ferror-limit 19 -fmessage-length 144 -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /tmp/main_with_3_globals-cef92e.o -x c main_with_3_globals.c > 1. <eof> parser at end of file > 2. Per-module optimization passes > 3. Running pass 'Global Variable Optimizer' on module 'main_with_3_globals.c'. > clang-3.9: error: unable to execute command: Segmentation fault > clang-3.9: error: clang frontend command failed due to signal (use -v to see invocation) > clang version 3.9.0 > Target: x86_64-unknown-linux-gnu > Thread model: posix > InstalledDir: /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp/../build_003/bin > clang-3.9: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script. > clang-3.9: note: diagnostic msg: > ******************** > > PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: > Preprocessed source(s) and associated run script(s) are located at: > clang-3.9: note: diagnostic msg: /tmp/main_with_3_globals-841619.c > clang-3.9: note: diagnostic msg: /tmp/main_with_3_globals-841619.sh > clang-3.9: note: diagnostic msg: > > ******************** > > > > > GDB backtrace from the "-cc1" part of another run of the same-as-the-preceding compilation attempt > -------------------------------------------------------------------------------------------------- > > Program received signal SIGSEGV, Segmentation fault. > 0x00000000027fbe12 in llvm::StringMapImpl::LookupBucketFor (this=0x82f00e8, Name=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Support/StringMap.cpp:102 > 102 } else if (LLVM_LIKELY(HashTable[BucketNo] == FullHashValue)) { > (gdb) bt > #0 0x00000000027fbe12 in llvm::StringMapImpl::LookupBucketFor (this=0x82f00e8, Name=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Support/StringMap.cpp:102 > #1 0x0000000002320fa4 in llvm::StringMap<llvm::Value*, llvm::MallocAllocator>::insert (this=0x82f00e8, KeyValue=0x8312cb0) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/StringMap.h:345 > #2 0x0000000002320a10 in llvm::ValueSymbolTable::reinsertValue (this=0x82f00e8, V=0x830cfd8) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/ValueSymbolTable.cpp:59 > #3 0x00000000022f0551 in llvm::SymbolTableListTraits<llvm::GlobalVariable>::transferNodesFromList (this=0x7fffffffabd8, L2=..., first=..., > last=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/SymbolTableListTraitsImpl.h:102 > #4 0x00000000023b1fd9 in llvm::iplist<llvm::GlobalVariable, llvm::SymbolTableListTraits<llvm::GlobalVariable> >::transfer ( > this=0x7fffffffabd8, position=..., L2=..., first=..., last=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:532 > #5 0x00000000023b1c45 in llvm::iplist<llvm::GlobalVariable, llvm::SymbolTableListTraits<llvm::GlobalVariable> >::splice (this=0x7fffffffabd8, > where=..., L2=..., first=..., last=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:587 > #6 0x00000000023a8e40 in llvm::iplist<llvm::GlobalVariable, llvm::SymbolTableListTraits<llvm::GlobalVariable> >::sort<OptimizeGlobalVars(llvm::Module&, llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>, llvm::SmallSet<llvm::Comdat const*, 8u, std::less<llvm::Comdat const*> >&)::GV_alignment_comparator>(OptimizeGlobalVars(llvm::Module&, llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>, llvm::SmallSet<llvm::Comdat const*, 8u, std::less<llvm::Comdat const*> >&)::GV_alignment_comparator) ( > this=0x82b1f98, comp=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/include/llvm/ADT/ilist.h:632 > #7 0x000000000239e77c in OptimizeGlobalVars(llvm::Module&, llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>, llvm::SmallSet<llvm::Comdat const*, 8u, std::less<llvm::Comdat const*> >&) (M=..., TLI=0x8293860, LookupDomTree=..., > NotDiscardableComdats=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2199 > #8 0x000000000239d88e in optimizeGlobalsInModule(llvm::Module&, llvm::DataLayout const&, llvm::TargetLibraryInfo*, llvm::function_ref<llvm::DominatorTree& (llvm::Function&)>) (M=..., DL=..., TLI=0x8293860, LookupDomTree=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2655 > #9 0x00000000023a9f8c in (anonymous namespace)::GlobalOptLegacyPass::runOnModule (this=0x8294f10, M=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/Transforms/IPO/GlobalOpt.cpp:2705 > #10 0x00000000022ac02a in (anonymous namespace)::MPPassManager::runOnModule (this=0x831de40, M=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1603 > #11 0x00000000022abb56 in llvm::legacy::PassManagerImpl::run (this=0x83237d0, M=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1706 > #12 0x00000000022ac541 in llvm::legacy::PassManager::run (this=0x7fffffffb500, M=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/lib/IR/LegacyPassManager.cpp:1737 > #13 0x0000000002adf7c5 in (anonymous namespace)::EmitAssemblyHelper::EmitAssembly (this=0x7fffffffb7a8, Action=clang::Backend_EmitObj, OS=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/BackendUtil.cpp:734 > #14 0x0000000002adeda6 in clang::EmitBackendOutput (Diags=..., CGOpts=..., TOpts=..., LOpts=..., TDesc=..., M=0x82b1f90, > Action=clang::Backend_EmitObj, OS=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/BackendUtil.cpp:751 > #15 0x00000000035d622f in clang::BackendConsumer::HandleTranslationUnit (this=0x82b1a80, C=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/CodeGenAction.cpp:179 > #16 0x0000000004259504 in clang::ParseAST (S=..., PrintStats=false, SkipFunctionBodies=false) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Parse/ParseAST.cpp:167 > #17 0x00000000030f011a in clang::ASTFrontendAction::ExecuteAction (this=0x8297f20) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/FrontendAction.cpp:556 > #18 0x00000000035d4bf5 in clang::CodeGenAction::ExecuteAction (this=0x8297f20) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/CodeGen/CodeGenAction.cpp:853 > #19 0x00000000030efc00 in clang::FrontendAction::Execute (this=0x8297f20) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/FrontendAction.cpp:457 > #20 0x0000000003094c81 in clang::CompilerInstance::ExecuteAction (this=0x827df40, Act=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/Frontend/CompilerInstance.cpp:867 > #21 0x0000000003241ba1 in clang::ExecuteCompilerInvocation (Clang=0x827df40) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/lib/FrontendTool/ExecuteCompilerInvocation.cpp:241 > #22 0x0000000000c33bc8 in cc1_main (Argv=..., > Argv0=0x7fffffffe3f9 "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp/clang", > MainAddr=0xc26010 <GetExecutablePath(char const*, bool)>) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/cc1_main.cpp:116 > #23 0x0000000000c27c2a in ExecuteCC1Tool (argv=..., Tool=...) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/driver.cpp:301 > #24 0x0000000000c26ae2 in main (argc_=52, argv_=0x7fffffffdfb8) > at /work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/llvm/tools/cfe/tools/driver/driver.cpp:382 > > > > > > > > > ----- /tmp/main_with_3_globals-841619.c ----- > > # 1 "<built-in>" > # 1 "main_with_3_globals.c" > int foo; > char bar; > long baz; > > int main(){return foo;} > > > > ----- /tmp/main_with_3_globals-841619.sh ----- > > # Crash reproducer for clang version 3.9.0 > # Driver args: "main_with_3_globals.c" "-O3" > # Original command: "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-main-file-name" "main_with_3_globals.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-momit-leaf-frame-pointer" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/../lib/clang/3.9.0/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-O3" "-fdebug-compilation-dir" "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/tmp" "-ferror-limit" "19" "-fmessage-length" "144" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-o" "/tmp/main_with_3_globals-cef92e.o" "-x" "c" "main_with_3_globals.c" > "/work/Abe/non-backup-worthy/build_dirs/Clang/pre-3.9/2016-07-17-22-54-42-1cb1a4c-master/build_003/bin/clang-3.9" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-disable-free" "-main-file-name" "main_with_3_globals.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-momit-leaf-frame-pointer" "-dwarf-column-info" "-debugger-tuning=gdb" "-O3" "-ferror-limit" "19" "-fmessage-length" "144" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-vectorize-loops" "-vectorize-slp" "-x" "c" "main_with_3_globals-841619.c" > > > > > > > [the previous 3 sections, i.e. error dump + preprocessed C code + shell code: much the same with an AArch64 target, using "-target aarch64-gnu-linux" and containing the output line "Target: aarch64--linux-gnu"] > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160804/4de5243f/attachment.html>
Abe Skolnik via llvm-dev
2016-Aug-04 19:39 UTC
[llvm-dev] help please: how to sort the contents of a "SymbolTableListTraits<GlobalVariable>"?
On 08/04/2016 02:13 PM, Mehdi Amini wrote:> The issue is that the “sort” method of iplist is delegating a bunch of things to SymbolTableListTraits, [...]Thanks very much for explaining.> Note: I don’t know why you needed a copy/move ctor for global value, > I was able to build with your “patch” to GlobalOpt.cpp without changing anything else.That was probably due to a copy/move ctor being needed for {my attempts at building a working "sort" for the GVs myself}. None of those attempts worked, in the end, but there was more than one failure modality. Some of the attempts wouldn`t even compile without a copy/move ctor for "GlobalVariable", which was understandable considering the code in question. Regards, Abe
Seemingly Similar Threads
- help please: how to sort the contents of a "SymbolTableListTraits<GlobalVariable>"?
- help please: how to sort the contents of a "SymbolTableListTraits<GlobalVariable>"?
- code to sort otherwise-unsortable "ilist"s, e.g. symbol tables
- [cfe-dev] improving test-suite`s FP subtests to be able to compare both exact-match outputs and more-optimized builds that may have different outputs due to FP optimizations
- [cfe-dev] improving test-suite`s FP subtests to be able to compare both exact-match outputs and more-optimized builds that may have different outputs due to FP optimizations