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

llvm-svn: 226340
This commit is contained in:
Steven Wu 2015-01-16 23:05:28 +00:00
parent a34d04d35e
commit cb0d13fc23
9 changed files with 37 additions and 0 deletions

View File

@ -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 {

View File

@ -114,6 +114,7 @@ LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout")
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")

View File

@ -404,6 +404,11 @@ def fno_autolink : Flag <["-"], "fno-autolink">, Group<f_Group>,
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">;

View File

@ -4320,6 +4320,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
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.

View File

@ -1563,6 +1563,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
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) {

View File

@ -615,6 +615,11 @@ StmtResult Parser::ParseAsmStatement(bool &msAsm) {
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);

View File

@ -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"

View File

@ -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

View File

@ -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;
}