From 7c97c574cc795705737cd0b73daf6867406fe624 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Mon, 6 Feb 2023 17:11:22 +0800 Subject: [Modules] Recreate file manager for ftime-trace when compiling a module Close https://github.com/llvm/llvm-project/issues/60544. The root cause for the issue is that when we compile a module unit, the file manager (and proprocessor and source manager) are owned by AST instead of the compilaton instance. So the file manager may be invalid when we want to create a time-report file for -ftime-trace when we are compiling a module unit. This patch tries to recreate the file manager for -ftime-trace if we find the file manager is not valid. --- clang/lib/Frontend/FrontendAction.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'clang/lib/Frontend/FrontendAction.cpp') diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index 1e27664..3551967 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -1117,6 +1117,9 @@ void FrontendAction::EndSourceFile() { // FrontendAction. CI.clearOutputFiles(/*EraseFiles=*/shouldEraseOutputFiles()); + // The resources are owned by AST when the current file is AST. + // So we reset the resources here to avoid users accessing it + // accidently. if (isCurrentFileAST()) { if (DisableFree) { CI.resetAndLeakPreprocessor(); -- cgit v1.1