From bbcba6a8f96da86c002db88c57d95030b63fa669 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Sat, 15 Nov 2025 14:23:08 -0800 Subject: [PATCH 1/6] [DiagnosticVerifier] add test with diagnostics in unparsed clang attr --- .../DiagnosticVerifier/clang-attribute.swift | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/Frontend/DiagnosticVerifier/clang-attribute.swift diff --git a/test/Frontend/DiagnosticVerifier/clang-attribute.swift b/test/Frontend/DiagnosticVerifier/clang-attribute.swift new file mode 100644 index 00000000000..d314cd1099b --- /dev/null +++ b/test/Frontend/DiagnosticVerifier/clang-attribute.swift @@ -0,0 +1,82 @@ +// RUN: %empty-directory(%t) +// RUN: split-file %s %t + +// RUN: not %target-swift-frontend -typecheck -verify %t/test.swift -I %t -plugin-path %swift-plugin-dir -Rmacro-expansions 2>&1 | \ +// RUN: %FileCheck %s --implicit-check-not error: --implicit-check-not note: --implicit-check-not warning: --implicit-check-not remark: --match-full-lines --sanitize TEST_H=%t%{fs-sep}test.h + +//--- test.h +void foo(int len, int *p) __attribute__(( + swift_attr("@_SwiftifyImport(.countedBy(pointer: .param(2), count: \"len\"))"))); + +//--- test.swift +import TestClang + +func bar(x: UnsafeMutableBufferPointer) { + foo(x) // trigger macro expansion +} + +//--- module.modulemap +module TestClang { + header "test.h" + export * +} + +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: error: unexpected remark produced: macro content: |/// This is an auto-generated wrapper for safer interop| +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here + // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) +// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file + +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: error: unexpected remark produced: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer) {| +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here + // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) +// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file + +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: error: unexpected remark produced: macro content: | let len = Int32(exactly: p.count)!| +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here + // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) +// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file + +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: error: unexpected remark produced: macro content: | return unsafe foo(len, p.baseAddress!)| +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here + // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) +// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file + +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: error: unexpected remark produced: macro content: |}| +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here + // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) +// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file + +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: remark: diagnostic produced elsewhere: macro content: |/// This is an auto-generated wrapper for safer interop| +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here + +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: remark: diagnostic produced elsewhere: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer) {| +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here + +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: remark: diagnostic produced elsewhere: macro content: | let len = Int32(exactly: p.count)!| +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here + +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: remark: diagnostic produced elsewhere: macro content: | return unsafe foo(len, p.baseAddress!)| +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here + +// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: remark: diagnostic produced elsewhere: macro content: |}| +// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here From 530588f53db6d2acfefcaac9f0f568e99a97eb73 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Fri, 14 Nov 2025 16:03:16 -0800 Subject: [PATCH 2/6] [DiagnosticVerifier] suggest outermost buffername for... ...-verify-additional-file It's not expected that users add macro expansion buffer names to -verify-additional-file. The recommended approach is to add the actual source file that the macro was expanded in, and use expected-expansion. --- lib/Frontend/DiagnosticVerifier.cpp | 11 ++++++++++- .../DiagnosticVerifier/clang-attribute.swift | 15 +++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/lib/Frontend/DiagnosticVerifier.cpp b/lib/Frontend/DiagnosticVerifier.cpp index e7dcedb344d..c406f41f9ae 100644 --- a/lib/Frontend/DiagnosticVerifier.cpp +++ b/lib/Frontend/DiagnosticVerifier.cpp @@ -430,7 +430,16 @@ bool DiagnosticVerifier::verifyUnrelated( auto diag = SM.GetMessage(Loc, llvm::SourceMgr::DK_Error, Message, {}, {}); printDiagnostic(diag); - auto FileName = SM.getIdentifierForBuffer(SM.findBufferContainingLoc(Loc)); + unsigned TopmostBufferID = SM.findBufferContainingLoc(Loc); + while (const GeneratedSourceInfo *GSI = + SM.getGeneratedSourceInfo(TopmostBufferID)) { + SourceLoc ParentLoc = GSI->originalSourceRange.getStart(); + if (ParentLoc.isInvalid()) + break; + TopmostBufferID = SM.findBufferContainingLoc(ParentLoc); + Loc = ParentLoc; + } + auto FileName = SM.getIdentifierForBuffer(TopmostBufferID); auto noteDiag = SM.GetMessage(Loc, llvm::SourceMgr::DK_Note, ("file '" + FileName + diff --git a/test/Frontend/DiagnosticVerifier/clang-attribute.swift b/test/Frontend/DiagnosticVerifier/clang-attribute.swift index d314cd1099b..3194c817545 100644 --- a/test/Frontend/DiagnosticVerifier/clang-attribute.swift +++ b/test/Frontend/DiagnosticVerifier/clang-attribute.swift @@ -23,40 +23,35 @@ module TestClang { // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: error: unexpected remark produced: macro content: |/// This is an auto-generated wrapper for safer interop| // CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file -// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) // CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: error: unexpected remark produced: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer) {| // CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file -// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) // CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: error: unexpected remark produced: macro content: | let len = Int32(exactly: p.count)!| // CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file -// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) // CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: error: unexpected remark produced: macro content: | return unsafe foo(len, p.baseAddress!)| // CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file -// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) // CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: error: unexpected remark produced: macro content: |}| // CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: note: file '@__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' is not parsed for 'expected' statements. Use '-verify-additional-file @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file -// CHECK: TEST_H:1:25: note: in expansion from here +// CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) // CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file From 703fc1c8df7b66ca65ef7adfe3c0f3a77193ed9d Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Fri, 14 Nov 2025 17:08:02 -0800 Subject: [PATCH 3/6] [ClangImporter] set zero-byte originalSourceRange for AttributeFromClang This won't affect diagnostic printing, as the diagnostic engine checks the GeneratedSourceInfoKind and stops expanding if it's an AttributeFromClang kind. This helps the diagnostic verifier expand to the original location in source code however. --- lib/ClangImporter/ImportDecl.cpp | 4 +++- .../DiagnosticVerifier/clang-attribute.swift | 20 ++++++++++++++----- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/ClangImporter/ImportDecl.cpp b/lib/ClangImporter/ImportDecl.cpp index 413bd3e4d72..500a860842f 100644 --- a/lib/ClangImporter/ImportDecl.cpp +++ b/lib/ClangImporter/ImportDecl.cpp @@ -8801,7 +8801,9 @@ SourceFile &ClangImporter::Implementation::getClangSwiftAttrSourceFile( auto bufferID = sourceMgr.addMemBufferCopy(attributeText); auto info = GeneratedSourceInfo{GeneratedSourceInfo::AttributeFromClang, - CharSourceRange(), + // NB: This source range is not used by the diagnostic engine, + // but it is traversed by DiagnostciVerifier. + CharSourceRange(MappedDecl->getStartLoc(), 0), sourceMgr.getRangeForBuffer(bufferID)}; info.astNode = static_cast(module); info.clangNode = MappedDecl->getClangNode(); diff --git a/test/Frontend/DiagnosticVerifier/clang-attribute.swift b/test/Frontend/DiagnosticVerifier/clang-attribute.swift index 3194c817545..2f5bbf99ad0 100644 --- a/test/Frontend/DiagnosticVerifier/clang-attribute.swift +++ b/test/Frontend/DiagnosticVerifier/clang-attribute.swift @@ -26,52 +26,62 @@ module TestClang { // CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) -// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here +// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: error: unexpected remark produced: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer) {| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) -// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here +// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: error: unexpected remark produced: macro content: | let len = Int32(exactly: p.count)!| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) -// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here +// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: error: unexpected remark produced: macro content: | return unsafe foo(len, p.baseAddress!)| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) -// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here +// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: error: unexpected remark produced: macro content: |}| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) -// CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here +// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: remark: diagnostic produced elsewhere: macro content: |/// This is an auto-generated wrapper for safer interop| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: remark: diagnostic produced elsewhere: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer) {| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: remark: diagnostic produced elsewhere: macro content: | let len = Int32(exactly: p.count)!| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: remark: diagnostic produced elsewhere: macro content: | return unsafe foo(len, p.baseAddress!)| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: remark: diagnostic produced elsewhere: macro content: |}| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here From b63abd860e1ccf1158d0fd7dc8aa2813b5e865e3 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Fri, 14 Nov 2025 18:02:02 -0800 Subject: [PATCH 4/6] [DiagnosticVerifier] emit placeholder when filename is empty This makes it more explicit and consistent, which are good properties for test output. It makes it easier both for humans and update-verify-tests to see what exactly is going on. This does not affect how diagnostics are displayed to users normally. --- lib/Frontend/DiagnosticVerifier.cpp | 9 +++- .../DiagnosticVerifier/clang-attribute.swift | 52 +++++++++---------- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/lib/Frontend/DiagnosticVerifier.cpp b/lib/Frontend/DiagnosticVerifier.cpp index c406f41f9ae..a962eec1287 100644 --- a/lib/Frontend/DiagnosticVerifier.cpp +++ b/lib/Frontend/DiagnosticVerifier.cpp @@ -485,7 +485,14 @@ void DiagnosticVerifier::printDiagnostic(const llvm::SMDiagnostic &Diag) const { ColoredStream coloredStream{stream}; raw_ostream &out = UseColor ? coloredStream : stream; llvm::SourceMgr &Underlying = SM.getLLVMSourceMgr(); - Underlying.PrintMessage(out, Diag); + if (Diag.getFilename().empty()) { + llvm::SMDiagnostic SubstDiag( + *Diag.getSourceMgr(), Diag.getLoc(), "", + Diag.getLineNo(), Diag.getColumnNo(), Diag.getKind(), Diag.getMessage(), + Diag.getLineContents(), Diag.getRanges(), Diag.getFixIts()); + Underlying.PrintMessage(out, SubstDiag); + } else + Underlying.PrintMessage(out, Diag); SourceLoc Loc = SourceLoc::getFromPointer(Diag.getLoc().getPointer()); if (Loc.isInvalid()) diff --git a/test/Frontend/DiagnosticVerifier/clang-attribute.swift b/test/Frontend/DiagnosticVerifier/clang-attribute.swift index 2f5bbf99ad0..e0a1b62e5e5 100644 --- a/test/Frontend/DiagnosticVerifier/clang-attribute.swift +++ b/test/Frontend/DiagnosticVerifier/clang-attribute.swift @@ -24,64 +24,64 @@ module TestClang { // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: error: unexpected remark produced: macro content: |/// This is an auto-generated wrapper for safer interop| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file -// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here - // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) -// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here -// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: :1:1: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) +// CHECK: TEST_H:1:6: note: in expansion from here +// CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: error: unexpected remark produced: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer) {| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file -// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: :1:1: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) -// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here -// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TEST_H:1:6: note: in expansion from here +// CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: error: unexpected remark produced: macro content: | let len = Int32(exactly: p.count)!| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file -// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: :1:1: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) -// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here -// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TEST_H:1:6: note: in expansion from here +// CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: error: unexpected remark produced: macro content: | return unsafe foo(len, p.baseAddress!)| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file -// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: :1:1: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) -// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here -// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TEST_H:1:6: note: in expansion from here +// CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: error: unexpected remark produced: macro content: |}| // CHECK: TEST_H:1:25: note: in expansion from here // CHECK: TEST_H:1:25: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file -// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: :1:1: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) -// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here -// CHECK: TMP_DIR/test.h:1:6: note: file 'TMP_DIR/test.h' is not parsed for 'expected' statements. Use '-verify-additional-file TMP_DIR/test.h' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file +// CHECK: TEST_H:1:6: note: in expansion from here +// CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: remark: diagnostic produced elsewhere: macro content: |/// This is an auto-generated wrapper for safer interop| // CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here -// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here +// CHECK: :1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: TEST_H:1:6: note: in expansion from here // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: remark: diagnostic produced elsewhere: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer) {| // CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here -// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here +// CHECK: :1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: TEST_H:1:6: note: in expansion from here // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: remark: diagnostic produced elsewhere: macro content: | let len = Int32(exactly: p.count)!| // CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here -// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here +// CHECK: :1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: TEST_H:1:6: note: in expansion from here // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: remark: diagnostic produced elsewhere: macro content: | return unsafe foo(len, p.baseAddress!)| // CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here -// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here +// CHECK: :1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: TEST_H:1:6: note: in expansion from here // CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: remark: diagnostic produced elsewhere: macro content: |}| // CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here -// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here +// CHECK: :1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here +// CHECK: TEST_H:1:6: note: in expansion from here From 62ba94ef12f4aef28518dffe5d225d3c7bdb3032 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Fri, 14 Nov 2025 18:49:01 -0800 Subject: [PATCH 5/6] [DiagnosticVerifier] don't repeat diagnostics in other files `verifyUnknown()` and `verifyUnrelated()` would not remove the diagnostics after reporting their errors, leading to the same diagnostics then being emitted a second time. This removes them from the list after emitting them, just like `verifyFile()` does. --- lib/Frontend/DiagnosticVerifier.cpp | 26 ++++++++++++------- .../DiagnosticVerifier/broken-c-module.swift | 4 +-- .../DiagnosticVerifier/clang-attribute.swift | 25 ------------------ test/Frontend/DiagnosticVerifier/verify.swift | 1 - .../Frontend/DiagnosticVerifier/verify2.swift | 1 - ...function-template-typechecker-errors.swift | 3 +-- 6 files changed, 19 insertions(+), 41 deletions(-) diff --git a/lib/Frontend/DiagnosticVerifier.cpp b/lib/Frontend/DiagnosticVerifier.cpp index a962eec1287..76c4bca6033 100644 --- a/lib/Frontend/DiagnosticVerifier.cpp +++ b/lib/Frontend/DiagnosticVerifier.cpp @@ -386,19 +386,23 @@ static void autoApplyFixes(SourceManager &SM, unsigned BufferID, bool DiagnosticVerifier::verifyUnknown( std::vector &CapturedDiagnostics) const { bool HadError = false; - for (unsigned i = 0, e = CapturedDiagnostics.size(); i != e; ++i) { - if (CapturedDiagnostics[i].Loc.isValid()) + auto CapturedDiagIter = CapturedDiagnostics.begin(); + while (CapturedDiagIter != CapturedDiagnostics.end()) { + if (CapturedDiagIter->Loc.isValid()) { + ++CapturedDiagIter; continue; + } HadError = true; std::string Message = ("unexpected " + - getDiagKindString(CapturedDiagnostics[i].Classification) + - " produced: " + CapturedDiagnostics[i].Message) + getDiagKindString(CapturedDiagIter->Classification) + + " produced: " + CapturedDiagIter->Message) .str(); auto diag = SM.GetMessage({}, llvm::SourceMgr::DK_Error, Message, {}, {}); printDiagnostic(diag); + CapturedDiagIter = CapturedDiagnostics.erase(CapturedDiagIter); } if (HadError) { @@ -414,17 +418,20 @@ bool DiagnosticVerifier::verifyUnknown( bool DiagnosticVerifier::verifyUnrelated( std::vector &CapturedDiagnostics) const { bool HadError = false; - for (unsigned i = 0, e = CapturedDiagnostics.size(); i != e; ++i) { - SourceLoc Loc = CapturedDiagnostics[i].Loc; - if (!Loc.isValid()) + auto CapturedDiagIter = CapturedDiagnostics.begin(); + while (CapturedDiagIter != CapturedDiagnostics.end()) { + SourceLoc Loc = CapturedDiagIter->Loc; + if (!Loc.isValid()) { + ++CapturedDiagIter; // checked by verifyUnknown continue; + } HadError = true; std::string Message = ("unexpected " + - getDiagKindString(CapturedDiagnostics[i].Classification) + - " produced: " + CapturedDiagnostics[i].Message) + getDiagKindString(CapturedDiagIter->Classification) + + " produced: " + CapturedDiagIter->Message) .str(); auto diag = SM.GetMessage(Loc, llvm::SourceMgr::DK_Error, Message, {}, {}); @@ -450,6 +457,7 @@ bool DiagnosticVerifier::verifyUnrelated( "ignore diagnostics in this file"), {}, {}); printDiagnostic(noteDiag); + CapturedDiagIter = CapturedDiagnostics.erase(CapturedDiagIter); } return HadError; diff --git a/test/Frontend/DiagnosticVerifier/broken-c-module.swift b/test/Frontend/DiagnosticVerifier/broken-c-module.swift index 53bc147105e..fef1d843a19 100644 --- a/test/Frontend/DiagnosticVerifier/broken-c-module.swift +++ b/test/Frontend/DiagnosticVerifier/broken-c-module.swift @@ -6,11 +6,9 @@ // 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: // CHECK: :0: error: fatal error encountered while in -verify mode -// CHECK: [[@LINE+7]]:8: error: unexpected error produced: could not build +// CHECK: [[@LINE+5]]:8: error: unexpected error produced: could not build // CHECK: error: unexpected note produced: in file included from :1: // CHECK: note: file '' is not parsed for 'expected' statements. Use '-verify-additional-file ' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file // CHECK: error: unexpected error produced: expected function body after function declarator // 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 -// CHECK: note: diagnostic produced elsewhere: in file included from -// CHECK: broken_c.h:2:11: error: diagnostic produced elsewhere: expected function body after function declarator import BrokenCModule diff --git a/test/Frontend/DiagnosticVerifier/clang-attribute.swift b/test/Frontend/DiagnosticVerifier/clang-attribute.swift index e0a1b62e5e5..7cc4605e223 100644 --- a/test/Frontend/DiagnosticVerifier/clang-attribute.swift +++ b/test/Frontend/DiagnosticVerifier/clang-attribute.swift @@ -60,28 +60,3 @@ module TestClang { // CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len")) // CHECK: TEST_H:1:6: note: in expansion from here // CHECK: TEST_H:1:6: note: file 'TEST_H' is not parsed for 'expected' statements. Use '-verify-additional-file TEST_H' to enable, or '-verify-ignore-unrelated' to ignore diagnostics in this file - -// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: remark: diagnostic produced elsewhere: macro content: |/// This is an auto-generated wrapper for safer interop| -// CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: :1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here -// CHECK: TEST_H:1:6: note: in expansion from here - -// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: remark: diagnostic produced elsewhere: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer) {| -// CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: :1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here -// CHECK: TEST_H:1:6: note: in expansion from here - -// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: remark: diagnostic produced elsewhere: macro content: | let len = Int32(exactly: p.count)!| -// CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: :1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here -// CHECK: TEST_H:1:6: note: in expansion from here - -// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: remark: diagnostic produced elsewhere: macro content: | return unsafe foo(len, p.baseAddress!)| -// CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: :1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here -// CHECK: TEST_H:1:6: note: in expansion from here - -// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: remark: diagnostic produced elsewhere: macro content: |}| -// CHECK: TEST_H:1:25: note: in expansion from here -// CHECK: :1:1: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here -// CHECK: TEST_H:1:6: note: in expansion from here diff --git a/test/Frontend/DiagnosticVerifier/verify.swift b/test/Frontend/DiagnosticVerifier/verify.swift index b62e44706f3..f96a0c42752 100644 --- a/test/Frontend/DiagnosticVerifier/verify.swift +++ b/test/Frontend/DiagnosticVerifier/verify.swift @@ -34,4 +34,3 @@ fn(()) // expected-error {{argument passed to call that takes no arguments}} let x: Array // CHECK: error: unexpected note produced: generic struct 'Array' declared here // 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 -// CHECK: note: diagnostic produced elsewhere: generic struct 'Array' declared here diff --git a/test/Frontend/DiagnosticVerifier/verify2.swift b/test/Frontend/DiagnosticVerifier/verify2.swift index ff3b23d6719..59cdb6553a7 100644 --- a/test/Frontend/DiagnosticVerifier/verify2.swift +++ b/test/Frontend/DiagnosticVerifier/verify2.swift @@ -44,7 +44,6 @@ extension Crap {} // expected-error {{non-nominal type 'Crap' (aka '() -> ()') c // CHECK: error: unexpected note produced: 'Bool' declared here // 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 -// CHECK: note: diagnostic produced elsewhere: 'Bool' declared here // Verify the serialized diags have the right magic at the top. // CHECK-SERIALIZED: DIA diff --git a/test/Interop/Cxx/templates/function-template-typechecker-errors.swift b/test/Interop/Cxx/templates/function-template-typechecker-errors.swift index 329fbe40b71..880435669b0 100644 --- a/test/Interop/Cxx/templates/function-template-typechecker-errors.swift +++ b/test/Interop/Cxx/templates/function-template-typechecker-errors.swift @@ -1,5 +1,4 @@ -// RUN: not %target-typecheck-verify-swift -verify-ignore-unrelated -I %S/Inputs -enable-experimental-cxx-interop 2>&1 | %FileCheck %s - +// RUN: not %target-typecheck-verify-swift -verify-ignore-unrelated -verify-ignore-unknown -I %S/Inputs -enable-experimental-cxx-interop 2>&1 | %FileCheck %s // README: If you just added support for protocol composition to the // ClangTypeConverter, please update this test to use a different type that we // don't support so the error messages here are still tested. From 69f6f477cd6da95cf6495db3e7c3cd0b75be10a8 Mon Sep 17 00:00:00 2001 From: "Henrik G. Olsson" Date: Fri, 14 Nov 2025 20:02:20 -0800 Subject: [PATCH 6/6] [DiagnosticVerifier] ensure expansion ancestors are populated Simply GSI->ancestors is not enough if the ancestors list has not been populated yet. Ensure this is done by calling getAncestors. --- lib/Frontend/DiagnosticVerifier.cpp | 7 ++++--- .../clang-importer-sdk/usr/include/ObjCConcurrency.h | 3 +++ test/Macros/accessor_macros.swift | 1 + test/Macros/expand_peers_hang.swift | 4 ++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Frontend/DiagnosticVerifier.cpp b/lib/Frontend/DiagnosticVerifier.cpp index 76c4bca6033..be790dd917a 100644 --- a/lib/Frontend/DiagnosticVerifier.cpp +++ b/lib/Frontend/DiagnosticVerifier.cpp @@ -20,6 +20,7 @@ #include "swift/Basic/ColorUtils.h" #include "swift/Basic/SourceManager.h" #include "swift/Parse/Lexer.h" +#include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatVariadic.h" @@ -1426,9 +1427,9 @@ DiagnosticVerifier::Result DiagnosticVerifier::verifyFile(unsigned BufferID) { // Diagnostics attached to generated sources originating in this // buffer also count as part of this buffer for this purpose. - const GeneratedSourceInfo *GSI = - SM.getGeneratedSourceInfo(CapturedDiagIter->SourceBufferID.value()); - if (!GSI || llvm::find(GSI->ancestors, BufferID) == GSI->ancestors.end()) { + unsigned scratch; + llvm::ArrayRef ancestors = SM.getAncestors(CapturedDiagIter->SourceBufferID.value(), scratch); + if (llvm::find(ancestors, BufferID) == ancestors.end()) { ++CapturedDiagIter; continue; } diff --git a/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h b/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h index 4b9f851e878..1ee9c2ef0b7 100644 --- a/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h +++ b/test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h @@ -233,6 +233,9 @@ MAIN_ACTOR MAIN_ACTOR __attribute__((__swift_attr__("@MainActor"))) @protocol Tr SENDABLE @interface SendableClass : NSObject @end +// expected-expansion@+3:13{{ +// expected-note@1 5{{conformance of 'NonSendableClass' to 'Sendable' has been explicitly marked unavailable here}} +// }} NONSENDABLE @interface NonSendableClass : NSObject @end // expected-note {{class 'NonSendableClass' does not conform to the 'Sendable' protocol}} ASSUME_NONSENDABLE_BEGIN diff --git a/test/Macros/accessor_macros.swift b/test/Macros/accessor_macros.swift index d64f91be117..6480f7279f1 100644 --- a/test/Macros/accessor_macros.swift +++ b/test/Macros/accessor_macros.swift @@ -102,6 +102,7 @@ struct MyBrokenStruct { /* expected-expansion@-2:25{{ expected-error@1:1{{variable already has a getter}} + expected-error@5:1{{variable already has a setter}} }} */ // CHECK-DIAGS: variable already has a getter diff --git a/test/Macros/expand_peers_hang.swift b/test/Macros/expand_peers_hang.swift index 10d7f974cf0..2377ed0fa42 100644 --- a/test/Macros/expand_peers_hang.swift +++ b/test/Macros/expand_peers_hang.swift @@ -11,6 +11,10 @@ macro HangingMacro() = #externalMacro(module: "MacroDefinition", type: "HangingM class Foo { init() {} + // expected-expansion@+5:32{{ + // expected-error@1{{unexpected token '}' in expanded member list}} + // expected-error@2{{expected declaration}} + // }} // expected-note@+1 2{{in expansion of macro 'HangingMacro' on property 'result' here}} @HangingMacro var result: Int // This comment makes it hang. }