I'll update the bug title once this is triaged/analyzed. /Users/dcci/work/llvm/build/bin/clang -Wno-everything try.c -O1 -o try-nodebug $ cat red.c b, a, c; d() { return b; } f(g) { int e = d(); c && (a = e + g); } main() {} Difference between text sections (with and without -g) $ diff text-nodebug text-debug 3,4c3,4 < 100000f70 488d0591 00000083 3800741e 554889e5 H.......8.t.UH.. < 100000f80 535089fb e8d7ffff ff01d848 8d0d6e00 SP.........H..n. --- > 100000f70 554889e5 535089fb 488d0589 00000083 UH..SP..H....... > 100000f80 38007410 e8d7ffff ff01d848 8d0d6e00 8.t........H..n.
Diffing a disassembly might be more instructive. You can use -ffunction-sections to keep size differences from introducing too many spurious differences.
Only significant difference in codegen: ## %bb.0: ## %entry + movq _c@GOTPCREL(%rip), %rax + cmpl $0, (%rax) + je LBB1_2 +## %bb.1: ## %land.rhs pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset %rbp, -16 @@ -39,46 +33,21 @@
This might be the same root cause of the PostRA one, but I haven't confirmed.
Hi Davide, Is it a requirement to emit the same code for "-g" and no "-g"?
> Is it a requirement to emit the same code for "-g" and no "-g"? Yas.
It's a bug if debug informations change the code generated as debug informations have no semantic value associated.
> > Is it a requirement to emit the same code for "-g" and no "-g"? > > Yas. The principle here is that if "-g" changes the generated code, it can potentially hide a bug. That is, you are not actually debugging the exact same program that exhibited the bug you are looking for. One hopes that the two versions of the program (i.e., with and without -g) do have the same behavior, but it is far far better to know that you are debugging the exact same program. This is more of a problem for LLVM than some other compilers, because LLVM introduces additional meta-instructions into the IR to help track debugging information. This can affect optimization and code generation passes that don't take care to ignore these extra instructions. Most of the code-generation differences we find can be resolved by handling the debug-info instructions correctly.
Thank you for the reply. GCC has a similar policy (https://gcc.gnu.org/ml/gcc/2018-05/msg00011.html). It would be interesting to test this requirement.
(In reply to Chengnian Sun from comment #8) > Thank you for the reply. > > GCC has a similar policy (https://gcc.gnu.org/ml/gcc/2018-05/msg00011.html). > > It would be interesting to test this requirement. We have an ongoing effort in llvm (and, at least for me, swift), to find and squash the bugs which cause the differences.
Hi, Whether this bug is resolved? Because I can't able to reproduce this issue with llvm 8.0.0 svn. I have compared the assembly code between "-O1" and "-O1 + g", I didn't saw any diff. whether source is correct? I think the compiled source is try.c but mentioned cat eats red.c. Thanks
I could also not reproduce this issue with clang 10.0.0.
Resolving as FIXED, as two people have failed to reproduce with a more recent LLVM.