[llvm-bugs] [Bug 34088] New: Incorrect optimization of assignment in present of memset

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Aug 5 16:04:47 PDT 2017


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

            Bug ID: 34088
           Summary: Incorrect optimization of assignment in present of
                    memset
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dpotapov at gmail.com
                CC: llvm-bugs at lists.llvm.org

Created attachment 18914
  --> https://bugs.llvm.org/attachment.cgi?id=18914&action=edit
An example to reproduce the problem.

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

  Init(&foo);
  buffer = foo.bar.buffer;
  memset(&foo, 0xCD, sizeof (foo));
  foo.bar.buffer = buffer;
  Print(&foo);

and if optimization is enabled, it becomes like this:

  Init(&foo);
  memset(&foo, 0xCD, sizeof (foo));
  Print(&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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170805/ff1e763c/attachment.html>


More information about the llvm-bugs mailing list