[clang] 063c2f8 - [clang] Add option to disable -clear-ast-before-backend
Arthur Eubanks via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 19 20:51:57 PDT 2021
Author: Arthur Eubanks
Date: 2021-10-19T20:51:48-07:00
New Revision: 063c2f89aa7f5b0b61a63d639d8124035f26935c
URL: https://github.com/llvm/llvm-project/commit/063c2f89aa7f5b0b61a63d639d8124035f26935c
DIFF: https://github.com/llvm/llvm-project/commit/063c2f89aa7f5b0b61a63d639d8124035f26935c.diff
LOG: [clang] Add option to disable -clear-ast-before-backend
Some downstream users have plugins that -clear-ast-before-backend may
affect. Add an option to opt out.
Reviewed By: dblaikie
Differential Revision: https://reviews.llvm.org/D112100
Added:
Modified:
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/CodeGenAction.cpp
clang/test/Misc/clear-ast-before-backend.c
Removed:
################################################################################
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 4d422abd03a0e..25f3ddd97f12a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5311,9 +5311,13 @@ def code_completion_with_fixits : Flag<["-"], "code-completion-with-fixits">,
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">>;
diff --git a/clang/lib/CodeGen/CodeGenAction.cpp b/clang/lib/CodeGen/CodeGenAction.cpp
index 881e30a4c8444..52c54d3c7a72a 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/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 @@ namespace clang {
}
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
diff --git a/clang/test/Misc/clear-ast-before-backend.c b/clang/test/Misc/clear-ast-before-backend.c
index 88809b86f866e..ba564dc378c18 100644
--- a/clang/test/Misc/clear-ast-before-backend.c
+++ b/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() {}
More information about the cfe-commits
mailing list