[llvm-bugs] [Bug 33075] New: Assignment to struct passed by value modifies caller's stack frame

via llvm-bugs llvm-bugs at lists.llvm.org
Wed May 17 10:30:34 PDT 2017


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

            Bug ID: 33075
           Summary: Assignment to struct passed by value modifies caller's
                    stack frame
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: gergo.barany at inria.fr
                CC: llvm-bugs at lists.llvm.org

Created attachment 18458
  --> https://bugs.llvm.org/attachment.cgi?id=18458&action=edit
Input C file for triggering the bug

Consider the following C program (also in the attachment):


$ cat bug_06.c 
struct S1 {
   int f4;
   int f8;
   int pad[3];
};

int func(struct S1 s)
{ 
    s.f8 = 666;
    return s.f4;
}


The struct is passed into the function by value, and the store to s.f8 should
only affect the function's local copy. (And be optimized away because it is
dead.) However, LLVM seems to generate code that modifies the caller's copy on
the stack:


$ clang bug_06.c -O3 -S -o -    .text
        .file   "bug_06.c"
        .globl  func
        .p2align        4, 0x90
        .type   func, at function
func:                                   # @func
        .cfi_startproc
# BB#0:
        movl    $666, 12(%rsp)          # imm = 0x29A
        movl    8(%rsp), %eax
        retq
.Lfunc_end0:
        .size   func, .Lfunc_end0-func
        .cfi_endproc


        .ident  "clang version 5.0.0 (trunk 303270)"
        .section        ".note.GNU-stack","", at progbits


Note the store of 666 to an address on the stack although no stack frame was
allocated, i.e., to an address in the caller's frame.

This may be a duplicate of https://bugs.llvm.org/show_bug.cgi?id=10485 , which
was not investigated further because it seemed to be a bug in the bitcode
interpreter.

-- 
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/20170517/5d5bc9fe/attachment-0001.html>


More information about the llvm-bugs mailing list