Skip to content

Commit cb0d13f

Browse files
committedJan 16, 2015
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
1 parent a34d04d commit cb0d13f

File tree

9 files changed

+37
-0
lines changed

9 files changed

+37
-0
lines changed
 

‎clang/include/clang/Basic/DiagnosticParseKinds.td

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def err_msasm_unsupported_arch : Error<
2525
"Unsupported architecture '%0' for MS-style inline assembly">;
2626
def err_msasm_unable_to_create_target : Error<
2727
"MS-style inline assembly is not available: %0">;
28+
def err_gnu_inline_asm_disabled : Error<
29+
"GNU-style inline assembly is disabled">;
2830
}
2931

3032
let CategoryName = "Parse Issue" in {

‎clang/include/clang/Basic/LangOptions.def

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ LANGOPT(MSBitfields , 1, 0, "Microsoft-compatible structure layout")
114114
LANGOPT(Freestanding, 1, 0, "freestanding implementation")
115115
LANGOPT(NoBuiltin , 1, 0, "disable builtin functions")
116116
LANGOPT(NoMathBuiltin , 1, 0, "disable math builtin functions")
117+
LANGOPT(GNUAsm , 1, 1, "GNU-style inline assembly")
117118

118119
BENIGN_LANGOPT(ThreadsafeStatics , 1, 1, "thread-safe static initializers")
119120
LANGOPT(POSIXThreads , 1, 0, "POSIX thread support")

‎clang/include/clang/Driver/Options.td

+5
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ def fno_autolink : Flag <["-"], "fno-autolink">, Group<f_Group>,
404404
Flags<[DriverOption, CC1Option]>,
405405
HelpText<"Disable generation of linker directives for automatic library linking">;
406406

407+
def fgnu_inline_asm : Flag<["-"], "fgnu-inline-asm">, Group<f_Group>, Flags<[DriverOption]>;
408+
def fno_gnu_inline_asm : Flag<["-"], "fno-gnu-inline-asm">, Group<f_Group>,
409+
Flags<[DriverOption, CC1Option]>,
410+
HelpText<"Disable GNU style inline asm">;
411+
407412
def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">,
408413
Group<f_Group>, Flags<[DriverOption, CC1Option]>,
409414
HelpText<"Enable sample-based profile guided optimizations">;

‎clang/lib/Driver/Tools.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -4320,6 +4320,11 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
43204320
false))
43214321
CmdArgs.push_back("-fasm-blocks");
43224322

4323+
// -fgnu-inline-asm is default.
4324+
if (!Args.hasFlag(options::OPT_fgnu_inline_asm,
4325+
options::OPT_fno_gnu_inline_asm, true))
4326+
CmdArgs.push_back("-fno-gnu-inline-asm");
4327+
43234328
// Enable vectorization per default according to the optimization level
43244329
// selected. For optimization levels that want vectorization we use the alias
43254330
// option to simplify the hasFlag logic.

‎clang/lib/Frontend/CompilerInvocation.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1563,6 +1563,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
15631563
Args.getLastArgValue(OPT_fmodule_implementation_of);
15641564
Opts.NativeHalfType = Opts.NativeHalfType;
15651565
Opts.HalfArgsAndReturns = Args.hasArg(OPT_fallow_half_arguments_and_returns);
1566+
Opts.GNUAsm = !Args.hasArg(OPT_fno_gnu_inline_asm);
15661567

15671568
if (!Opts.CurrentModule.empty() && !Opts.ImplementationOfModule.empty() &&
15681569
Opts.CurrentModule != Opts.ImplementationOfModule) {

‎clang/lib/Parse/ParseStmtAsm.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,11 @@ StmtResult Parser::ParseAsmStatement(bool &msAsm) {
615615
msAsm = true;
616616
return ParseMicrosoftAsmStatement(AsmLoc);
617617
}
618+
619+
// Check if GNU-style inline Asm is disabled.
620+
if (!getLangOpts().GNUAsm)
621+
Diag(AsmLoc, diag::err_gnu_inline_asm_disabled);
622+
618623
DeclSpec DS(AttrFactory);
619624
SourceLocation Loc = Tok.getLocation();
620625
ParseTypeQualifierListOpt(DS, AR_VendorAttributesParsed);

‎clang/test/Driver/ms-inline-asm.c renamed to ‎clang/test/Driver/inline-asm.c

+9
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@
1313
// RUN: FileCheck --check-prefix=CHECK-NO-BLOCKS < %t %s
1414

1515
// CHECK-NO-BLOCKS-NOT: "-fasm-blocks"
16+
17+
// RUN: %clang -target x86_64-apple-darwin10 \
18+
// RUN: -### -fsyntax-only -fno-gnu-inline-asm %s 2>&1 | \
19+
// RUN: FileCheck --check-prefix=CHECK-NO-GNU-INLINE-ASM %s
20+
// RUN: %clang -target x86_64-apple-darwin10 \
21+
// RUN: -### -fsyntax-only -fgnu-inline-asm -fno-gnu-inline-asm %s 2>&1 | \
22+
// RUN: FileCheck --check-prefix=CHECK-NO-GNU-INLINE-ASM %s
23+
24+
// CHECK-NO-GNU-INLINE-ASM: "-fno-gnu-inline-asm"

‎clang/test/Parser/ms-inline-asm.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// REQUIRES: x86-registered-target
22
// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -verify -fasm-blocks
3+
// Disabling gnu inline assembly should have no effect on this testcase
4+
// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -verify -fasm-blocks -fno-gnu-inline-asm
35

46
#define M __asm int 0x2c
57
#define M2 int

‎clang/test/Parser/no-gnu-inline-asm.c

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %clang_cc1 %s -triple i686-apple-darwin -verify -fsyntax-only -fno-gnu-inline-asm
2+
3+
void f (void) {
4+
long long foo = 0, bar;
5+
asm volatile("INST %0, %1" : "=r"(foo) : "r"(bar)); // expected-error {{GNU-style inline assembly is disabled}}
6+
return;
7+
}

0 commit comments

Comments
 (0)