Skip to content

Commit 3ae136c

Browse files
committed
[Frontend] Fix error detection
Seperating out TBD file generation uncovered a bug in the frontend where we could fail to notice that we emitted an error during the end-of-pipeline actions and returned a zero exit code. Tweak the logic to detect this case.
1 parent c5cd19a commit 3ae136c

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,10 @@ static bool generateCode(CompilerInstance &Instance, StringRef OutputFilename,
16511651
// Free up some compiler resources now that we have an IRModule.
16521652
freeASTContextIfPossible(Instance);
16531653

1654+
// If we emitted any errors while perfoming the end-of-pipeline actions, bail.
1655+
if (Instance.getDiags().hadAnyError())
1656+
return true;
1657+
16541658
// Now that we have a single IR Module, hand it over to performLLVM.
16551659
return performLLVM(opts, Instance.getDiags(), nullptr, HashGlobal, IRModule,
16561660
TargetMachine.get(), OutputFilename,
@@ -1772,21 +1776,17 @@ static bool performCompileStepsPostSILGen(CompilerInstance &Instance,
17721776
IRGenOpts, Invocation.getTBDGenOptions(), std::move(SM), PSPs,
17731777
OutputFilename, MSF, HashGlobal, ParallelOutputFilenames);
17741778

1775-
// Just because we had an AST error it doesn't mean we can't performLLVM.
1776-
bool HadError = Instance.getASTContext().hadError();
1777-
1778-
// If the AST Context has no errors but no IRModule is available,
1779-
// parallelIRGen happened correctly, since parallel IRGen produces multiple
1780-
// modules.
1779+
// If no IRModule is available, bail. This can either happen if IR generation
1780+
// fails, or if parallelIRGen happened correctly (in which case it would have
1781+
// already performed LLVM).
17811782
if (!IRModule)
1782-
return HadError;
1783+
return Instance.getDiags().hadAnyError();
17831784

17841785
if (validateTBDIfNeeded(Invocation, MSF, *IRModule.getModule()))
17851786
return true;
17861787

17871788
return generateCode(Instance, OutputFilename, IRModule.getModule(),
1788-
HashGlobal) ||
1789-
HadError;
1789+
HashGlobal);
17901790
}
17911791

17921792
static void emitIndexDataForSourceFile(SourceFile *PrimarySourceFile,

0 commit comments

Comments
 (0)