[llvm-bugs] [Bug 35571] New: [Clang-optimization] wrong code for optimization the union assignment in a called function

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Dec 7 19:48:58 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=35571

            Bug ID: 35571
           Summary: [Clang-optimization] wrong code for optimization the
                    union assignment in a called function
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: yangyibiao at nju.edu.cn
                CC: llvm-bugs at lists.llvm.org

$ clang -v
clang version 6.0.0-svn320088-1~exp1 (trunk)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.2.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.2.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

$ cat small.c
int printf(const char *, ...);
union {
  int a;
  short b;
} c, *d = &c, e = {1};
void f() {
  c.a = 0;
  *d = e;
  c.b = 0;
}
int main() {
  f();
  printf("%d\n", c.b);
}

$ clang -O0 small.c; ./a.out
0
$ clang -Ofast small.c; ./a.out
1

When removing function f and put the three lines of code in the main function,
the output is the same.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171208/f715f700/attachment-0001.html>


More information about the llvm-bugs mailing list