diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -454,6 +454,8 @@ CodeGenOpts.XRayAlwaysEmitTypedEvents = LangOpts.XRayAlwaysEmitTypedEvents; CodeGenOpts.DisableFree = FrontendOpts.DisableFree; FrontendOpts.GenerateGlobalModuleIndex = FrontendOpts.UseGlobalModuleIndex; + if (FrontendOpts.ShowStats) + CodeGenOpts.ClearASTBeforeBackend = false; LangOpts.SanitizeCoverage = CodeGenOpts.hasSanitizeCoverage(); LangOpts.ForceEmitVTables = CodeGenOpts.ForceEmitVTables; LangOpts.SpeculativeLoadHardening = CodeGenOpts.SpeculativeLoadHardening; diff --git a/clang/test/Misc/clear-ast-before-backend.c b/clang/test/Misc/clear-ast-before-backend.c --- a/clang/test/Misc/clear-ast-before-backend.c +++ b/clang/test/Misc/clear-ast-before-backend.c @@ -1,3 +1,9 @@ // 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 + +// CHECK: *** Decl Stats: +// CHECK: {{.*}} decls total +// CHECK: 1 Function decls +// CHECK: Total bytes = void f() {}