<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 - Compilation error when using -save-temps -masm=intel"
   href="https://bugs.llvm.org/show_bug.cgi?id=45435">45435</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Compilation error when using -save-temps -masm=intel
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>10.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>Frontend
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>peterwarrenfrost@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=23311" name="attach_23311" title="A zip file containing the original C code, cut-down preprocessed version, and generated assembly.">attachment 23311</a> <a href="attachment.cgi?id=23311&action=edit" title="A zip file containing the original C code, cut-down preprocessed version, and generated assembly.">[details]</a></span>
A zip file containing the original C code, cut-down preprocessed version, and
generated assembly.

Hi,

When compiling C with the clang frontend using -save-temps -masm=intel it seems
to think the following x86 assembly it generates is invalid when it comes to
assembling it.


$ clang -save-temps -masm=intel -c -o hello_world.o hello_world.i

hello_world.s:18:16: error: invalid base+index expression
        mov     qword ptr [ST], rax


$ clang -save-temps -masm=att -c -o hello_world.o hello_world.i

** no errors, compiles fine**

$ clang -masm=intel -c -o hello_world.o hello_world.i

** no errors, compiles fine**


ST is a file-level declared pointer to a typedef struct, although if I change
ST to be declared within the scope of the function I do not get a compilation
error because clang just puts it in the stack instead of trying to reference a
symbol called ST.

The hello_world.i file is the preprocessed version of the original file
(hello_world.c), that I've trimmed down to be as small as possible to
demonstrate the bug.

I've tried this with clang 9.0 and 10.0 and both seem to show the same error.
If you want more context on this code I found this while working on this
project
<a href="https://github.com/badcf00d/bare-bones-uefi/tree/clang-save-temps-intel-bug">https://github.com/badcf00d/bare-bones-uefi/tree/clang-save-temps-intel-bug</a>.</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>