|
| 1 | +diff --git a/include/swift/Frontend/FrontendOptions.h b/include/swift/Frontend/FrontendOptions.h |
| 2 | +index c47fdaae886..aa9c265d6d3 100644 |
| 3 | +--- a/include/swift/Frontend/FrontendOptions.h |
| 4 | ++++ b/include/swift/Frontend/FrontendOptions.h |
| 5 | +@@ -212,6 +212,9 @@ public: |
| 6 | + /// The path to which we should output statistics files. |
| 7 | + std::string StatsOutputDir; |
| 8 | + |
| 9 | ++ /// CodeQL: Prevent ASTContext from being freed during at the frontend |
| 10 | ++ bool KeepASTContext = false; |
| 11 | ++ |
| 12 | + /// Trace changes to stats to files in StatsOutputDir. |
| 13 | + bool TraceStats = false; |
| 14 | + |
| 15 | +diff --git a/include/swift/FrontendTool/FrontendTool.h b/include/swift/FrontendTool/FrontendTool.h |
| 16 | +index 184e6196918..8bc237725b5 100644 |
| 17 | +--- a/include/swift/FrontendTool/FrontendTool.h |
| 18 | ++++ b/include/swift/FrontendTool/FrontendTool.h |
| 19 | +@@ -46,6 +46,9 @@ public: |
| 20 | + /// The frontend has performed semantic analysis. |
| 21 | + virtual void performedSemanticAnalysis(CompilerInstance &instance); |
| 22 | + |
| 23 | ++ /// CodeQL: The frontend has performed compilation. |
| 24 | ++ virtual void performedCompilation(CompilerInstance &instance); |
| 25 | ++ |
| 26 | + /// The frontend has performed basic SIL generation. |
| 27 | + /// SIL diagnostic passes have not yet been applied. |
| 28 | + virtual void performedSILGeneration(SILModule &module); |
| 29 | +diff --git a/lib/FrontendTool/FrontendTool.cpp b/lib/FrontendTool/FrontendTool.cpp |
| 30 | +index 47b8883f7e2..4080c02d6b0 100644 |
| 31 | +--- a/lib/FrontendTool/FrontendTool.cpp |
| 32 | ++++ b/lib/FrontendTool/FrontendTool.cpp |
| 33 | +@@ -1572,6 +1572,11 @@ static bool validateTBDIfNeeded(const CompilerInvocation &Invocation, |
| 34 | + } |
| 35 | + |
| 36 | + static void freeASTContextIfPossible(CompilerInstance &Instance) { |
| 37 | ++ // CodeQL: keep ASTContext until we are done with the extraction |
| 38 | ++ if (Instance.getInvocation().getFrontendOptions().KeepASTContext) { |
| 39 | ++ return; |
| 40 | ++ } |
| 41 | ++ |
| 42 | + // If the stats reporter is installed, we need the ASTContext to live through |
| 43 | + // the entire compilation process. |
| 44 | + if (Instance.getASTContext().Stats) { |
| 45 | +@@ -2321,6 +2326,10 @@ int swift::performFrontend(ArrayRef<const char *> Args, |
| 46 | + |
| 47 | + int ReturnValue = 0; |
| 48 | + bool HadError = performCompile(*Instance, ReturnValue, observer); |
| 49 | ++ // Compilation happened |
| 50 | ++ if (observer) { |
| 51 | ++ observer->performedCompilation(*Instance); |
| 52 | ++ } |
| 53 | + |
| 54 | + if (verifierEnabled) { |
| 55 | + DiagnosticEngine &diags = Instance->getDiags(); |
| 56 | +@@ -2348,3 +2357,5 @@ void FrontendObserver::configuredCompiler(CompilerInstance &instance) {} |
| 57 | + void FrontendObserver::performedSemanticAnalysis(CompilerInstance &instance) {} |
| 58 | + void FrontendObserver::performedSILGeneration(SILModule &module) {} |
| 59 | + void FrontendObserver::performedSILProcessing(SILModule &module) {} |
| 60 | ++// CodeQL: Add another hook right after compilation so that we can run the extraction |
| 61 | ++void FrontendObserver::performedCompilation(CompilerInstance &instance) {} |
0 commit comments