r279546 - ARM-Darwin: ignore and diagnose attempts to omit frame pointer.
Tim Northover via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 23 11:12:59 PDT 2016
Author: tnorthover
Date: Tue Aug 23 13:12:58 2016
New Revision: 279546
URL: http://llvm.org/viewvc/llvm-project?rev=279546&view=rev
Log:
ARM-Darwin: ignore and diagnose attempts to omit frame pointer.
iOS (and other 32-bit ARM variants) always require a valid frame pointer to
improve backtraces. Previously the -fomit-frame-pointer and
-momit-leaf-frame-pointer options were being silently discarded via hacks in
the backend. It's better if Clang configures itself to emit the correct IR and
warns about (ignored) attempts to override this.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/frame-pointer-elim.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=279546&r1=279545&r2=279546&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Tue Aug 23 13:12:58 2016
@@ -169,6 +169,9 @@ def warn_drv_optimization_value : Warnin
InGroup<InvalidCommandLineArgument>;
def warn_ignored_gcc_optimization : Warning<"optimization flag '%0' is not supported">,
InGroup<IgnoredOptimizationArgument>;
+def warn_drv_unsupported_opt_for_target : Warning<
+ "optimization flag '%0' is not supported for target '%1'">,
+ InGroup<IgnoredOptimizationArgument>;
def warn_c_kext : Warning<
"ignoring -fapple-kext which is valid for C++ and Objective-C++ only">;
def warn_drv_input_file_unused : Warning<
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=279546&r1=279545&r2=279546&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Tue Aug 23 13:12:58 2016
@@ -1085,6 +1085,18 @@ DerivedArgList *Darwin::TranslateArgs(co
}
}
+ auto Arch = tools::darwin::getArchTypeForMachOArchName(BoundArch);
+ if ((Arch == llvm::Triple::arm || Arch == llvm::Triple::thumb)) {
+ if (Args.hasFlag(options::OPT_fomit_frame_pointer,
+ options::OPT_fno_omit_frame_pointer, false))
+ getDriver().Diag(clang::diag::warn_drv_unsupported_opt_for_target)
+ << "-fomit-frame-pointer" << BoundArch;
+ if (Args.hasFlag(options::OPT_momit_leaf_frame_pointer,
+ options::OPT_mno_omit_leaf_frame_pointer, false))
+ getDriver().Diag(clang::diag::warn_drv_unsupported_opt_for_target)
+ << "-momit-leaf-frame-pointer" << BoundArch;
+ }
+
return DAL;
}
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=279546&r1=279545&r2=279546&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Aug 23 13:12:58 2016
@@ -3232,8 +3232,20 @@ static bool areOptimizationsEnabled(cons
return false;
}
-static bool shouldUseFramePointerForTarget(const ArgList &Args,
- const llvm::Triple &Triple) {
+static bool mustUseFramePointerForTarget(const llvm::Triple &Triple) {
+ switch (Triple.getArch()){
+ default:
+ return false;
+ case llvm::Triple::arm:
+ case llvm::Triple::thumb:
+ // ARM Darwin targets require a frame pointer to be always present to aid
+ // offline debugging via backtraces.
+ return Triple.isOSDarwin();
+ }
+}
+
+static bool useFramePointerForTargetByDefault(const ArgList &Args,
+ const llvm::Triple &Triple) {
switch (Triple.getArch()) {
case llvm::Triple::xcore:
case llvm::Triple::wasm32:
@@ -3285,25 +3297,29 @@ static bool shouldUseFramePointer(const
const llvm::Triple &Triple) {
if (Arg *A = Args.getLastArg(options::OPT_fno_omit_frame_pointer,
options::OPT_fomit_frame_pointer))
- return A->getOption().matches(options::OPT_fno_omit_frame_pointer);
+ return A->getOption().matches(options::OPT_fno_omit_frame_pointer) ||
+ mustUseFramePointerForTarget(Triple);
+
if (Args.hasArg(options::OPT_pg))
return true;
- return shouldUseFramePointerForTarget(Args, Triple);
+ return useFramePointerForTargetByDefault(Args, Triple);
}
static bool shouldUseLeafFramePointer(const ArgList &Args,
const llvm::Triple &Triple) {
if (Arg *A = Args.getLastArg(options::OPT_mno_omit_leaf_frame_pointer,
options::OPT_momit_leaf_frame_pointer))
- return A->getOption().matches(options::OPT_mno_omit_leaf_frame_pointer);
+ return A->getOption().matches(options::OPT_mno_omit_leaf_frame_pointer) ||
+ mustUseFramePointerForTarget(Triple);
+
if (Args.hasArg(options::OPT_pg))
return true;
if (Triple.isPS4CPU())
return false;
- return shouldUseFramePointerForTarget(Args, Triple);
+ return useFramePointerForTargetByDefault(Args, Triple);
}
/// Add a CC1 option to specify the debug compilation directory.
Modified: cfe/trunk/test/Driver/frame-pointer-elim.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/frame-pointer-elim.c?rev=279546&r1=279545&r2=279546&view=diff
==============================================================================
--- cfe/trunk/test/Driver/frame-pointer-elim.c (original)
+++ cfe/trunk/test/Driver/frame-pointer-elim.c Tue Aug 23 13:12:58 2016
@@ -35,6 +35,24 @@
// RUN: FileCheck --check-prefix=OMIT_LEAF %s
// OMIT_LEAF: "-momit-leaf-frame-pointer"
+// RUN: %clang -### -target armv7s-apple-ios -fomit-frame-pointer %s 2>&1 | \
+// RUN: FileCheck --check-prefix=WARN-OMIT-7S %s
+// WARN-OMIT-7S: warning: optimization flag '-fomit-frame-pointer' is not supported for target 'armv7s'
+// WARN-OMIT-7S: "-mdisable-fp-elim"
+// WARN-OMIT-7S-NOT: "-momit-leaf-frame-pointer"
+
+// RUN: %clang -### -target armv7k-apple-watchos -fomit-frame-pointer %s 2>&1 | \
+// RUN: FileCheck --check-prefix=WARN-OMIT-7K %s
+// WARN-OMIT-7K: warning: optimization flag '-fomit-frame-pointer' is not supported for target 'armv7k'
+// WARN-OMIT-7K: "-mdisable-fp-elim"
+// WARN-OMIT-7K-NOT: "-momit-leaf-frame-pointer"
+
+// RUN: %clang -### -target armv7s-apple-ios8.0 -momit-leaf-frame-pointer %s 2>&1 | \
+// RUN: FileCheck --check-prefix=WARN-OMIT-LEAF-7S %s
+// WARN-OMIT-LEAF-7S: warning: optimization flag '-momit-leaf-frame-pointer' is not supported for target 'armv7s'
+// WARN-OMIT-LEAF-7S: "-mdisable-fp-elim"
+// WARN-OMIT-LEAF-7S-NOT: "-momit-leaf-frame-pointer"
+
// On the PS4, we default to omitting the frame pointer on leaf functions
// (OMIT_LEAF check line is above)
// RUN: %clang -### -target x86_64-scei-ps4 -S %s 2>&1 | \
More information about the cfe-commits
mailing list