[flang] Intermix messages from parser and semantic analysis (#90654)

When there are one or more fatal error messages produced by the parser,
semantic analysis is not performed. But when there are messages produced
by the parser and none of them are fatal, those messages are emitted to
the user before compilation continues with semantic analysis, and any
messages produced by semantics are emitted after the messages from
parsing.

This can be confusing for the user, as the messages may no longer all be
in source file location order. It also makes it difficult to write tests
that check for both non-fatal messages from parsing as well as messages
from semantics using inline CHECK: or other expected messages in test
source code.

This patch ensures that if semantic analysis is performed, and non-fatal
messages were produced by the parser, that all the messages will be
combined and emitted in source file order.
This commit is contained in:
Peter Klausler
2024-05-01 13:49:33 -07:00
committed by GitHub
parent b8c301f6e2
commit f2e808932c
8 changed files with 43 additions and 22 deletions

View File

@@ -123,12 +123,12 @@ static bool saveMLIRTempFile(const CompilerInvocation &ci,
bool PrescanAction::beginSourceFileAction() { return runPrescan(); }
bool PrescanAndParseAction::beginSourceFileAction() {
return runPrescan() && runParse();
return runPrescan() && runParse(/*emitMessages=*/true);
}
bool PrescanAndSemaAction::beginSourceFileAction() {
return runPrescan() && runParse() && runSemanticChecks() &&
generateRtTypeTables();
return runPrescan() && runParse(/*emitMessages=*/false) &&
runSemanticChecks() && generateRtTypeTables();
}
bool PrescanAndSemaDebugAction::beginSourceFileAction() {
@@ -137,8 +137,8 @@ bool PrescanAndSemaDebugAction::beginSourceFileAction() {
// from exiting early (i.e. in the presence of semantic errors). We should
// never do this in actions intended for end-users or otherwise regular
// compiler workflows!
return runPrescan() && runParse() && (runSemanticChecks() || true) &&
(generateRtTypeTables() || true);
return runPrescan() && runParse(/*emitMessages=*/false) &&
(runSemanticChecks() || true) && (generateRtTypeTables() || true);
}
static void addDependentLibs(mlir::ModuleOp &mlirModule, CompilerInstance &ci) {
@@ -275,8 +275,8 @@ bool CodeGenAction::beginSourceFileAction() {
ci.getDiagnostics().Report(diagID);
return false;
}
bool res = runPrescan() && runParse() && runSemanticChecks() &&
generateRtTypeTables();
bool res = runPrescan() && runParse(/*emitMessages=*/false) &&
runSemanticChecks() && generateRtTypeTables();
if (!res)
return res;