Skip to content

Commit d388da7

Browse files
authored
Merge pull request #84753 from hnrklssn/fix-verify-all
[DiagnosticVerifier] Fix Twine use after free
2 parents 2d9b88f + f343289 commit d388da7

File tree

6 files changed

+57
-30
lines changed

6 files changed

+57
-30
lines changed

lib/Frontend/DiagnosticVerifier.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -431,14 +431,15 @@ bool DiagnosticVerifier::verifyUnrelated(
431431
printDiagnostic(diag);
432432

433433
auto FileName = SM.getIdentifierForBuffer(SM.findBufferContainingLoc(Loc));
434-
auto NoteMessage = ("file '" + FileName +
435-
"' is not parsed for 'expected' statements. Use "
436-
"'-verify-additional-file " +
437-
FileName +
438-
"' to enable, or '-verify-ignore-unrelated' to "
439-
"ignore diagnostics in this file");
440434
auto noteDiag =
441-
SM.GetMessage(Loc, llvm::SourceMgr::DK_Note, NoteMessage, {}, {});
435+
SM.GetMessage(Loc, llvm::SourceMgr::DK_Note,
436+
("file '" + FileName +
437+
"' is not parsed for 'expected' statements. Use "
438+
"'-verify-additional-file " +
439+
FileName +
440+
"' to enable, or '-verify-ignore-unrelated' to "
441+
"ignore diagnostics in this file"),
442+
{}, {});
442443
printDiagnostic(noteDiag);
443444
}
444445

test/Frontend/DiagnosticVerifier/broken-c-module.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
// This needs to be a separate test from verify.swift because compilation will
44
// terminate after the failing import statement.
55

6-
// RUN: not %target-typecheck-verify-swift -verify-ignore-unrelated -I %S/Inputs/broken-c-module 2>&1 | %FileCheck %s
6+
// RUN: not %target-typecheck-verify-swift -I %S/Inputs/broken-c-module 2>&1 | %FileCheck %s --implicit-check-not error: --implicit-check-not note: --implicit-check-not warning:
77

8-
// CHECK: [[@LINE+3]]:8: error: unexpected error produced: could not build
8+
// CHECK: <unknown>:0: error: fatal error encountered while in -verify mode
9+
// CHECK: [[@LINE+7]]:8: error: unexpected error produced: could not build
10+
// CHECK: error: unexpected note produced: in file included from <module-includes>:1:
11+
// CHECK: note: file '<module-includes>' is not parsed for 'expected' statements. Use '-verify-additional-file <module-includes>' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
12+
// CHECK: error: unexpected error produced: expected function body after function declarator
13+
// CHECK: note: file '{{.*}}broken_c.h' is not parsed for 'expected' statements. Use '-verify-additional-file {{.*}}broken_c.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
914
// CHECK: note: diagnostic produced elsewhere: in file included from <module-includes>
1015
// CHECK: broken_c.h:2:11: error: diagnostic produced elsewhere: expected function body after function declarator
1116
import BrokenCModule

test/Frontend/DiagnosticVerifier/fixits.swift

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Tests for fix-its on `-verify` mode.
22

3-
// RUN: not %target-typecheck-verify-swift 2>&1 | %FileCheck %s
3+
// RUN: not %target-typecheck-verify-swift 2>&1 | %FileCheck %s --implicit-check-not error: --implicit-check-not note: --implicit-check-not warning:
44

55
func labeledFunc(aa: Int, bb: Int) {}
66

77
func testNoneMarkerCheck() {
8+
// CHECK: [[@LINE+2]]:78: error: expected no fix-its; actual fix-it seen: {{.*}}3-16=unlabeledFunc{{.*}}
89
// CHECK: [[@LINE+1]]:87: error: A second {{\{\{}}none}} was found. It may only appear once in an expectation.
910
undefinedFunc() // expected-error {{cannot find 'undefinedFunc' in scope}} {{none}} {{none}}
1011

@@ -197,34 +198,44 @@ func test1Fixits() {
197198
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{15-18=xx}} {{15-18=aa}} {{none}}
198199

199200
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
200-
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{200:15-200:18=aa}}
201+
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{201:15-201:18=aa}}
201202
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
202-
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{202:15-18=aa}}
203+
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{203:15-18=aa}}
203204
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
204-
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{15-204:18=aa}}
205+
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{15-205:18=aa}}
205206
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
206207
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{-0:15-+0:18=aa}}
207208
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
208209
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{15--0:18=aa}}
209210
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
210-
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {+0:15-210:18=aa}}
211+
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {+0:15-211:18=aa}}
211212
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
212213
labeledFunc(aa: 0, // expected-error {{incorrect argument label in call (have 'aa:bbx:', expected 'aa:bb:')}} {{+1:15-+1:18=bb}}
213214
bbx: 1)
214215
// CHECK-NOT: [[@LINE+1]]:{{[0-9]+}}: error:
215-
labeledFunc(aa: 0, // expected-error {{incorrect argument label in call (have 'aa:bbx:', expected 'aa:bb:')}} {{216:15-+1:18=bb}}
216+
labeledFunc(aa: 0, // expected-error {{incorrect argument label in call (have 'aa:bbx:', expected 'aa:bb:')}} {{217:15-+1:18=bb}}
216217
bbx: 1)
217218

218219
// CHECK: [[@LINE+1]]:121: error: expected fix-it not seen; actual fix-it seen: {{\{\{}}15-18=aa}}
219-
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{61:15-18=aa}}
220+
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{62:15-18=aa}}
220221
// CHECK: [[@LINE+1]]:121: error: expected fix-it not seen; actual fix-it seen: {{\{\{}}15-18=aa}}
221222
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{-1:15-18=aa}}
222223
// CHECK: [[@LINE+1]]:121: error: expected fix-it not seen; actual fix-it seen: {{\{\{}}15-18=aa}}
223224
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{+0:15--1:18=aa}}
224225
// CHECK: [[@LINE+1]]:121: error: expected fix-it not seen; actual fix-it seen: {{\{\{}}15-18=aa}}
225-
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{61:15-+1:18=aa}}
226+
labeledFunc(aax: 0, bb: 1) // expected-error {{incorrect argument label in call (have 'aax:bb:', expected 'aa:bb:')}} {{62:15-+1:18=aa}}
226227
}
227228

