Index: include/clang/Basic/DiagnosticParseKinds.td =================================================================== --- include/clang/Basic/DiagnosticParseKinds.td +++ include/clang/Basic/DiagnosticParseKinds.td @@ -25,6 +25,8 @@ "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 { Index: include/clang/Basic/LangOptions.def =================================================================== --- include/clang/Basic/LangOptions.def +++ include/clang/Basic/LangOptions.def @@ -114,6 +114,7 @@ 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") Index: include/clang/Driver/Options.td =================================================================== --- include/clang/Driver/Options.td +++ include/clang/Driver/Options.td @@ -404,6 +404,14 @@ Flags<[DriverOption, CC1Option]>, HelpText<"Disable generation of linker directives for automatic library linking">; +def finline_asm : Flag<["-"], "finline-asm">, Group, Flags<[DriverOption]>; +def fno_inline_asm : Flag<["-"], "fno-inline-asm">, Group, Flags<[DriverOption]>, + HelpText<"Disable inline assembly">; +def fgnu_inline_asm : Flag<["-"], "fgnu-inline-asm">, Group, Flags<[DriverOption]>; +def fno_gnu_inline_asm : Flag<["-"], "fno-gnu-inline-asm">, Group, + Flags<[DriverOption, CC1Option]>, + HelpText<"Disable GNU style inline asm">; + def fprofile_sample_use_EQ : Joined<["-"], "fprofile-sample-use=">, Group, Flags<[DriverOption, CC1Option]>, HelpText<"Enable sample-based profile guided optimizations">; Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -4315,11 +4315,21 @@ CmdArgs.push_back("-fno-spell-checking"); + // -fno-inline-asm, disable both gnu-style and ms-style inline asm // -fno-asm-blocks is default. - if (Args.hasFlag(options::OPT_fasm_blocks, options::OPT_fno_asm_blocks, - false)) + if (Args.hasFlag(options::OPT_fasm_blocks, + options::OPT_fno_asm_blocks, false) && + Args.hasFlag(options::OPT_finline_asm, + options::OPT_fno_inline_asm, true)) CmdArgs.push_back("-fasm-blocks"); + // -fgnu-inline-asm is default + if (Args.hasFlag(options::OPT_fno_gnu_inline_asm, + options::OPT_fgnu_inline_asm, false) || + Args.hasFlag(options::OPT_fno_inline_asm, + options::OPT_finline_asm, false)) + 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. Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -1563,6 +1563,7 @@ 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) { Index: lib/Parse/ParseStmtAsm.cpp =================================================================== --- lib/Parse/ParseStmtAsm.cpp +++ lib/Parse/ParseStmtAsm.cpp @@ -615,6 +615,11 @@ 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); Index: lib/Parse/Parser.cpp =================================================================== --- lib/Parse/Parser.cpp +++ lib/Parse/Parser.cpp @@ -1252,6 +1252,9 @@ assert(Tok.is(tok::kw_asm) && "Not an asm!"); SourceLocation Loc = ConsumeToken(); + if (!getLangOpts().GNUAsm) + Diag(Loc, diag::err_gnu_inline_asm_disabled); + if (Tok.is(tok::kw_volatile)) { // Remove from the end of 'asm' to the end of 'volatile'. SourceRange RemovalRange(PP.getLocForEndOfToken(Loc), Index: test/Driver/inline-asm.c =================================================================== --- /dev/null +++ test/Driver/inline-asm.c @@ -0,0 +1,32 @@ +// 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" + +// 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 + +// CHECK-NO-GNU-INLINE-ASM: "-fno-gnu-inline-asm" + +// RUN: %clang -target x86_64-apple-darwin10 \ +// RUN: -### -fsyntax-only -fno-inline-asm %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-NO-ASM %s +// RUN: %clang -target x86_64-apple-darwin10 \ +// RUN: -### -fsyntax-only -fno-inline-asm -fasm-block %s 2>&1 | \ +// RUN: FileCheck --check-prefix=CHECK-NO-ASM %s + +// CHECK-NO-ASM: "-fno-gnu-inline-asm" +// CHECK-NO-ASM-NOT: "-fasm-blocks" + Index: test/Driver/ms-inline-asm.c =================================================================== --- test/Driver/ms-inline-asm.c +++ /dev/null @@ -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" Index: test/Parser/ms-inline-asm.c =================================================================== --- test/Parser/ms-inline-asm.c +++ test/Parser/ms-inline-asm.c @@ -1,5 +1,7 @@ // REQUIRES: x86-registered-target // RUN: %clang_cc1 %s -triple i386-apple-darwin10 -verify -fasm-blocks +// disable gnu inline asm shouldn't affect +// RUN: %clang_cc1 %s -triple i386-apple-darwin10 -verify -fasm-blocks -fno-gnu-inline-asm #define M __asm int 0x2c #define M2 int Index: test/Parser/no-gnu-inline-asm.c =================================================================== --- /dev/null +++ test/Parser/no-gnu-inline-asm.c @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 %s -triple i686-apple-darwin -verify -fsyntax-only -fno-gnu-inline-asm + +extern void func() asm ("FUNC"); // expected-error {{GNU-style inline assembly is disabled}} + +void f (void) { + long long foo = 0, bar; + register int foo1 asm ("eax"); // expected-error {{GNU-style inline assembly is disabled}} + asm volatile("INST %0, %1" : "=r"(foo) : "r"(bar)); // expected-error {{GNU-style inline assembly is disabled}} + return; +}