r226340 - Adding option -fno-inline-asm to disallow inline asm
Steven Wu
stevenwu at apple.com
Fri Jan 16 15:05:29 PST 2015
Author: steven_wu
Date: Fri Jan 16 17:05:28 2015
New Revision: 226340
URL: http://llvm.org/viewvc/llvm-project?rev=226340&view=rev
Log:
Adding option -fno-inline-asm to disallow inline asm
Summary:
This patch add a new option to dis-allow all inline asm.
Any GCC style inline asm will be reported as an error.
Reviewers: rnk, echristo
Reviewed By: rnk, echristo
Subscribers: bob.wilson, rnk, echristo, rsmith, cfe-commits
Differential Revision: http://reviews.llvm.org/D6870
Added:
cfe/trunk/test/Driver/inline-asm.c
- copied, changed from r226337, cfe/trunk/test/Driver/ms-inline-asm.c
cfe/trunk/test/Parser/no-gnu-inline-asm.c
Removed:
cfe/trunk/test/Driver/ms-inline-asm.c
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/LangOptions.def
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Parse/ParseStmtAsm.cpp
cfe/trunk/test/Parser/ms-inline-asm.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=226340&r1=226339&r2=226340&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri Jan 16 17:05:28 2015
@@ -25,6 +25,8 @@ def err_msasm_unsupported_arch : Error<
"Unsupported architecture '%0' for MS-style inline assembly">;
def err_msasm_unable_to_create_target : Error<
"MS-style inline assembly is not available: %0">;
+def err_gnu_inline_asm_disabled : Error<
+ "GNU-style inline assembly is disabled">;
}
let CategoryName = "Parse Issue" in {
Modified: cfe/trunk/include/clang/Basic/LangOptions.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.def?rev=226340&r1=226339&r2=226340&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/LangOptions.def (original)
+++ cfe/trunk/include/clang/Basic/LangOptions.def Fri Jan 16 17:05:28 2015
@@ -114,6 +114,7 @@ LANGOPT(MSBitfields , 1, 0, "Micro
LANGOPT(Freestanding, 1, 0, "freestanding implementation")
LANGOPT(NoBuiltin , 1, 0, "disable builtin functions")
LANGOPT(NoMathBuiltin , 1, 0, "disable math builtin functions")
+LANGOPT(GNUAsm , 1, 1, "GNU-style inline assembly")
BENIGN_LANGOPT(ThreadsafeStatics , 1, 1, "thread-safe static initializers")
LANGOPT(POSIXThreads , 1, 0, "POSIX thread support")
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=226340&r1=226339&r2=226340&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Jan 16 17:05:28 2015
@@ -404,6 +404,11 @@ def fno_autolink : Flag <["-"], "fno-aut
Flags<[DriverOption, CC1Option]>,
HelpText<"Disable generation of linker directives for automatic library linking">;
+def fgnu_inline_asm : Flag<["-"], "fgnu-inline-asm">, Group<f_Group>, Flags<[DriverOption]>;
+def fno_gnu_inline_asm : Flag<["-"], "fno-gnu-inline-asm">, Group<f_Group>,
+ Flags<[DriverOption, CC1Option]>,
+ HelpText<"Disable GNU style inline asm">;
+
def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">,
Group<f_Group>, Flags<[DriverOption, CC1Option]>,
HelpText<"Enable sample-based profile guided optimizations">;
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=226340&r1=226339&r2=226340&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Fri Jan 16 17:05:28 2015
@@ -4320,6 +4320,11 @@ void Clang::ConstructJob(Compilation &C,
false))
CmdArgs.push_back("-fasm-blocks");
+ // -fgnu-inline-asm is default.
+ if (!Args.hasFlag(options::OPT_fgnu_inline_asm,
+ options::OPT_fno_gnu_inline_asm, true))
+ CmdArgs.push_back("-fno-gnu-inline-asm");
+
// Enable vectorization per default according to the optimization level
// selected. For optimization levels that want vectorization we use the alias
// option to simplify the hasFlag logic.
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=226340&r1=226339&r2=226340&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Jan 16 17:05:28 2015
@@ -1563,6 +1563,7 @@ static void ParseLangArgs(LangOptions &O
Args.getLastArgValue(OPT_fmodule_implementation_of);
Opts.NativeHalfType = Opts.NativeHalfType;
Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns);
+ Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm);
if (!Opts.CurrentModule.empty() && !Opts.ImplementationOfModule.empty() &&
Opts.CurrentModule != Opts.ImplementationOfModule) {
Modified: cfe/trunk/lib/Parse/ParseStmtAsm.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmtAsm.cpp?rev=226340&r1=226339&r2=226340&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmtAsm.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmtAsm.cpp Fri Jan 16 17:05:28 2015
@@ -615,6 +615,11 @@ StmtResult Parser::ParseAsmStatement(boo
msAsm = true;
return ParseMicrosoftAsmStatement(AsmLoc);
}
+
+ // Check if GNU-style inline Asm is disabled.
+ if (!getLangOpts().GNUAsm)
+ Diag(AsmLoc, diag::err_gnu_inline_asm_disabled);
+
DeclSpec DS(AttrFactory);
SourceLocation Loc = Tok.getLocation();
ParseTypeQualifierListOpt(DS, AR_VendorAttributesParsed);
Copied: cfe/trunk/test/Driver/inline-asm.c (from r226337, cfe/trunk/test/Driver/ms-inline-asm.c)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/inline-asm.c?p2=cfe/trunk/test/Driver/inline-asm.c&p1=cfe/trunk/test/Driver/ms-inline-asm.c&r1=226337&r2=226340&rev=226340&view=diff
==============================================================================
--- cfe/trunk/test/Driver/ms-inline-asm.c (original)
+++ cfe/trunk/test/Driver/inline-asm.c Fri Jan 16 17:05:28 2015
@@ -13,3 +13,12 @@
// RUN: FileCheck --check-prefix=CHECK-NO-BLOCKS < %t %s
// CHECK-NO-BLOCKS-NOT: "-fasm-blocks"
+
+// RUN: %clang -target x86_64-apple-darwin10 \
+// RUN: -### -fsyntax-only -fno-gnu-inline-asm %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-NO-GNU-INLINE-ASM %s
+// RUN: %clang -target x86_64-apple-darwin10 \
+// RUN: -### -fsyntax-only -fgnu-inline-asm -fno-gnu-inline-asm %s 2>&1 | \
+// RUN: FileCheck --check-prefix=CHECK-NO-GNU-INLINE-ASM %s
+
+// CHECK-NO-GNU-INLINE-ASM: "-fno-gnu-inline-asm"
Removed: cfe/trunk/test/Driver/ms-inline-asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/ms-inline-asm.c?rev=226339&view=auto
==============================================================================
--- cfe/trunk/test/Driver/ms-inline-asm.c (original)
+++ cfe/trunk/test/Driver/ms-inline-asm.c (removed)
@@ -1,15 +0,0 @@
-// RUN: %clang -target x86_64-apple-darwin10 \
-// RUN: -### -fsyntax-only -fasm-blocks %s 2> %t
-// RUN: FileCheck --check-prefix=CHECK-BLOCKS < %t %s
-
-// RUN: %clang -target x86_64-apple-darwin10 \
-// RUN: -### -fsyntax-only -fno-asm-blocks -fasm-blocks %s 2> %t
-// RUN: FileCheck --check-prefix=CHECK-BLOCKS < %t %s
-
-// CHECK-BLOCKS: "-fasm-blocks"
-
-// RUN: %clang -target x86_64-apple-darwin10 \
-// RUN: -### -fsyntax-only -fasm-blocks -fno-asm-blocks %s 2> %t
-// RUN: FileCheck --check-prefix=CHECK-NO-BLOCKS < %t %s
-
-// CHECK-NO-BLOCKS-NOT: "-fasm-blocks"
Modified: cfe/trunk/test/Parser/ms-inline-asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/ms-inline-asm.c?rev=226340&r1=226339&r2=226340&view=diff
==============================================================================
--- cfe/trunk/test/Parser/ms-inline-asm.c (original)
+++ cfe/trunk/test/Parser/ms-inline-asm.c Fri Jan 16 17:05:28 2015
@@ -1,5 +1,7 @@
// REQUIRES: x86-registered-target
// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -verify -fasm-blocks
+// Disabling gnu inline assembly should have no effect on this testcase
+// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -verify -fasm-blocks -fno-gnu-inline-asm
#define M __asm int 0x2c
#define M2 int
Added: cfe/trunk/test/Parser/no-gnu-inline-asm.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/no-gnu-inline-asm.c?rev=226340&view=auto
==============================================================================
--- cfe/trunk/test/Parser/no-gnu-inline-asm.c (added)
+++ cfe/trunk/test/Parser/no-gnu-inline-asm.c Fri Jan 16 17:05:28 2015
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 %s -triple i686-apple-darwin -verify -fsyntax-only -fno-gnu-inline-asm
+
+void f (void) {
+ long long foo = 0, bar;
+ asm volatile("INST %0, %1" : "=r"(foo) : "r"(bar)); // expected-error {{GNU-style inline assembly is disabled}}
+ return;
+}
More information about the cfe-commits
mailing list