229+
// CHECK: [[@LINE+10]]:6: error: unexpected note produced: 'unlabeledFunc' declared here
230+
// CHECK: [[@LINE+9]]:6: error: unexpected note produced: 'unlabeledFunc' declared here
231+
// CHECK: [[@LINE+8]]:6: error: unexpected note produced: 'unlabeledFunc' declared here
232+
// CHECK: [[@LINE+7]]:6: error: unexpected note produced: 'unlabeledFunc' declared here
233+
// CHECK: [[@LINE+6]]:6: error: unexpected note produced: 'unlabeledFunc' declared here
234+
// CHECK: [[@LINE+5]]:6: error: unexpected note produced: 'unlabeledFunc' declared here
235+
// CHECK: [[@LINE+4]]:6: error: unexpected note produced: 'unlabeledFunc' declared here
236+
// CHECK: [[@LINE+3]]:6: error: unexpected note produced: 'unlabeledFunc' declared here
237+
// CHECK: [[@LINE+2]]:6: error: unexpected note produced: 'unlabeledFunc' declared here
238+
// CHECK: [[@LINE+1]]:6: error: unexpected note produced: 'unlabeledFunc' declared here
228239
func unlabeledFunc(_ aa: Int) {}
229240

230241
func testDefaultedLineNumbers() {

test/Frontend/DiagnosticVerifier/multiple_prefix_invalid.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -verify -verify-additional-prefix first- -verify-additional-prefix first-second- -emit-sil -o /dev/null 2>&1 | %FileCheck %s
1+
// RUN: not --crash %target-swift-frontend %s -verify -verify-additional-prefix first- -verify-additional-prefix first-second- -emit-sil -o /dev/null 2>&1 | %FileCheck %s --implicit-check-not error: --implicit-check-not note: --implicit-check-not warning:
22

33
// This test makes sure that if we add prefixes such that an earlier prefix is a
44
// prefix of a later prefix, we crash. We do this since the earlier prefix will
@@ -9,6 +9,10 @@
99
// CHECK: Error! Found a verifier diagnostic additional prefix that is a prefix of a later prefix. The later prefix will never be pattern matched!
1010
// CHECK: First Prefix: first-
1111
// CHECK: Second Prefix: first-second-
12+
// CHECK: <unknown>:0: error: fatal error encountered during compilation; please submit a bug report
13+
// CHECK: <unknown>:0: note: Standard compiler error!
14+
15+
// CHECK: error:
1216

1317
func test() {
1418

test/Frontend/DiagnosticVerifier/verify.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Tests for the Swift frontends `-verify` mode.
22

3-
// RUN: not %target-typecheck-verify-swift -verify-ignore-unrelated 2>&1 | %FileCheck %s
3+
// RUN: not %target-typecheck-verify-swift 2>&1 | %FileCheck %s --implicit-check-not error: --implicit-check-not note: --implicit-check-not warning:
44

55
// CHECK: [[@LINE+1]]:1: error: unexpected error produced: cannot find 'undefinedFunc' in scope
66
undefinedFunc()
@@ -30,6 +30,8 @@ fn(()) // expected-error {{argument passed to call that takes no arguments}}
3030
// CHECK: [[@LINE+1]]:81: error: expected no fix-its; actual fix-it seen: {{[{][{]4-6=[}][}]}}
3131
fn(()) // expected-error {{argument passed to call that takes no arguments}} {{none}}
3232

33-
// CHECK: [[@LINE+2]]:8: error: unexpected error produced: generic type 'Array' specialized with too many type parameters
34-
// CHECK: note: diagnostic produced elsewhere: generic struct 'Array' declared here
33+
// CHECK: [[@LINE+1]]:8: error: unexpected error produced: generic type 'Array' specialized with too many type parameters
3534
let x: Array<Int, Int>
35+
// CHECK: error: unexpected note produced: generic struct 'Array' declared here
36+
// CHECK: note: file 'Swift.Array' is not parsed for 'expected' statements. Use '-verify-additional-file Swift.Array' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
37+
// CHECK: note: diagnostic produced elsewhere: generic struct 'Array' declared here
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: not %target-swift-frontend -typecheck -verify -verify-ignore-unrelated -serialize-diagnostics-path %t/serialized.dia %s 2>&1 | %FileCheck %s
3-
// RUN: not %target-swift-frontend -typecheck -verify -verify-ignore-unrelated -warnings-as-errors %s 2>&1 | %FileCheck %s -check-prefix CHECK-WARNINGS-AS-ERRORS
2+
// RUN: not %target-swift-frontend -typecheck -verify -serialize-diagnostics-path %t/serialized.dia %s 2>&1 | %FileCheck %s --check-prefixes CHECK,CHECK-WARNINGS-AS-WARNINGS --implicit-check-not error: --implicit-check-not note: --implicit-check-not warning:
3+
// RUN: not %target-swift-frontend -typecheck -verify -warnings-as-errors %s 2>&1 | %FileCheck %s -check-prefixes CHECK,CHECK-WARNINGS-AS-ERRORS --implicit-check-not error: --implicit-check-not note: --implicit-check-not warning:
44
// RUN: %FileCheck %s -check-prefix CHECK-SERIALIZED <%t/serialized.dia
55

66
// Wrong message
77
let x: Int = "hello, world!" // expected-error {{foo bar baz}}
88
// CHECK-NOT: error: cannot convert value of type 'String' to specified type 'Int'
9-
// CHECK: error: incorrect message found
9+
// CHECK: [[@LINE-2]]:50: error: incorrect message found
1010

1111
// Wrong column
1212
let y: Int = "hello, world!" // expected-error@:49 {{cannot convert value of type}}
13-
// CHECK: message found at column 14 but was expected to appear at column 49
13+
// CHECK: error: message found at column 14 but was expected to appear at column 49
1414

1515
// Wrong fix-it
1616
let z: Int = "hello, world!" as Any
1717
// expected-error@-1 {{cannot convert value of type}} {{3-3=foobarbaz}}
18-
// CHECK: expected fix-it not seen; actual fix-it seen: {{[{][{]}}36-36= as! Int{{[}][}]}}
18+
// CHECK: error: expected fix-it not seen; actual fix-it seen: {{[{][{]}}36-36= as! Int{{[}][}]}}
1919

2020
// Expected no fix-it
2121
let a: Bool = "hello, world!" as Any
2222
// expected-error@-1 {{cannot convert value of type}} {{none}}
23-
// CHECK: expected no fix-its; actual fix-it seen: {{[{][{]}}37-37= as! Bool{{[}][}]}}
23+
// CHECK: error: expected no fix-its; actual fix-it seen: {{[{][{]}}37-37= as! Bool{{[}][}]}}
2424

2525
// Unexpected error
2626
_ = foo()
27-
// CHECK: unexpected error produced: cannot find 'foo' in scope
27+
// CHECK: error: unexpected error produced: cannot find 'foo' in scope
2828

2929
func b() {
3030
let c = 2
3131
}
32-
// CHECK: unexpected warning produced: initialization of immutable value 'c' was never used
33-
// CHECK-WARNINGS-AS-ERRORS: unexpected error produced: initialization of immutable value 'c' was never used
32+
// CHECK-WARNINGS-AS-WARNINGS: error: unexpected warning produced: initialization of immutable value 'c' was never used
33+
// CHECK-WARNINGS-AS-ERRORS: error: unexpected error produced: initialization of immutable value 'c' was never used
3434

3535
typealias Crap = () -> ()
3636
extension Crap {} // expected-error {{non-nominal type 'Crap' (aka '() -> ()') cannot be extended}} {{documentation-file=foo-bar-baz}}
@@ -42,5 +42,9 @@ extension Crap {} // expected-error {{non-nominal type 'Crap' (aka '() -> ()') c
4242
extension Crap {} // expected-error {{non-nominal type 'Crap' (aka '() -> ()') cannot be extended}} {{documentation-file=nominal-types,foo-bar-baz}}
4343
// CHECK: error: expected documentation file not seen; actual documentation file: {{[{][{]}}documentation-file=nominal-types{{[}][}]}}
4444

45+
// CHECK: error: unexpected note produced: 'Bool' declared here
46+
// CHECK: note: file 'Swift.Bool' is not parsed for 'expected' statements. Use '-verify-additional-file Swift.Bool' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file
47+
// CHECK: note: diagnostic produced elsewhere: 'Bool' declared here
48+
4549
// Verify the serialized diags have the right magic at the top.
4650
// CHECK-SERIALIZED: DIA

0 commit comments

Comments
 (0)