From 0874e538aaeaab95b23dc751911a2b121e9fa320 Mon Sep 17 00:00:00 2001 From: Bob Wilson Date: Tue, 29 Jul 2014 00:23:18 +0000 Subject: [PATCH] Fix up handling of ARM options for controlling strict alignment. The -mstrict-align option was originally added in r167619 as a target- independent option. It was then changed in r167623 to be implemented with an ARM-specific backend option, even though the code remained in the target-independent Clang::ConstructJob function. This means that if you used the -mstrict-align option with a non-ARM target, you would still get the -arm-strict-align option getting passed to the backend, which was harmless but gross. The driver option was then replaced by the GCC-compatible -m[no-]unaligned-access option (r189175) and modified to work with AArch64 (r208075). However, in the process, the help text for -mstrict-align was incorrectly changed to show it as only being supported for AArch64. Even worse, the logic for handling these options together with -mkernel was wrong for AArch64, where -mkernel does not currently imply strict alignment. This patch fixes up all of those things. Besides the obvious change to the option help text, it moves the logic into the ARM and AArch64-specific parts of the driver, so that the option will be correctly ignored for non-ARM targets. llvm-svn: 214148 --- clang/include/clang/Driver/Options.td | 2 +- clang/lib/Driver/Tools.cpp | 41 +++++++++++++++-------------------- clang/test/Driver/arm-alignment.c | 3 +++ 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 61e463c..7a68761f 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -1113,7 +1113,7 @@ def munaligned_access : Flag<["-"], "munaligned-access">, Group, Group, HelpText<"Force all memory accesses to be aligned (AArch32/AArch64 only)">; def mstrict_align : Flag<["-"], "mstrict-align">, Alias, Flags<[CC1Option,HelpHidden]>, - HelpText<"Force all memory accesses to be aligned (AArch64 only, same as mno-unaligned-access)">; + HelpText<"Force all memory accesses to be aligned (same as mno-unaligned-access)">; def mno_thumb : Flag<["-"], "mno-thumb">, Group; def mrestrict_it: Flag<["-"], "mrestrict-it">, Group, HelpText<"Disallow generation of deprecated IT blocks for ARMv8. It is on by default for ARMv8 Thumb mode.">; diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index adbe094..b607f2f 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -799,6 +799,18 @@ void Clang::AddARMTargetArgs(const ArgList &Args, CmdArgs.push_back("-arm-use-movt=0"); } + // -mkernel implies -mstrict-align; don't add the redundant option. + if (!KernelOrKext) { + if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access, + options::OPT_munaligned_access)) { + CmdArgs.push_back("-backend-option"); + if (A->getOption().matches(options::OPT_mno_unaligned_access)) + CmdArgs.push_back("-arm-strict-align"); + else + CmdArgs.push_back("-arm-no-strict-align"); + } + } + // Setting -mno-global-merge disables the codegen global merge pass. Setting // -mglobal-merge has no effect as the pass is enabled by default. if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge, @@ -873,9 +885,13 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args, CmdArgs.push_back("-target-abi"); CmdArgs.push_back(ABIName); - if (Args.hasArg(options::OPT_mstrict_align)) { + if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access, + options::OPT_munaligned_access)) { CmdArgs.push_back("-backend-option"); - CmdArgs.push_back("-aarch64-strict-align"); + if (A->getOption().matches(options::OPT_mno_unaligned_access)) + CmdArgs.push_back("-aarch64-strict-align"); + else + CmdArgs.push_back("-aarch64-no-strict-align"); } // Setting -mno-global-merge disables the codegen global merge pass. Setting @@ -3673,27 +3689,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment); CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment)); } - // -mkernel implies -mstrict-align; don't add the redundant option. - if (!KernelOrKext) { - if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access, - options::OPT_munaligned_access)) { - if (A->getOption().matches(options::OPT_mno_unaligned_access)) { - CmdArgs.push_back("-backend-option"); - if (getToolChain().getTriple().getArch() == llvm::Triple::aarch64 || - getToolChain().getTriple().getArch() == llvm::Triple::aarch64_be) - CmdArgs.push_back("-aarch64-strict-align"); - else - CmdArgs.push_back("-arm-strict-align"); - } else { - CmdArgs.push_back("-backend-option"); - if (getToolChain().getTriple().getArch() == llvm::Triple::aarch64 || - getToolChain().getTriple().getArch() == llvm::Triple::aarch64_be) - CmdArgs.push_back("-aarch64-no-strict-align"); - else - CmdArgs.push_back("-arm-no-strict-align"); - } - } - } if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it, options::OPT_mno_restrict_it)) { diff --git a/clang/test/Driver/arm-alignment.c b/clang/test/Driver/arm-alignment.c index 98046d7..e7b7ac3 100644 --- a/clang/test/Driver/arm-alignment.c +++ b/clang/test/Driver/arm-alignment.c @@ -44,5 +44,8 @@ // RUN: %clang -target aarch64-none-gnueabi -munaligned-access -mstrict-align -### %s 2> %t // RUN: FileCheck --check-prefix=CHECK-ALIGNED-AARCH64 < %t %s +// RUN: %clang -target aarch64-none-gnueabi -mkernel -mno-unaligned-access -### %s 2> %t +// RUN: FileCheck --check-prefix=CHECK-ALIGNED-AARCH64 < %t %s + // CHECK-ALIGNED-ARM: "-backend-option" "-arm-strict-align" // CHECK-ALIGNED-AARCH64: "-backend-option" "-aarch64-strict-align" -- 2.7.4