[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 15:19:32 PDT 2021


aeubanks created this revision.
aeubanks added reviewers: hans, dblaikie.
Herald added a subscriber: dang.
aeubanks requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Some downstream users have plugins that -clear-ast-before-backend may
affect. Add an option to opt out.


Repository:
  rG LLVM Github Monorepo

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
@@ -5314,6 +5314,9 @@
 def clear_ast_before_backend : Flag<["-"], "clear-ast-before-backend">,
   HelpText<"Clear the Clang AST before running backend code generation">,
   MarshallingInfoFlag<CodeGenOpts<"ClearASTBeforeBackend">>;
+def no_clear_ast_before_backend : Flag<["-"], "no-clear-ast-before-backend">,
+  HelpText<"Don't clear the Clang AST before running backend code generation">,
+  MarshallingInfoNegativeFlag<CodeGenOpts<"ClearASTBeforeBackend">>;
 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.380789.patch
Type: text/x-patch
Size: 2847 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211019/fcc4689d/attachment.bin>


More information about the cfe-commits mailing list