<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 - __attribute__((naked)) function loses parameter"
   href="https://bugs.llvm.org/show_bug.cgi?id=36078">36078</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>__attribute__((naked)) function loses parameter
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </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>Interprocedural Optimizations
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>momchil.velikov@arm.com
          </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=19740" name="attach_19740" title="minimal testcase">attachment 19740</a> <a href="attachment.cgi?id=19740&action=edit" title="minimal testcase">[details]</a></span>
minimal testcase

LLVM discards a parameter of a function, declared with the "naked" attribute.

Compiling the attached test program for Arm with `clang -target arm-eabi -O3 -S
naked.c` output the following assembly for `bar`:

    bar:
            .fnstart
            b       foo

i.e. the parameter to `foo` is not passed at all.

This change occurs during "Deduce function attributes", which marks the
parameter with "readnone" and subsequently it's removed by "Promote 'by
reference' arguments to scalars" pass.

    *** IR Dump After Function Integration/Inlining ***
    ; Function Attrs: naked noinline nounwind
    define internal fastcc i32 @foo(i32*) unnamed_addr #1 {
    entry:
      call void asm sideeffect "ldr r0, [r0] \0Abx lr        \0A", ""() #2,
!srcloc !3
      unreachable
    }
    *** IR Dump After Deduce function attributes ***
    ; Function Attrs: naked noinline nounwind
    define internal fastcc i32 @foo(i32* nocapture readnone) unnamed_addr #1 {
    entry:
      call void asm sideeffect "ldr r0, [r0] \0Abx lr        \0A", ""() #2,
!srcloc !3
      unreachable
    }
    *** IR Dump After Promote 'by reference' arguments to scalars ***
    ; Function Attrs: naked noinline nounwind
    define internal fastcc i32 @foo() unnamed_addr #1 {
    entry:
      call void asm sideeffect "ldr r0, [r0] \0Abx lr        \0A", ""() #2,
!srcloc !3
      unreachable
    }</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>