<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/60792>60792</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Incorrect expansion of \@ in inline asm
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          andyhhp
      </td>
    </tr>
</table>

<pre>
    `\@` is the macro expansion count, and is supposed to be unique in each expansion inside a translation unit.  It is commonly used to generate unique local named labels.

However, Clang IAS doesn't get this quite right.  https://godbolt.org/z/reedx7Gsr 

Given:
```c
asm ("toplevel:\n\t"
     ".macro M\n\t"
     "# M expansion \\@ \n\t"
     ".L\\@: add $\\@, %eax\n\t"
     ".endm\n\t");

asm ("M"); // \@ = 0
asm ("M"); // \@ = 1

void a(void)
{
    asm ("M"); // \@ should be 2, actually 0
    asm ("M"); // \@ should be 3, actually 0
}
```
GCC/Binutils, and Clang without IAS (not surprising - it hands of to GAS) expand `M` with 4 different numbers.  However, Clang IAS does something a bit more weird.

(warning - stdout and stderr are mixed in the following transcript, but it's reasonably easy to follow)
```asm
$ clang -S m.c -o /dev/stdout 
        .text
        .file   "m.c"
                                        # Start of file scope inline assembly
toplevel:


.L0:
        addl    $0, %eax

.L1:
        addl    $1, %eax


 # End of file scope inline assembly
        .globl  a # -- Begin function a
        .p2align        4, 0x90
        .type   a,@function
a:                                      # @a
        .cfi_startproc
# %bb.0:
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset %rbp, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register %rbp
        #APP
<instantiation>:1:1: error: invalid symbol redefinition
.L0: add $0, %eax
^
.L0:
        addl    $0, %eax

        #NO_APP
        #APP
<instantiation>:1:1: error: invalid symbol redefinition
.L0: add $0, %eax
^
.L0:
        addl    $0, %eax

        #NO_APP
        popq    %rbp
        .cfi_def_cfa %rsp, 8
        retq
.Lfunc_end0:
        .size   a, .Lfunc_end0-a
        .cfi_endproc
                                        # -- End function
        .ident  "clang version 10.0.0-4ubuntu1 "
        .section        ".note.GNU-stack","",@progbits
        .addrsig
2 errors generated.
```

At the top level, it maintains an incrementing expansion count across separate `asm()`, so the 0 and 1 case expand correctly.  However, when we come to the first `asm()` in `a()`, the expansion count resets back to 0.

This causes what should be unique local symbols to not be unique, and then suffer `error: invalid symbol redefinition`.

For completeness, the second `asm()` in `a()` also resets back to 0 again, which is why we end up with two duplicate symbol redefinitions.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcV1tz27oR_jXQy444JKiL-aAHW47SzJycnpm0zx6QWJHoAQEGC0rW-fWdJUVdnLh1-lhNQkvA4ttvF3ujIjK1Q9yI5ZNYPs9UHxsfNsrpU9N0s9Lr00asUrHcikUqVikYgtggtKoKHvC1U46Md1D53kUht6CcZhnqu84TaogeSoTeme89gnGAqmpuzhlHRiMoiEE5siryYu9MTAC-REaqfNt6Z0_Qn-FqdBhUvIBaXykLTrWowaoSLSUifRbp4_j8mz_iAQNz21rlavjy-A20R3JCriPUGCE2huB7byJCMHXDupsYOxL5o5A7IXe116W3MfGhFnL3l5C7gKhf158pwK2uz-aAjk-Na6t0_FeNvxW1IOSDkDL6zuIBLYsut04st1FIOUoBf4SUyejir-8KCJnD1xtX8h0N1wTvY_52ERL5IyitQcjFdU1uQcglqtf3EdDp9nZXFiJ_uvXB1cqvl30Y3QgTv_wZ0l-Szm41HLzRoIR84C98ZNxbP12pfgCWGt9bzcEph7itYq-sPU3Efhkl_xmKWD-_iYVzoGy3Qu6ejOujsTTlzRifRxMb38chToV8cD4C9aELhoyrYQ4mQqOcJvB7TofPj9-ELMY40CBW6VdOUwaBBWiz32NAF8H1bYmBEoB3EwLItxgb1qKgNBFaHxCOaIK-yyghH44quJENRc1kWTdFjSGACgiteUXN6c61Yu-t9UcWH5K8CqYbSkXZRzBRyDVBQEXeqdKeABW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