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,11 @@ Flags<[DriverOption, CC1Option]>, HelpText<"Disable generation of linker directives for automatic library linking">; +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 @@ -4320,6 +4320,11 @@ 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. 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: test/Driver/inline-asm.c =================================================================== --- test/Driver/inline-asm.c +++ test/Driver/inline-asm.c @@ -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" 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 should have no effects 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 Index: test/Parser/no-gnu-inline-asm.c =================================================================== --- /dev/null +++ test/Parser/no-gnu-inline-asm.c @@ -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; +}