diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -1363,6 +1363,17 @@ } } +static bool isLaxVectorConversionsDefault(const llvm::Triple &Triple) { + switch (Triple.getArch()) { + default: + return true; + + case llvm::Triple::thumb: + case llvm::Triple::thumbeb: + return Triple.getSubArch() != llvm::Triple::ARMSubArch_v8_1m_mainline; + } +} + static bool isNoCommonDefault(const llvm::Triple &Triple) { switch (Triple.getArch()) { default: @@ -4678,10 +4689,13 @@ if (TC.SupportsProfiling()) Args.AddLastArg(CmdArgs, options::OPT_mfentry); - // -flax-vector-conversions is default. - if (!Args.hasFlag(options::OPT_flax_vector_conversions, - options::OPT_fno_lax_vector_conversions)) + if (const Arg *A = Args.getLastArg(options::OPT_flax_vector_conversions, + options::OPT_fno_lax_vector_conversions)) { + if (A->getOption().matches(options::OPT_fno_lax_vector_conversions)) + CmdArgs.push_back("-fno-lax-vector-conversions"); + } else if (!isLaxVectorConversionsDefault(Triple)) { CmdArgs.push_back("-fno-lax-vector-conversions"); + } if (Args.getLastArg(options::OPT_fapple_kext) || (Args.hasArg(options::OPT_mkernel) && types::isCXX(InputType))) diff --git a/clang/test/Driver/lax-vector-conversions.c b/clang/test/Driver/lax-vector-conversions.c new file mode 100644 --- /dev/null +++ b/clang/test/Driver/lax-vector-conversions.c @@ -0,0 +1,8 @@ +// RUN: %clang --target=arm-arm-none-eabi -march=armv8.1m.main -### -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-STRICT %s + +// RUN: %clang --target=arm-arm-none-eabi -march=armv8a -### -c %s 2>&1 \ +// RUN: | FileCheck --check-prefix=CHECK-LAX %s + +// CHECK-STRICT: "-fno-lax-vector-conversions" +// CHECK-LAX-NOT: "-fno-lax-vector-conversions"