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

    <tr>
        <th>Summary</th>
        <td>
            Clang warns for unused Arm -march even when used by preprocessor
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:ARM,
            clang:driver
      </td>
    </tr>

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

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

<pre>
    (derived from https://github.com/ClangBuiltLinux/linux/issues/1315)

Summary: clang should not warn that compiler `-march` arguments are unused when the preprocessor is run on assembly files.

`/tmp/test.s` is just an empty file. Each time we're going to pass `-march` to the compiler and assembler with `-Wa`.
```
$ ./bin/clang --target=arm-linux-gnueabi -march=armv7-m -Wa,-march=armv7-m -Wunused-command-line-argument /tmp/test.s -c
clang-15: warning: argument unused during compilation: '-march=armv7-m' [-Wunused-command-line-argument]
```
If we assemble only then we are warned that the compiler `-march` is unused. So far so good.
```
$ ./bin/clang --target=arm-linux-gnueabi -march=armv7-m -Wa,-march=armv7-m -Wunused-command-line-argument -x assembler-with-cpp /tmp/test.s -c
clang-15: warning: argument unused during compilation: '-march=armv7-m' [-Wunused-command-line-argument]
```
If we assemble but apply the preprocessor first we are still warned that it is unused. Which isn't correct because this option actually sets some preprocessor defines (justification for that at the end).
```
$ ./bin/clang --target=arm-linux-gnueabi -march=armv7-m -Wa,-march=armv7-m -Wunused-command-line-argument /tmp/test.s -E
clang-15: warning: /tmp/test.s: 'assembler' input unused [-Wunused-command-line-argument]
clang-15: warning: argument unused during compilation: '-Wa,-march=armv7-m' [-Wunused-command-line-argument]
clang-15: warning: argument unused during compilation: '-Wunused-command-line-argument' [-Wunused-command-line-argument]
```
Now if we only preprocess an assembly file there's nothing to do so everything is unused. Fine.
```
$ ./bin/clang --target=arm-linux-gnueabi -march=armv7-m -Wa,-march=armv7-m -Wunused-command-line-argument -x assembler-with-cpp /tmp/test.s -E
# 1 "/tmp/test.s"
# 1 "<built-in>" 1
# 1 "/tmp/test.s" 2
```
If we run the preprocessor on the assembly file, everything is used. Part of me says that the `-Wa,-march` should be unused here. You are running the preprocessor on an assembly file but also we know that only the compiler `-march` is used to set defines. Not sure.

The key issue is that the compiler `-march` should be used if you're running the preprocessor. Clang should not be warning you that it is unused.

Since it governs defines like `__thumb2__` so clearly it does something. Here we see that removing the compiler `-march` causes this file to fail to assemble, therefore it is "used". If you put it back clang then tells you it is unused despite clearly being used to add the define.
```
$ cat /tmp/test2.s
#ifndef __thumb2__
#error
#endif
$ ./bin/clang --target=arm-linux-gnueabi -Wa,-march=armv7-m -Wunused-command-line-argument -x assembler-with-cpp /tmp/test2.s -c
/tmp/test2.s:2:2: error:
#error
 ^
1 error generated.
$ ./bin/clang --target=arm-linux-gnueabi -march=armv7-m -Wa,-march=armv7-m -Wunused-command-line-argument -x assembler-with-cpp /tmp/test2.
s -c
clang-15: warning: argument unused during compilation: '-march=armv7-m' [-Wunused-command-line-argument]
```
Somehow `-march` fixes the issue but is also unused.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzVV1FvozgQ_jXJywhEoEk2D3nItl3dSner0_Wk1T1VBobgLdjINmnz72_GQBLSbHbvqpN6UgvExvY38818M6Q6368n8YccjdxhDoXRNZTONXaSbCbxJ_rbSle2aZjpmn7cVkJtP7aycr9K1b7QSNXfpbUtWnqYJbP5JF5NortJtOmuD21dC7OnLSHjDcCWuq1yUNrBszAKXCkc0AmNrNDAZBEF9H5W0gMIs21rVM7SE0KrWkswn0vkRQiNwcboDK3VBqQF0yrQCoS1WKfVHgra0IanWGhPAunqhq9oXWj5FFr6rbUOhAKsG9ctDOFeZCU4WSM84yReEoCtloTfaWjojDFSGmRIBzOEygcg9OuZ3Ojf_yroGh7BdH_dz_gGQsKVSkXXzlVB4MgF6CbJnTB14N0dbFWLIpXQH-6ndsugBt49vr0w3DkuIHA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