Bug ID: 34088
           Summary: Incorrect optimization of assignment in present of
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen

Created attachment 18914
An example to reproduce the problem.

During optimization clang removes assignments that should not be eliminated.
I have the following code:

  buffer =;
  memset(&foo, 0xCD, sizeof (foo)); = buffer;

and if optimization is enabled, it becomes like this:

  memset(&foo, 0xCD, sizeof (foo));

The bug happens only with target: i386-pc-linux-gnu and for some layout of
structures. (Perhaps, it can happen on x86_64 too for different structures,
but I have not encountered it only on i386 architecture.)

I have attached a full example that demonstrates the problem. It includes
the following files:
test1.h - defines some structures.
test1.c - the main code that is incorrectly optimized
test2.c - defines Init() and Print()
Makefile - builds and runs the example code

If optimization is not enabled, the program prints as expected:
  ptr=(nil) size=0x0
however when any level optimization is enabled, I get the following output:
  ptr=0xcdcdcdcd size=0xcdcdcdcd
i.e. the initial value of 'buffer' set in Init() is overwritten by memset.

clang information:
$ clang-5.0 -m32 --version
clang version 5.0.0-svn309965-1~exp1 (branches/release_50)
Target: i386-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

You are receiving this mail because:
You are on the CC list for the bug.
llvm-bugs mailing list

Reply via email to