Skip to content

Commit 341adb5

Browse files
committed
SILVerifier: print a readable error message when referencing an undefined SIL function
This error was not printed because the verifier complained before the error handling was done.
1 parent 8a5e011 commit 341adb5

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,6 @@ ParseIncompleteOSSA("parse-incomplete-ossa",
7070
//===----------------------------------------------------------------------===//
7171

7272
SILParserState::~SILParserState() {
73-
if (!ForwardRefFns.empty()) {
74-
for (auto Entry : ForwardRefFns) {
75-
if (Entry.second.Loc.isValid()) {
76-
M.getASTContext().Diags.diagnose(Entry.second.Loc,
77-
diag::sil_use_of_undefined_value,
78-
Entry.first.str());
79-
}
80-
}
81-
}
82-
8373
// Turn any debug-info-only function declarations into zombies.
8474
markZombies();
8575
}
@@ -93,6 +83,21 @@ void SILParserState::markZombies() {
9383
}
9484
}
9585

86+
bool SILParserState::diagnoseUndefinedValues(DiagnosticEngine &diags) {
87+
bool hasError = false;
88+
if (!ForwardRefFns.empty()) {
89+
for (auto Entry : ForwardRefFns) {
90+
if (Entry.second.Loc.isValid()) {
91+
diags.diagnose(Entry.second.Loc,
92+
diag::sil_use_of_undefined_value,
93+
Entry.first.str());
94+
hasError = true;
95+
}
96+
}
97+
}
98+
return hasError;
99+
}
100+
96101
std::unique_ptr<SILModule>
97102
ParseSILModuleRequest::evaluate(Evaluator &evaluator,
98103
ASTLoweringDescriptor desc) const {
@@ -111,6 +116,10 @@ ParseSILModuleRequest::evaluate(Evaluator &evaluator,
111116
}
112117

113118
auto hadError = parser.parseTopLevelSIL();
119+
120+
if (parserState.diagnoseUndefinedValues(parser.Diags))
121+
hadError = true;
122+
114123
if (hadError) {
115124
// The rest of the SIL pipeline expects well-formed SIL, so if we encounter
116125
// a parsing error, just return an empty SIL module.

lib/SIL/Parser/SILParserState.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class SILParserState : public SILParserStateBase {
5151
/// Did we parse a sil_stage for this module?
5252
bool DidParseSILStage = false;
5353

54+
bool diagnoseUndefinedValues(DiagnosticEngine &diags);
55+
5456
bool parseDeclSIL(Parser &P) override;
5557
bool parseDeclSILStage(Parser &P) override;
5658
bool parseSILVTable(Parser &P) override;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: not %target-sil-opt -o /dev/null %s 2>&1 | %FileCheck %s
2+
3+
// REQUIRES: asserts
4+
5+
sil_stage canonical
6+
7+
import Builtin
8+
9+
sil @undefined_function_ref : $@convention(thin) () -> () {
10+
bb0:
11+
// CHECK: :[[@LINE+1]]:21: error: use of undefined value 'undefined_function'
12+
%0 = function_ref @undefined_function : $@convention(thin) () -> ()
13+
%r = tuple ()
14+
return %r
15+
}
16+

0 commit comments

Comments
 (0)