Skip to content

Commit 88c2269

Browse files
authored
Merge pull request swiftlang#77323 from swiftlang/gaborh/use-imported-locs
[cxx-interop] Use the locations imported from C++
2 parents fe6703b + 6d24c52 commit 88c2269

File tree

13 files changed

+33
-36
lines changed

13 files changed

+33
-36
lines changed

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ static_assert(sizeof(checkSourceLocType(&ID##Decl::getLoc)) == 2, \
10111011
return getLocFromSource();
10121012
switch(File->getKind()) {
10131013
case FileUnitKind::Source:
1014+
case FileUnitKind::ClangModule:
10141015
return getLocFromSource();
10151016
case FileUnitKind::SerializedAST: {
10161017
if (!SerializedOK)
@@ -1019,7 +1020,6 @@ static_assert(sizeof(checkSourceLocType(&ID##Decl::getLoc)) == 2, \
10191020
}
10201021
case FileUnitKind::Builtin:
10211022
case FileUnitKind::Synthesized:
1022-
case FileUnitKind::ClangModule:
10231023
case FileUnitKind::DWARFModule:
10241024
return SourceLoc();
10251025
}

lib/Sema/TypeCheckMacros.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,12 +1360,11 @@ static SourceFile *evaluateAttachedMacro(MacroDecl *macro, Decl *attachedTo,
13601360
if (!attrSourceFile)
13611361
return nullptr;
13621362

1363-
// If the declaration has no source location and comes from a Clang module,
1363+
// If the declaration comes from a Clang module,
13641364
// pretty-print the declaration and use that location.
13651365
SourceLoc attachedToLoc = attachedTo->getLoc();
13661366
bool isPrettyPrintedDecl = false;
1367-
if (attachedToLoc.isInvalid() &&
1368-
isa<ClangModuleUnit>(dc->getModuleScopeContext())) {
1367+
if (isa<ClangModuleUnit>(dc->getModuleScopeContext())) {
13691368
isPrettyPrintedDecl = true;
13701369
attachedToLoc = evaluateOrDefault(
13711370
ctx.evaluator, PrettyPrintDeclRequest{attachedTo}, SourceLoc());

test/ClangImporter/cfuncs_scope.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ func testLocalVsFileScope() {
88

99
theFunctionInQuestion()
1010
// CHECK: :[[@LINE-1]]:25: error: missing argument
11-
// CHECK: LocalVsFileScope.theFunctionInQuestion:1:{{[0-9]+}}: note:
12-
// This is not a wonderful test because it's relying on the diagnostic
13-
// engine's synthesis of fake declarations to figure out what module the
14-
// importer assigned the function to. But, well, that's what we get.
11+
// CHECK: LocalVsFileScope.h:{{[0-9]+}}:{{[0-9]+}}: note:
1512

1613
aFunctionInBase() // just make sure it's imported
1714
// CHECK-NOT: :[[@LINE-1]]:{{[0-9]+}}:

test/ClangImporter/diags-with-many-imports.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ import Module100
108108
obsoleted()
109109
// CHECK: [[@LINE-1]]:1: error:
110110
// CHECK: explicitly marked unavailable here
111-
// CHECK: func obsoleted()
111+
// CHECK: void obsoleted() __attribute__((unavailable));

test/ClangImporter/experimental_diagnostics_no_noise.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ s.c = 5
6060
// CHECK-NEXT: ctypes.h:{{[0-9]+}}:{{[0-9]+}}: note: built-in type 'Complex' not supported
6161
// CHECK-NEXT: int _Complex c;
6262
// CHECK-NEXT: ^
63-
// CHECK-NEXT: ctypes.PartialImport.a:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'a'?
64-
// CHECK-NEXT: public var a: Int32
65-
// CHECK-NEXT: ^
66-
// CHECK-NEXT: ctypes.PartialImport.b:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'b'?
67-
// CHECK-NEXT: public var b: Int32
68-
// CHECK-NEXT: ^
63+
// CHECK-NEXT: ctypes.h:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'a'?
64+
// CHECK-NEXT: int a;
65+
// CHECK-NEXT: ^
66+
// CHECK-NEXT: ctypes.h:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'b'?
67+
// CHECK-NEXT: int b;
68+
// CHECK-NEXT: ^
6969

7070
// CHECK-NOT: note
7171
// CHECK-NOT: warning

test/ClangImporter/experimental_diagnostics_opt_out.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ _ = bar.methodReturningForwardDeclaredInterface()
1919
let s: PartialImport
2020
s.c = 5
2121
// CHECK: experimental_diagnostics_opt_out.swift:{{[0-9]+}}:{{[0-9]+}}: error: value of type 'PartialImport' has no member 'c'
22-
// CHECK: ctypes.PartialImport.a:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'a'?
23-
// CHECK: ctypes.PartialImport.b:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'b'?
22+
// CHECK: ctypes.h:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'a'?
23+
// CHECK: ctypes.h:{{[0-9]+}}:{{[0-9]+}}: note: did you mean 'b'?
2424
// CHECK-NOT: warning
2525
// CHECK-NOT: error
2626
// CHECK-NOT: note

test/ClangImporter/generic_compatibility_alias.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ import ObjCIRExtras
1111

1212
func foo(_: SwiftConstrGenericNameAlias<String>) {
1313
// expected-error@-1 {{'SwiftConstrGenericNameAlias' requires that 'String' inherit from 'NSNumber'}}
14-
// expected-note@-2 {{requirement specified as 'T' : 'NSNumber' [with T = String]}}
14+
// TODO: validate node in imported Obj-C header.
1515
}
1616

1717
func faz(_: SwiftGenericNameAlias<Int>) {
1818
// expected-error@-1 {{'SwiftGenericNameAlias' requires that 'Int' be a class type}}
19-
// expected-note@-2 {{requirement specified as 'T' : 'AnyObject' [with T = Int]}}
19+
// TODO: validate node in imported Obj-C header.
2020
}
2121

2222
func bar(_: SwiftGenericNameAlias<NSNumber>) {} // Ok

test/ClangImporter/objc_bridging_generics.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ func testImportedTypeParamRequirements() {
8888
let _ = PettableContainer<Rock>()
8989
let _ = PettableContainer<Porcupine>() // expected-error{{type 'Porcupine' does not conform to protocol 'Pettable'}}
9090
let _ = PettableContainer<Cat>()
91-
let _ = AnimalContainer<Desk>() // expected-error{{'AnimalContainer' requires that 'Desk' inherit from 'Animal'}} expected-note{{requirement specified as 'T' : 'Animal' [with T = Desk]}}
92-
let _ = AnimalContainer<Rock>() // expected-error{{'AnimalContainer' requires that 'Rock' inherit from 'Animal'}} expected-note{{requirement specified as 'T' : 'Animal' [with T = Rock]}}
91+
let _ = AnimalContainer<Desk>() // expected-error{{'AnimalContainer' requires that 'Desk' inherit from 'Animal'}} // TODO: add test for note appearing in Obj-c header.
92+
let _ = AnimalContainer<Rock>() // expected-error{{'AnimalContainer' requires that 'Rock' inherit from 'Animal'}} // TODO: add test for note appearing in Obj-c header.
9393
let _ = AnimalContainer<Porcupine>()
9494
let _ = AnimalContainer<Cat>()
95-
let _ = PettableAnimalContainer<Desk>() // expected-error{{'PettableAnimalContainer' requires that 'Desk' inherit from 'Animal'}} expected-note{{requirement specified as 'T' : 'Animal' [with T = Desk]}}
96-
let _ = PettableAnimalContainer<Rock>() // expected-error{{'PettableAnimalContainer' requires that 'Rock' inherit from 'Animal'}} expected-note{{requirement specified as 'T' : 'Animal' [with T = Rock]}}
95+
let _ = PettableAnimalContainer<Desk>() // expected-error{{'PettableAnimalContainer' requires that 'Desk' inherit from 'Animal'}} // TODO: add test for note appearing in Obj-c header.
96+
let _ = PettableAnimalContainer<Rock>() // expected-error{{'PettableAnimalContainer' requires that 'Rock' inherit from 'Animal'}} // TODO: add test for note appearing in Obj-c header.
9797
let _ = PettableAnimalContainer<Porcupine>() // expected-error{{type 'Porcupine' does not conform to protocol 'Pettable'}}
9898
let _ = PettableAnimalContainer<Cat>()
9999
}

test/DebugInfo/test-foundation.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class MyObject : NSObject {
2626
// directly.
2727
// IMPORT-CHECK-DAG: !DIImportedEntity(tag: DW_TAG_imported_module, {{.*}}entity: ![[OVERLAY]]
2828

29-
// ALLOCCTOR-CHECK: ![[F:.*]] = !DIFile(filename: "<compiler-generated>",
3029
// ALLOCCTOR-CHECK: distinct !DISubprogram(name: "init", linkageName: "$sSo7NSArrayCABycfC"
31-
// ALLOCCTOR-CHECK-SAME: file: ![[F]],
30+
// ALLOCCTOR-CHECK-SAME: file: ![[F:[0-9]+]],
31+
// ALLOCCTOR-CHECK: ![[F]] = !DIFile(filename: "{{.*}}/NSArray.h",
3232
@objc func foo(_ obj: MyObject) {
3333
return obj.foo(obj)
3434
}

test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ typedef void ( ^ObjCErrorHandler )( NSError * _Nullable inError );
179179
- (void) myMethod:(NSInteger)value1 foo:(NSInteger)value2;
180180
@end
181181

182-
@interface GenericObject<T> : NSObject
182+
@interface GenericObject<T> : NSObject // expected-note {{generic class 'GenericObject' does not conform to the 'Sendable' protocol}}
183183
- (void)doSomethingWithCompletionHandler:(void (^)(T _Nullable_result, NSError * _Nullable))completionHandler;
184184
- (void)doAnotherThingWithCompletionHandler:(void (^)(GenericObject<T> *_Nullable))completionHandler;
185185
@end
@@ -218,7 +218,7 @@ MAIN_ACTOR MAIN_ACTOR __attribute__((__swift_attr__("@MainActor"))) @protocol Tr
218218

219219
SENDABLE @interface SendableClass : NSObject @end
220220

221-
NONSENDABLE @interface NonSendableClass : NSObject @end
221+
NONSENDABLE @interface NonSendableClass : NSObject @end // expected-note {{class 'NonSendableClass' does not conform to the 'Sendable' protocol}}
222222

223223
ASSUME_NONSENDABLE_BEGIN
224224

@@ -232,14 +232,14 @@ SENDABLE @protocol SendableProtocol @end
232232
typedef NS_ENUM(unsigned, SendableEnum) {
233233
SendableEnumFoo, SendableEnumBar
234234
};
235-
typedef NS_ENUM(unsigned, NonSendableEnum) {
235+
typedef NS_ENUM(unsigned, NonSendableEnum) { // expected-note {{enum 'NonSendableEnum' does not conform to the 'Sendable' protocol}}
236236
NonSendableEnumFoo, NonSendableEnumBar
237237
} NONSENDABLE;
238238

239239
typedef NS_OPTIONS(unsigned, SendableOptions) {
240240
SendableOptionsFoo = 1 << 0, SendableOptionsBar = 1 << 1
241241
};
242-
typedef NS_OPTIONS(unsigned, NonSendableOptions) {
242+
typedef NS_OPTIONS(unsigned, NonSendableOptions) { // expected-note {{struct 'NonSendableOptions' does not conform to the 'Sendable' protocol}}
243243
NonSendableOptionsFoo = 1 << 0, NonSendableOptionsBar = 1 << 1
244244
} NONSENDABLE;
245245

@@ -264,10 +264,10 @@ UI_ACTOR
264264
@end
265265

266266
typedef NSString *SendableStringEnum NS_STRING_ENUM;
267-
typedef NSString *NonSendableStringEnum NS_STRING_ENUM NONSENDABLE;
267+
typedef NSString *NonSendableStringEnum NS_STRING_ENUM NONSENDABLE; // expected-note {{struct 'NonSendableStringEnum' does not conform to the 'Sendable' protocol}}
268268

269269
typedef NSString *SendableStringStruct NS_EXTENSIBLE_STRING_ENUM;
270-
typedef NSString *NonSendableStringStruct NS_EXTENSIBLE_STRING_ENUM NONSENDABLE;
270+
typedef NSString *NonSendableStringStruct NS_EXTENSIBLE_STRING_ENUM NONSENDABLE; // expected-note {{struct 'NonSendableStringStruct' does not conform to the 'Sendable' protocol}}
271271

272272
SENDABLE
273273
typedef struct {

0 commit comments

Comments
 (0)