Skip to content

Commit 703fc1c

Browse files
committed
[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.
1 parent 530588f commit 703fc1c

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8801,7 +8801,9 @@ SourceFile &ClangImporter::Implementation::getClangSwiftAttrSourceFile(
88018801
auto bufferID = sourceMgr.addMemBufferCopy(attributeText);
88028802

88038803
auto info = GeneratedSourceInfo{GeneratedSourceInfo::AttributeFromClang,
8804-
CharSourceRange(),
8804+
// NB: This source range is not used by the diagnostic engine,
8805+
// but it is traversed by DiagnostciVerifier.
8806+
CharSourceRange(MappedDecl->getStartLoc(), 0),
88058807
sourceMgr.getRangeForBuffer(bufferID)};
88068808
info.astNode = static_cast<void *>(module);
88078809
info.clangNode = MappedDecl->getClangNode();

test/Frontend/DiagnosticVerifier/clang-attribute.swift

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,52 +26,62 @@ module TestClang {
2626
// 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
2727
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
2828
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
29-
// 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
29+
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
30+
// 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
3031

3132
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: error: unexpected remark produced: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer<Int32>) {|
3233
// CHECK: TEST_H:1:25: note: in expansion from here
3334
// 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
3435
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
3536
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
36-
// 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
37+
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
38+
// 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
3739

3840
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: error: unexpected remark produced: macro content: | let len = Int32(exactly: p.count)!|
3941
// CHECK: TEST_H:1:25: note: in expansion from here
4042
// 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
4143
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
4244
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
43-
// 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
45+
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
46+
// 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
4447

4548
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: error: unexpected remark produced: macro content: | return unsafe foo(len, p.baseAddress!)|
4649
// CHECK: TEST_H:1:25: note: in expansion from here
4750
// 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
4851
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
4952
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
50-
// 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
53+
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
54+
// 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
5155

5256
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: error: unexpected remark produced: macro content: |}|
5357
// CHECK: TEST_H:1:25: note: in expansion from here
5458
// 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
5559
// CHECK: error: unexpected note produced: in expansion of macro '_SwiftifyImport' on global function 'foo' here
5660
// CHECK-NEXT: @_SwiftifyImport(.countedBy(pointer: .param(2), count: "len"))
57-
// 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
61+
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
62+
// 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
5863

5964
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:1:1: remark: diagnostic produced elsewhere: macro content: |/// This is an auto-generated wrapper for safer interop|
6065
// CHECK: TEST_H:1:25: note: in expansion from here
6166
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
67+
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
6268

6369
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:2:1: remark: diagnostic produced elsewhere: macro content: |@_alwaysEmitIntoClient @_disfavoredOverload public func foo(_ p: UnsafeMutableBufferPointer<Int32>) {|
6470
// CHECK: TEST_H:1:25: note: in expansion from here
6571
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
72+
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
6673

6774
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:3:1: remark: diagnostic produced elsewhere: macro content: | let len = Int32(exactly: p.count)!|
6875
// CHECK: TEST_H:1:25: note: in expansion from here
6976
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
77+
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
7078

7179
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:4:1: remark: diagnostic produced elsewhere: macro content: | return unsafe foo(len, p.baseAddress!)|
7280
// CHECK: TEST_H:1:25: note: in expansion from here
7381
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
82+
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here
7483

7584
// CHECK: @__swiftmacro_So3foo15_SwiftifyImportfMp_.swift:5:1: remark: diagnostic produced elsewhere: macro content: |}|
7685
// CHECK: TEST_H:1:25: note: in expansion from here
7786
// CHECK: note: diagnostic produced elsewhere: in expansion of macro '_SwiftifyImport' on global function 'foo' here
87+
// CHECK: TMP_DIR/test.h:1:6: note: in expansion from here

0 commit comments

Comments
 (0)