clang++ compilation error on adding debug flag


Short version --> adding debug flags leads to clang++ error (shown
below). without adding debug flags, compilation is successful.

Longer version-->

I am doing the follwing things in my project in order to debug it:

1. Compiling an llvm code pass.cpp with clang++ -ggdb that consists of
some optimization passes on my test.c file - I create an so file from
this - called

2. I create a .bc file of the optimization pass - using clang++
-emit-llvm. lets call it pass.bc.

3. Compiling and creating an executable of my my test.c file, with -g
flag - lets call it test

4. Creating a .bc of my test.c file - lets call it test.bc

5. running some optimization passes on my test.bc file, with the file created in step 1. let us call the output file

6. linking the optimized test.inst.bc file in step 4 with the llvm .bc
file generated in step 1. Let us call it test.inst2.bc

7. finally compiling the linked file using clang++ -c test.inst2.bc.

I get the following error :

clang-3.6: /home/shehbaz/courses/ece1781/project/fslice/llvm/lib/CodeGen/LexicalScopes.cpp:179:
llvm::LexicalScopes::getOrCreateRegularScope(llvm::MDNode*): Assertion
`DISubprogram(Scope).describes(MF->getFunction())' failed.
0 clang-3.6 0x00000000024cb8c4 llvm::sys::PrintStackTrace(_IO_FILE*) + 53
1 clang-3.6 0x00000000024cbb6e
2 clang-3.6 0x00000000024ca661
3 0x00007fa7bd39ad10
4 0x00007fa7bc5ad267 gsignal + 55
5 0x00007fa7bc5aeeca abort + 362
6 0x00007fa7bc5a603d
7 0x00007fa7bc5a60f2
8 clang-3.6 0x0000000001f89b97
llvm::LexicalScopes::getOrCreateRegularScope(llvm::MDNode*) + 703
9 clang-3.6 0x0000000001f890e9
llvm::LexicalScopes::getOrCreateLexicalScope(llvm::DebugLoc) + 191
10 clang-3.6 0x0000000001f88adf
const*, llvm::MachineInstr const*> >&,
llvm::DenseMap<llvm::MachineInstr const*, llvm::LexicalScope*,
llvm::DenseMapInfo<llvm::MachineInstr const*>,
llvm::detail::DenseMapPair<llvm::MachineInstr const*,
llvm::LexicalScope*> >&) + 459
11 clang-3.6 0x0000000001f88899
llvm::LexicalScopes::initialize(llvm::MachineFunction const&) + 127
12 clang-3.6 0x000000000282c753
llvm::DwarfDebug::beginFunction(llvm::MachineFunction const*) + 257
13 clang-3.6 0x0000000002812cf3
llvm::AsmPrinter::EmitFunctionHeader() + 1099
14 clang-3.6 0x00000000019b5123
15 clang-3.6 0x0000000001dd0473
llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 95
16 clang-3.6 0x00000000020e0def
llvm::FPPassManager::runOnFunction(llvm::Function&) + 305
17 clang-3.6 0x00000000020e0f81
llvm::FPPassManager::runOnModule(llvm::Module&) + 99
18 clang-3.6 0x00000000020e12c3
19 clang-3.6 0x00000000020e1986
llvm::legacy::PassManagerImpl::run(llvm::Module&) + 250
20 clang-3.6 0x00000000020e1ba7
llvm::legacy::PassManager::run(llvm::Module&) + 39
21 clang-3.6 0x0000000002a6da1c
22 clang-3.6 0x0000000002a6db2d
clang::CodeGenOptions const&, clang::TargetOptions const&,
clang::LangOptions const&, llvm::StringRef, llvm::Module*,
clang::BackendAction, llvm::raw_ostream*) + 173
23 clang-3.6 0x0000000002a541a4
clang::CodeGenAction::ExecuteAction() + 1408
24 clang-3.6 0x00000000026e4be4 clang::FrontendAction::Execute() + 154
25 clang-3.6 0x00000000026ab864
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 788
26 clang-3.6 0x000000000280a257
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1072
27 clang-3.6 0x000000000125833e cc1_main(llvm::ArrayRef<char
const*>, char const*, void*) + 776
28 clang-3.6 0x000000000125022f
29 clang-3.6 0x0000000001250852 main + 1082
30 0x00007fa7bc598a40 __libc_start_main + 240
31 clang-3.6 0x000000000124cec9 _start + 41
Stack dump:
0. Program arguments:
-cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all
-disable-free -main-file-name testfs.opt.bc -mrelocation-model static
-mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu
x86-64 -dwarf-column-info -coverage-file
-resource-dir /home/shehbaz/courses/ece1781/project/fslice/llvm/build/bin/../lib/clang/3.6.2
-fdebug-compilation-dir /home/shehbaz/courses/ece1781/project/fslice
-ferror-limit 19 -fmessage-length 181 -mstackrealign
-fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o
./testfs/testfs.opt.o -x ir ./testfs/testfs.opt.bc
1. Code generation
2. Running pass 'Function Pass Manager' on module './testfs/testfs.opt.bc'.
3. Running pass 'X86 Assembly / Object Emitter' on function '@main'
clang-3.6: error: unable to execute command: Aborted (core dumped)
clang-3.6: error: clang frontend command failed due to signal (use -v
to see invocation)
clang version 3.6.2 (tags/RELEASE_362/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
clang-3.6: note: diagnostic msg: PLEASE submit a bug report to and include the crash backtrace, preprocessed
source, and associated run script.
clang-3.6: note: diagnostic msg: Error generating preprocessed
source(s) - no preprocessable inputs.

Note that the program runs perfectly fine, if I do not add the debug symbols in

step 1 (-ggdb)
step 3 ( -g) <--- having this or running program without it does not
cause issues
step 7 (-ggdb)

Please let me know if there is another way to debug the code. I wish
to use gdb, not lldb, hence the -ggdb flag. If I use -g flag, that
also reports the same error while compiling the code. I looked up the
error message and it seems there is some other cause for the same
error trace:

Thank you,

This assertion has found many bugs in LLVM, and many of them have been fixed since LLVM 3.6. I don’t know of any good way to work around this assertion without getting a new compiler. You could try building 3.6.2 without assertions. LLVM will not crash immediately if you bypass this particular assertion, it will just generate bogus debug info somewhere.