Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2717,6 +2717,8 @@ 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); + if (Args.hasArg(options::OPT_pg)) + return true; return shouldUseFramePointerForTarget(Args, Triple); } @@ -2726,6 +2728,8 @@ 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); + if (Args.hasArg(options::OPT_pg)) + return true; if (Triple.isPS4CPU()) return false; Index: lib/Frontend/CompilerInvocation.cpp =================================================================== --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -452,7 +452,8 @@ Opts.CXXCtorDtorAliases = Args.hasArg(OPT_mconstructor_aliases); Opts.CodeModel = getCodeModel(Args, Diags); Opts.DebugPass = Args.getLastArgValue(OPT_mdebug_pass); - Opts.DisableFPElim = Args.hasArg(OPT_mdisable_fp_elim); + Opts.DisableFPElim = + (Args.hasArg(OPT_mdisable_fp_elim) || Args.hasArg(OPT_pg)); Opts.DisableFree = Args.hasArg(OPT_disable_free); Opts.DisableTailCalls = Args.hasArg(OPT_mdisable_tail_calls); Opts.FloatABI = Args.getLastArgValue(OPT_mfloat_abi); Index: test/CodeGen/x86_64-profiling-keep-fp.c =================================================================== --- /dev/null +++ test/CodeGen/x86_64-profiling-keep-fp.c @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -triple x86_64-unknown-unknown -O3 -pg -S -o - %s | \ +// RUN: FileCheck %s + +// Test that the frame pointer is kept when compiling with +// profiling. + +//CHECK: pushq %rbp +int main(void) +{ + return 0; +}