]> granicus.if.org Git - clang/commitdiff
Add a cc1 option to force disabling lifetime-markers emission from clang
authorMehdi Amini <mehdi.amini@apple.com>
Fri, 6 Jan 2017 23:18:09 +0000 (23:18 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Fri, 6 Jan 2017 23:18:09 +0000 (23:18 +0000)
Summary: This intended as a debugging/development flag only.

Differential Revision: https://reviews.llvm.org/D28385

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291300 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/CC1Options.td
include/clang/Frontend/CodeGenOptions.def
lib/CodeGen/BackendUtil.cpp
lib/CodeGen/CodeGenFunction.cpp
lib/Frontend/CompilerInvocation.cpp
test/CodeGen/lifetime2.c

index 2910b8521bab458328a2949f0e4f4f5dcc27076a..ab296ebb9f6a6d4a6974151fc65807fd3d98407d 100644 (file)
@@ -167,6 +167,9 @@ def disable_llvm_passes : Flag<["-"], "disable-llvm-passes">,
            "frontend by not running any LLVM passes at all">;
 def disable_llvm_optzns : Flag<["-"], "disable-llvm-optzns">,
   Alias<disable_llvm_passes>;
+def disable_lifetimemarkers : Flag<["-"], "disable-lifetime-markers">,
+  HelpText<"Disable lifetime-markers emission even when optimizations are "
+           "enabled">;
 def disable_red_zone : Flag<["-"], "disable-red-zone">,
   HelpText<"Do not emit code that uses the red zone.">;
 def dwarf_column_info : Flag<["-"], "dwarf-column-info">,
index 54c9f81265a67b3b9c175f182a05e3dfc3fac0d7..964a6cc2a007b93dfa7ea621957cf4ab0bf05002 100644 (file)
@@ -52,6 +52,7 @@ CODEGENOPT(DisableGCov       , 1, 0) ///< Don't run the GCov pass, for testing.
 CODEGENOPT(DisableLLVMPasses , 1, 0) ///< Don't run any LLVM IR passes to get
                                      ///< the pristine IR generated by the
                                      ///< frontend.
+CODEGENOPT(DisableLifetimeMarkers, 1, 0) ///< Don't emit any lifetime markers
 CODEGENOPT(ExperimentalNewPassManager, 1, 0) ///< Enables the new, experimental
                                              ///< pass manager.
 CODEGENOPT(DisableRedZone    , 1, 0) ///< Set when -mno-red-zone is enabled.
index 8dd1623ee2c283d735af7c5fe23cf9a8b3046e72..aa08a454e4e0ac3119d2f9ffe57346c3b56612ed 100644 (file)
@@ -312,7 +312,8 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
   // At O0 and O1 we only run the always inliner which is more efficient. At
   // higher optimization levels we run the normal inliner.
   if (CodeGenOpts.OptimizationLevel <= 1) {
-    bool InsertLifetimeIntrinsics = CodeGenOpts.OptimizationLevel != 0;
+    bool InsertLifetimeIntrinsics = (CodeGenOpts.OptimizationLevel != 0 &&
+                                     !CodeGenOpts.DisableLifetimeMarkers);
     PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics);
   } else {
     PMBuilder.Inliner = createFunctionInliningPass(
index 7cab13de923b399072f149e7cd0f5e9aea5a71eb..137c69420ddf6685342ce3441594ee7da5a5127e 100644 (file)
@@ -42,6 +42,9 @@ using namespace CodeGen;
 /// markers.
 static bool shouldEmitLifetimeMarkers(const CodeGenOptions &CGOpts,
                                       const LangOptions &LangOpts) {
+  if (CGOpts.DisableLifetimeMarkers)
+    return false;
+
   // Asan uses markers for use-after-scope checks.
   if (CGOpts.SanitizeAddressUseAfterScope)
     return true;
index 93bbcc42da1a35651e2ba243a8ce68183edef211..36f6b0a5111ab1b4c3e2cde70c506c0695893dc9 100644 (file)
@@ -520,6 +520,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
     Opts.EmitLLVMUseLists = A->getOption().getID() == OPT_emit_llvm_uselists;
 
   Opts.DisableLLVMPasses = Args.hasArg(OPT_disable_llvm_passes);
+  Opts.DisableLifetimeMarkers = Args.hasArg(OPT_disable_lifetimemarkers);
   Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
   Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables);
   Opts.UseRegisterSizedBitfieldAccess = Args.hasArg(
index 0d22282fdd437054790f519d2942d11eabb13073..4374b3c279c70067aa8616e66fb36cb8c3264335 100644 (file)
@@ -1,4 +1,6 @@
 // RUN: %clang -S -emit-llvm -o - -O2 %s | FileCheck %s -check-prefixes=CHECK,O2
+// RUN: %clang -S -emit-llvm -o - -O2 -Xclang -disable-lifetime-markers %s \
+// RUN:       | FileCheck %s -check-prefixes=CHECK,O0
 // RUN: %clang -S -emit-llvm -o - -O0 %s | FileCheck %s -check-prefixes=CHECK,O0
 
 extern int bar(char *A, int n);