[patch] gcc compat: Support -masm= flag for x86 targets
Nico Weber
thakis at chromium.org
Sat May 10 20:10:50 PDT 2014
Hi,
gcc understands -masm=att (default) and -masm=intel, to control the style
of -S output. The attached patch adds support for this to clang.
Motivation: Web searches for "masm clang" lead to pages that suggest
passing -S -mllvm --x86-asm-syntax=intel instead. This shows that there's
interest, and the driver has a "FIXME: remove this, eventually" for the
-mllvm option.
Nico
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140510/eb58a6dd/attachment.html>
-------------- next part --------------
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td (revision 208472)
+++ include/clang/Driver/Options.td (working copy)
@@ -1005,6 +1005,7 @@
def m64 : Flag<["-"], "m64">, Group<m_Group>, Flags<[DriverOption, CoreOption]>;
def mabi_EQ : Joined<["-"], "mabi=">, Group<m_Group>;
def march_EQ : Joined<["-"], "march=">, Group<m_Group>;
+def masm_EQ : Joined<["-"], "masm=">, Group<m_Group>, Flags<[DriverOption]>;
def mcmodel_EQ : Joined<["-"], "mcmodel=">, Group<m_Group>;
def mconstant_cfstrings : Flag<["-"], "mconstant-cfstrings">, Group<clang_ignored_m_Group>;
def mcpu_EQ : Joined<["-"], "mcpu=">, Group<m_Group>;
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp (revision 208485)
+++ lib/Driver/Tools.cpp (working copy)
@@ -1486,6 +1486,17 @@
}
if (NoImplicitFloat)
CmdArgs.push_back("-no-implicit-float");
+
+ if (Arg *A = Args.getLastArg(options::OPT_masm_EQ)) {
+ StringRef Value = A->getValue();
+ if (Value == "intel" || Value == "att") {
+ CmdArgs.push_back("-mllvm");
+ CmdArgs.push_back(Args.MakeArgString("-x86-asm-syntax=" + Value));
+ } else {
+ getToolChain().getDriver().Diag(diag::err_drv_unsupported_option_argument)
+ << A->getOption().getName() << Value;
+ }
+ }
}
static inline bool HasPICArg(const ArgList &Args) {
Index: test/Driver/masm.c
===================================================================
--- test/Driver/masm.c (revision 0)
+++ test/Driver/masm.c (working copy)
@@ -0,0 +1,12 @@
+// RUN: %clang -target i386-unknown-linux -masm=intel %s -S -o - | FileCheck --check-prefix=CHECK-INTEL %s
+// RUN: %clang -target i386-unknown-linux -masm=att %s -S -o - | FileCheck --check-prefix=CHECK-ATT %s
+// RUN: not %clang -target i386-unknown-linux -masm=somerequired %s -S -o - 2>&1 | FileCheck --check-prefix=CHECK-SOMEREQUIRED %s
+// RUN: %clang -target arm-unknown-eabi -masm=intel %s -S -o - 2>&1 | FileCheck --check-prefix=CHECK-ARM %s
+
+int f() {
+// CHECK-ATT: movl $0, %eax
+// CHECK-INTEL: mov eax, 0
+// CHECK-SOMEREQUIRED: error: unsupported argument 'somerequired' to option 'masm='
+// CHECK-ARM: warning: argument unused during compilation: '-masm=intel'
+ return 0;
+}
More information about the cfe-commits
mailing list