[PATCH] D112100: [clang] Add option to disable -clear-ast-before-backend

Arthur Eubanks via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 19 20:52:09 PDT 2021


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG063c2f89aa7f: [clang] Add option to disable -clear-ast-before-backend (authored by aeubanks).

Changed prior to commit:
  https://reviews.llvm.org/D112100?vs=380847&id=380849#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112100/new/

https://reviews.llvm.org/D112100

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/test/Misc/clear-ast-before-backend.c


Index: clang/test/Misc/clear-ast-before-backend.c
===================================================================
--- clang/test/Misc/clear-ast-before-backend.c
+++ clang/test/Misc/clear-ast-before-backend.c
@@ -1,9 +1,14 @@
-// RUN: %clang_cc1 -clear-ast-before-backend %s -emit-obj -o /dev/null -O1
-// RUN: %clang_cc1 -clear-ast-before-backend %s -emit-obj -o /dev/null -print-stats 2>&1 | FileCheck %s
+// REQUIRES: asserts
 
-// CHECK: *** Decl Stats:
-// CHECK: {{.*}} decls total
-// CHECK: 1 Function decls
-// CHECK: Total bytes =
+// RUN: %clang_cc1 -mllvm -debug-only=codegenaction -clear-ast-before-backend %s -emit-obj -o /dev/null -O1 2>&1 | FileCheck %s --check-prefix=YES
+// RUN: %clang_cc1 -mllvm -debug-only=codegenaction -clear-ast-before-backend -no-clear-ast-before-backend %s -emit-obj -o /dev/null -O1 2>&1 | FileCheck %s --allow-empty --check-prefix=NO
+// RUN: %clang_cc1 -clear-ast-before-backend %s -emit-obj -o /dev/null -print-stats 2>&1 | FileCheck %s --check-prefix=STATS
+
+// YES: Clearing AST
+// NO-NOT: Clearing AST
+// STATS: *** Decl Stats:
+// STATS: {{.*}} decls total
+// STATS: 1 Function decls
+// STATS: Total bytes =
 
 void f() {}
Index: clang/lib/CodeGen/CodeGenAction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -52,6 +52,8 @@
 using namespace clang;
 using namespace llvm;
 
+#define DEBUG_TYPE "codegenaction"
+
 namespace clang {
   class BackendConsumer;
   class ClangDiagnosticHandler final : public DiagnosticHandler {
@@ -352,6 +354,7 @@
       }
 
       if (CodeGenOpts.ClearASTBeforeBackend) {
+        LLVM_DEBUG(llvm::dbgs() << "Clearing AST...\n");
         // Access to the AST is no longer available after this.
         // Other things that the ASTContext manages are still available, e.g.
         // the SourceManager. It'd be nice if we could separate out all the
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5311,9 +5311,13 @@
 def disable_free : Flag<["-"], "disable-free">,
   HelpText<"Disable freeing of memory on exit">,
   MarshallingInfoFlag<FrontendOpts<"DisableFree">>;
-def clear_ast_before_backend : Flag<["-"], "clear-ast-before-backend">,
-  HelpText<"Clear the Clang AST before running backend code generation">,
-  MarshallingInfoFlag<CodeGenOpts<"ClearASTBeforeBackend">>;
+defm clear_ast_before_backend : BoolOption<"",
+  "clear-ast-before-backend",
+  CodeGenOpts<"ClearASTBeforeBackend">,
+  DefaultFalse,
+  PosFlag<SetTrue, [], "Clear">,
+  NegFlag<SetFalse, [], "Don't clear">,
+  BothFlags<[], " the Clang AST before running backend code generation">>;
 def enable_noundef_analysis : Flag<["-"], "enable-noundef-analysis">, Group<f_Group>,
   HelpText<"Enable analyzing function argument and return types for mandatory definedness">,
   MarshallingInfoFlag<CodeGenOpts<"EnableNoundefAttrs">>;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D112100.380849.patch
Type: text/x-patch
Size: 3058 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211020/f6fff5e9/attachment-0001.bin>


More information about the cfe-commits mailing list