LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 37306 - [fuzzDI] -O1 + `-g` cause the generated code to change.
Summary: [fuzzDI] -O1 + `-g` cause the generated code to change.
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: DebugInfo (show other bugs)
Version: trunk
Hardware: PC All
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks: 37728
  Show dependency tree
 
Reported: 2018-05-01 08:12 PDT by Davide Italiano
Modified: 2019-09-18 08:27 PDT (History)
10 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Davide Italiano 2018-05-01 08:12:21 PDT
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.
Comment 1 Paul Robinson 2018-05-01 08:22:05 PDT
Diffing a disassembly might be more instructive.  You can use
-ffunction-sections to keep size differences from introducing
too many spurious differences.
Comment 2 Davide Italiano 2018-05-01 09:47:59 PDT
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 @@
Comment 3 Davide Italiano 2018-05-01 09:50:23 PDT
This might be the same root cause of the PostRA one, but I haven't confirmed.
Comment 4 Chengnian Sun 2018-05-01 10:37:08 PDT
Hi Davide, 

Is it a requirement to emit the same code for "-g" and no "-g"?
Comment 5 Adrian Prantl 2018-05-01 11:02:10 PDT
> Is it a requirement to emit the same code for "-g" and no "-g"?

Yas.
Comment 6 Davide Italiano 2018-05-01 11:03:00 PDT
It's a bug if debug informations change the code generated as debug informations have no semantic value associated.
Comment 7 Paul Robinson 2018-05-01 11:53:14 PDT
> > 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.
Comment 8 Chengnian Sun 2018-05-01 13:02:24 PDT
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.
Comment 9 Davide Italiano 2018-05-01 13:10:32 PDT
(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.
Comment 10 praveenvelliengiri 2019-03-06 09:25:44 PST
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
Comment 11 Chris Ye 2019-09-18 02:18:54 PDT
I could also not reproduce this issue with clang 10.0.0.
Comment 12 Paul Robinson 2019-09-18 08:27:16 PDT
Resolving as FIXED, as two people have failed to reproduce with a more
recent LLVM.