From e8e1ffef117aaad63139603b29d34a847f9c6208 Mon Sep 17 00:00:00 2001 From: Andrey Turetskiy Date: Mon, 20 Jun 2016 10:31:39 +0000 Subject: [PATCH] [X86] Add -mno-iamcu option. Add -mno-iamcu option to: 1) Countervail -miamcu option easily 2) Be compatible with GCC which supports this option Differential Revision: http://reviews.llvm.org/D21469 llvm-svn: 273147 --- clang/include/clang/Driver/Options.td | 1 + clang/lib/Driver/Driver.cpp | 35 +++++++++++++++------------ clang/lib/Driver/Tools.cpp | 10 +++++--- clang/test/Driver/miamcu-opt.c | 4 +++ 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 00523666de1d..992875811176 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1311,6 +1311,7 @@ def mx32 : Flag<["-"], "mx32">, Group, Flags<[DriverOption, CoreOption] def mabi_EQ : Joined<["-"], "mabi=">, Group; def miamcu : Flag<["-"], "miamcu">, Group, Flags<[DriverOption, CoreOption]>, HelpText<"Use Intel MCU ABI">; +def mno_iamcu : Flag<["-"], "mno-iamcu">, Group, Flags<[DriverOption, CoreOption]>; def malign_functions_EQ : Joined<["-"], "malign-functions=">, Group; def malign_loops_EQ : Joined<["-"], "malign-loops=">, Group; def malign_jumps_EQ : Joined<["-"], "malign-jumps=">, Group; diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 96971e91ae62..d8c83742495c 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -280,8 +280,9 @@ DerivedArgList *Driver::TranslateInputArgs(const InputArgList &Args) const { } // Enforce -static if -miamcu is present. - if (Args.hasArg(options::OPT_miamcu)) - DAL->AddFlagArg(0, Opts->getOption(options::OPT_static)); + if (Arg *Ar = Args.getLastArg(options::OPT_miamcu, options::OPT_mno_iamcu)) + if (Ar->getOption().matches(options::OPT_miamcu)) + DAL->AddFlagArg(0, Opts->getOption(options::OPT_static)); // Add a default value of -mlinker-version=, if one was given and the user // didn't specify one. @@ -375,22 +376,24 @@ static llvm::Triple computeTargetTriple(const Driver &D, } // Handle -miamcu flag. - if (Args.hasArg(options::OPT_miamcu)) { - if (Target.get32BitArchVariant().getArch() != llvm::Triple::x86) - D.Diag(diag::err_drv_unsupported_opt_for_target) << "-miamcu" - << Target.str(); + if (Arg *Ar = Args.getLastArg(options::OPT_miamcu, options::OPT_mno_iamcu)) { + if (Ar->getOption().matches(options::OPT_miamcu)) { + if (Target.get32BitArchVariant().getArch() != llvm::Triple::x86) + D.Diag(diag::err_drv_unsupported_opt_for_target) << "-miamcu" + << Target.str(); - if (A && !A->getOption().matches(options::OPT_m32)) - D.Diag(diag::err_drv_argument_not_allowed_with) - << "-miamcu" << A->getBaseArg().getAsString(Args); + if (A && !A->getOption().matches(options::OPT_m32)) + D.Diag(diag::err_drv_argument_not_allowed_with) + << "-miamcu" << A->getBaseArg().getAsString(Args); - Target.setArch(llvm::Triple::x86); - Target.setArchName("i586"); - Target.setEnvironment(llvm::Triple::UnknownEnvironment); - Target.setEnvironmentName(""); - Target.setOS(llvm::Triple::ELFIAMCU); - Target.setVendor(llvm::Triple::UnknownVendor); - Target.setVendorName("intel"); + Target.setArch(llvm::Triple::x86); + Target.setArchName("i586"); + Target.setEnvironment(llvm::Triple::UnknownEnvironment); + Target.setEnvironmentName(""); + Target.setOS(llvm::Triple::ELFIAMCU); + Target.setVendor(llvm::Triple::UnknownVendor); + Target.setVendorName("intel"); + } } return Target; diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index b911c17e2bce..a23f660a11b6 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -2243,10 +2243,12 @@ void Clang::AddX86TargetArgs(const ArgList &Args, } // Set flags to support MCU ABI. - if (Args.hasArg(options::OPT_miamcu)) { - CmdArgs.push_back("-mfloat-abi"); - CmdArgs.push_back("soft"); - CmdArgs.push_back("-mstack-alignment=4"); + if (Arg *A = Args.getLastArg(options::OPT_miamcu, options::OPT_mno_iamcu)) { + if (A->getOption().matches(options::OPT_miamcu)) { + CmdArgs.push_back("-mfloat-abi"); + CmdArgs.push_back("soft"); + CmdArgs.push_back("-mstack-alignment=4"); + } } } diff --git a/clang/test/Driver/miamcu-opt.c b/clang/test/Driver/miamcu-opt.c index d8dccde82214..7f96998837e9 100644 --- a/clang/test/Driver/miamcu-opt.c +++ b/clang/test/Driver/miamcu-opt.c @@ -4,9 +4,11 @@ // RUN: %clang -miamcu -no-canonical-prefixes %s -### -o %t.o 2>&1 | FileCheck %s // RUN: %clang -miamcu -no-canonical-prefixes -m32 %s -### -o %t.o 2>&1 | FileCheck %s // RUN: %clang -miamcu -no-canonical-prefixes -target x86_64-unknown-linux-gnu %s -### -o %t.o 2>&1 | FileCheck %s +// RUN: %clang -mno-iamcu -miamcu -no-canonical-prefixes %s -### -o %t.o 2>&1 | FileCheck %s // RUN: %clang -miamcu -no-canonical-prefixes -m64 %s -### -o %t.o 2>&1 | FileCheck %s -check-prefix=M64 // RUN: %clang -miamcu -no-canonical-prefixes -dynamic %s -### -o %t.o 2>&1 | FileCheck %s -check-prefix=DYNAMIC // RUN: %clang -miamcu -no-canonical-prefixes -target armv8-eabi %s -### -o %t.o 2>&1 | FileCheck %s -check-prefix=NOT-X86 +// RUN: %clang -miamcu -mno-iamcu -no-canonical-prefixes -target x86_64-unknown-linux-gnu %s -### -o %t.o 2>&1 | FileCheck %s -check-prefix=MNOIAMCU // M64: error: invalid argument '-miamcu' not allowed with '-m64' @@ -14,6 +16,8 @@ // NOT-X86: error: unsupported option '-miamcu' for target 'armv8---eabi' +// MNOIAMCU-NOT: "-triple" "i586-intel-elfiamcu" + // CHECK: "{{.*}}clang{{.*}}" "-cc1" // CHECK: "-triple" "i586-intel-elfiamcu" // CHECK: "-static-define"