[all-commits] [llvm/llvm-project] ae9818: [clang] Make -masm=intel affect inline asm style

Nico Weber via All-commits all-commits at lists.llvm.org
Wed Nov 17 10:42:18 PST 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ae98182cf7341181e4aa815c372a072dec82779f
      https://github.com/llvm/llvm-project/commit/ae98182cf7341181e4aa815c372a072dec82779f
  Author: Nico Weber <thakis at chromium.org>
  Date:   2021-11-17 (Wed, 17 Nov 2021)

  Changed paths:
    M clang/include/clang/Basic/CodeGenOptions.def
    M clang/include/clang/Basic/CodeGenOptions.h
    M clang/include/clang/Driver/Options.td
    M clang/lib/CodeGen/CGStmt.cpp
    M clang/lib/Driver/ToolChains/Clang.cpp
    M clang/lib/Frontend/CompilerInvocation.cpp
    M clang/lib/Headers/immintrin.h
    M clang/lib/Headers/intrin.h
    M clang/lib/Headers/x86gprintrin.h
    A clang/test/CodeGen/inline-asm-intel.c
    M clang/test/CodeGen/inline-asm-mixed-style.c
    M clang/test/CodeGen/ms-intrinsics-cpuid.c
    M clang/test/CodeGen/ms-intrinsics.c
    M clang/test/Driver/masm.c

  Log Message:
  -----------
  [clang] Make -masm=intel affect inline asm style

With this,

  void f() {  __asm__("mov eax, ebx"); }

now compiles with clang with -masm=intel.

This matches gcc.

The flag is not accepted in clang-cl mode. It has no effect on
MSVC-style `__asm {}` blocks, which are unconditionally in intel
mode both before and after this change.

One difference to gcc is that in clang, inline asm strings are
"local" while they're "global" in gcc. Building the following with
-masm=intel works with clang, but not with gcc where the ".att_syntax"
from the 2nd __asm__() is in effect until file end (or until a
".intel_syntax" somewhere later in the file):

  __asm__("mov eax, ebx");
  __asm__(".att_syntax\nmovl %ebx, %eax");
  __asm__("mov eax, ebx");

This also updates clang's intrinsic headers to work both in
-masm=att (the default) and -masm=intel modes.
The official solution for this according to "Multiple assembler dialects in asm
templates" in gcc docs->Extensions->Inline Assembly->Extended Asm
is to write every inline asm snippet twice:

    bt{l %[Offset],%[Base] | %[Base],%[Offset]}

This works in LLVM after D113932 and D113894, so use that.

(Just putting `.att_syntax` at the start of the snippet works in some but not
all cases: When LLVM interpolates in parameters like `%0`, it uses at&t or
intel syntax according to the inline asm snippet's flavor, so the `.att_syntax`
within the snippet happens to late: The interpolated-in parameter is already
in intel style, and then won't parse in the switched `.att_syntax`.)

It might be nice to invent a `#pragma clang asm_dialect push "att"` /
`#pragma clang asm_dialect pop` to be able to force asm style per snippet,
so that the inline asm string doesn't contain the same code in two variants,
but let's leave that for a follow-up.

Fixes PR21401 and PR20241.

Differential Revision: https://reviews.llvm.org/D113707




More information about the All-commits mailing list