<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Assignment to struct passed by value modifies caller's stack frame"
   href="https://bugs.llvm.org/show_bug.cgi?id=33075">33075</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Assignment to struct passed by value modifies caller's stack frame
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>gergo.barany@inria.fr
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=18458" name="attach_18458" title="Input C file for triggering the bug">attachment 18458</a> <a href="attachment.cgi?id=18458&action=edit" title="Input C file for triggering the bug">[details]</a></span>
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,@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","",@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 <a class="bz_bug_link 
          bz_status_CLOSED  bz_closed"
   title="CLOSED INVALID - Struct Passed by Value treated as if Passed By Reference with --force-interpreter"
   href="show_bug.cgi?id=10485">https://bugs.llvm.org/show_bug.cgi?id=10485</a> , which
was not investigated further because it seemed to be a bug in the bitcode
interpreter.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>