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 19051 - another example of different code generation at -O2 -g and -O2
Summary: another example of different code generation at -O2 -g and -O2
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Common Code Generator Code (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Katya Romanova
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-03-05 00:08 PST by Katya Romanova
Modified: 2015-03-23 15:25 PDT (History)
3 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 Katya Romanova 2014-03-05 00:08:43 PST
Code motion is noticed when running tests with and without the debug info at O2.
I've triaged this bug, and it's not a duplicate of BZ #18590. 


========Testcase==================
 extern void foo(char *dst,unsigned siz,const char *src);
 extern const char * i2str(int);

 struct AAA3 {
  AAA3(const char *value) { foo(text,sizeof(text),value);}
  void operator=(const char *value) { foo(text,sizeof(text),value);}
  operator const char*() const { return text;}
  char text[4];
 };

 void bar (int param1,int param2)  {
   const char * temp(0);

   if (param2) {
     temp = i2str(param2);
   }
   AAA3 var1("");
   AAA3 var2("");

   if (param1)
     var2 = "+";
   else
     var2 = "-";
   var1 = "";
 }
==============================================


clang -c -g -O2 test.cpp -o test.g.o
clang -c -O2 test.cpp -o test.o

objdump -d test.g.o > test.g.txt
objdump -d test.o > test.txt

diff test.txt test.g.txt
2c2
< test.o:     file format elf64-x86-64
---
> test.g.o:     file format elf64-x86-64
23,25c23,25
<   39: 48 8d 3c 24             lea    (%rsp),%rdi
<   3d: be 04 00 00 00          mov    $0x4,%esi
<   42: 85 db                   test   %ebx,%ebx
---
>   39: 85 db                   test   %ebx,%ebx
>   3b: 48 8d 3c 24             lea    (%rsp),%rdi
>   3f: be 04 00 00 00          mov    $0x4,%esi


Katya.
Comment 1 Katya Romanova 2015-03-23 15:24:02 PDT
Fixed in r204865

For more details, refer to the Crucible review: 
http://reviews.llvm.org/D2970