Skip to content

Commit 3323d61

Browse files
authored
Merge pull request #81258 from tshortli/clang-importer-warning-group
ClangImporter: Introduce the `#ClangDeclarationImport` diagnostic group
2 parents a1ea020 + 24fa9c8 commit 3323d61

File tree

9 files changed

+57
-35
lines changed

9 files changed

+57
-35
lines changed

include/swift/AST/DiagnosticGroups.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
GROUP(no_group, "")
4242

4343
GROUP(ActorIsolatedCall, "actor-isolated-call")
44-
GROUP(NonisolatedNonsendingByDefault, "nonisolated-nonsending-by-default")
44+
GROUP(ClangDeclarationImport, "clang-declaration-import")
4545
GROUP(ConformanceIsolation, "conformance-isolation")
4646
GROUP(DeprecatedDeclaration, "deprecated-declaration")
4747
GROUP(DynamicCallable, "dynamic-callable-requirements")
@@ -52,6 +52,7 @@ GROUP(IsolatedConformances, "isolated-conformances")
5252
GROUP(MultipleInheritance, "multiple-inheritance")
5353
GROUP(MutableGlobalVariable, "mutable-global-variable")
5454
GROUP(NominalTypes, "nominal-types")
55+
GROUP(NonisolatedNonsendingByDefault, "nonisolated-nonsending-by-default")
5556
GROUP(OpaqueTypeInference, "opaque-type-inference")
5657
GROUP(PreconcurrencyImport, "preconcurrency-import")
5758
GROUP(PropertyWrappers, "property-wrapper-requirements")

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ ERROR(emit_pcm_error,Fatal,
5151
ERROR(dump_pcm_error,Fatal,
5252
"failed to dump precompiled module '%0'", (StringRef))
5353

54-
WARNING(invalid_swift_name_method,none,
54+
GROUPED_WARNING(invalid_swift_name_method, ClangDeclarationImport, none,
5555
"too %select{few|many}0 parameters in swift_name attribute (expected %1; "
5656
"got %2)", (bool, unsigned, unsigned))
57-
WARNING(invalid_swift_name_for_decl,none,
57+
GROUPED_WARNING(invalid_swift_name_for_decl, ClangDeclarationImport, none,
5858
"custom Swift name '%0' ignored because it is not valid for %kindonly1; "
5959
"imported as %1 instead",
6060
(StringRef, ValueDecl *))
@@ -67,35 +67,35 @@ ERROR(swift_name_protocol_static, none, "swift_name cannot be used to define "
6767
ERROR(swift_name_no_prototype, none,
6868
"swift_name cannot be used on a non-prototyped function declaration", ())
6969

70-
WARNING(inconsistent_swift_name,none,
70+
GROUPED_WARNING(inconsistent_swift_name, ClangDeclarationImport, none,
7171
"inconsistent Swift name for Objective-C %select{method|property}0 "
7272
"'%1' in '%2' (%3 in '%4' vs. %5 in '%6')",
7373
(bool, StringRef, StringRef, DeclName, StringRef, DeclName,
7474
StringRef))
7575

76-
WARNING(swift_name_circular_context_import,none,
76+
GROUPED_WARNING(swift_name_circular_context_import, ClangDeclarationImport, none,
7777
"cycle detected while resolving '%0' in swift_name attribute for '%1'",
7878
(StringRef, StringRef))
7979
NOTE(swift_name_circular_context_import_other,none,
8080
"while resolving '%0' in swift_name attribute for '%1'",
8181
(StringRef, StringRef))
8282

83-
WARNING(unresolvable_clang_decl,none,
83+
GROUPED_WARNING(unresolvable_clang_decl, ClangDeclarationImport, none,
8484
"imported declaration '%0' could not be mapped to '%1'",
8585
(StringRef, StringRef))
8686

8787
NOTE(unresolvable_clang_decl_is_a_framework_bug,none,
8888
"please report this issue to the owners of '%0'",
8989
(StringRef))
9090

91-
WARNING(clang_swift_attr_unhandled,none,
91+
GROUPED_WARNING(clang_swift_attr_unhandled, ClangDeclarationImport, none,
9292
"ignoring unknown Swift attribute or modifier '%0'", (StringRef))
9393

94-
WARNING(clang_error_code_must_be_sendable,none,
94+
GROUPED_WARNING(clang_error_code_must_be_sendable, ClangDeclarationImport, none,
9595
"cannot make error code type '%0' non-sendable because Swift errors "
9696
"are always sendable", (StringRef))
9797

98-
WARNING(clang_ignored_sendable_attr,none,
98+
GROUPED_WARNING(clang_ignored_sendable_attr, ClangDeclarationImport, none,
9999
"cannot make type %0 sendable because '@Sendable' and '& Sendable' "
100100
"cannot be added to it",
101101
(Type))
@@ -108,18 +108,18 @@ WARNING(implicit_bridging_header_imported_from_module,none,
108108
"is deprecated and will be removed in a later version of Swift",
109109
(StringRef, Identifier))
110110

111-
WARNING(import_multiple_mainactor_attr,none,
111+
GROUPED_WARNING(import_multiple_mainactor_attr, ClangDeclarationImport, none,
112112
"this attribute for global actor '%0' is invalid; the declaration already has attribute for global actor '%1'",
113113
(StringRef, StringRef))
114114

115-
WARNING(contradicting_mutation_attrs,none,
115+
GROUPED_WARNING(contradicting_mutation_attrs, ClangDeclarationImport, none,
116116
"attribute '%0' is ignored when combined with attribute '%1'",
117117
(StringRef, StringRef))
118118

119-
WARNING(nonmutating_without_const,none,
119+
GROUPED_WARNING(nonmutating_without_const, ClangDeclarationImport, none,
120120
"attribute 'nonmutating' has no effect on non-const method", ())
121121

122-
WARNING(nonmutating_without_mutable_fields,none,
122+
GROUPED_WARNING(nonmutating_without_mutable_fields, ClangDeclarationImport, none,
123123
"attribute 'nonmutating' has no effect without any mutable fields", ())
124124

125125
ERROR(module_map_not_found, none, "module map file '%0' not found", (StringRef))
@@ -135,7 +135,7 @@ WARNING(libstdcxx_modulemap_not_found, none,
135135
"module map for libstdc++ not found for '%0'; C++ stdlib may be unavailable",
136136
(StringRef))
137137

138-
WARNING(api_pattern_attr_ignored, none,
138+
GROUPED_WARNING(api_pattern_attr_ignored, ClangDeclarationImport, none,
139139
"'%0' Swift attribute ignored on type '%1': type is not copyable or destructible",
140140
(StringRef, StringRef))
141141

@@ -226,7 +226,7 @@ ERROR(private_fileid_attr_repeated, none,
226226
NOTE(private_fileid_attr_here, none,
227227
"SWIFT_PRIVATE_FILEID annotation found here", ())
228228

229-
WARNING(private_fileid_attr_format_invalid, none,
229+
GROUPED_WARNING(private_fileid_attr_format_invalid, ClangDeclarationImport, none,
230230
"SWIFT_PRIVATE_FILEID annotation on '%0' does not have a valid file ID",
231231
(StringRef))
232232
REMARK(private_fileid_attr_format_specification, none,
@@ -306,12 +306,12 @@ ERROR(returns_retained_or_returns_unretained_for_non_cxx_frt_values, none,
306306
// TODO: In the next C++ interop version, convert this warning into an error and
307307
// stop importing unannotated C++ APIs that return SWIFT_SHARED_REFERENCE.
308308
// rdar://138806722
309-
WARNING(no_returns_retained_returns_unretained, none,
309+
GROUPED_WARNING(no_returns_retained_returns_unretained, ClangDeclarationImport, none,
310310
"%0 should be annotated with either SWIFT_RETURNS_RETAINED or "
311311
"SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE",
312312
(const clang::NamedDecl *))
313313

314-
WARNING(returns_retained_returns_unretained_on_overloaded_operator, none,
314+
GROUPED_WARNING(returns_retained_returns_unretained_on_overloaded_operator, ClangDeclarationImport, none,
315315
"SWIFT_RETURNS_RETAINED and SWIFT_RETURNS_UNRETAINED is not supported "
316316
"yet for overloaded C++ %0. Overloaded C++ operators always "
317317
"return "
@@ -322,7 +322,7 @@ WARNING(returns_retained_returns_unretained_on_overloaded_operator, none,
322322
// stop importing C++ types that inherit from SWIFT_SHARED_REFERENCE if the
323323
// Swift compiler cannot find unique retain/release functions.
324324
// rdar://145194375
325-
WARNING(cant_infer_frt_in_cxx_inheritance, none,
325+
GROUPED_WARNING(cant_infer_frt_in_cxx_inheritance, ClangDeclarationImport, none,
326326
"unable to infer SWIFT_SHARED_REFERENCE for %0, although one of its "
327327
"transitive base types is marked as SWIFT_SHARED_REFERENCE",
328328
(const clang::NamedDecl *))
@@ -355,8 +355,12 @@ NOTE(forward_declared_protocol_clashes_with_imported_objc_Swift_protocol, none,
355355
"its name conflicts with a %1 in module %2",
356356
(const clang::NamedDecl*, StringRef, StringRef))
357357

358-
WARNING(return_escapable_with_lifetimebound, none, "the returned type '%0' is annotated as escapable; it cannot have lifetime dependencies", (StringRef))
359-
WARNING(return_nonescapable_without_lifetimebound, none, "the returned type '%0' is annotated as non-escapable; its lifetime dependencies must be annotated", (StringRef))
358+
GROUPED_WARNING(return_escapable_with_lifetimebound, ClangDeclarationImport, none,
359+
"the returned type '%0' is annotated as escapable; it cannot have lifetime dependencies",
360+
(StringRef))
361+
GROUPED_WARNING(return_nonescapable_without_lifetimebound, ClangDeclarationImport, none,
362+
"the returned type '%0' is annotated as non-escapable; its lifetime dependencies must be annotated",
363+
(StringRef))
360364

361365
ERROR(unknown_template_parameter,none,
362366
"template parameter '%0' does not exist", (StringRef))

test/ClangImporter/Inputs/custom-modules/ImportAsMember.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ typedef float MNInnerFloat __attribute__((swift_name("IAMMultipleNested.Inner"))
7070

7171
typedef int IAMBadInnerInt
7272
__attribute__((swift_name("IAMNonexistent.Inner")));
73-
// CHECK: ImportAsMember.h:[[@LINE-1]]:{{[0-9]+}}: warning: imported declaration 'IAMBadInnerInt' could not be mapped to 'IAMNonexistent.Inner'
74-
// CHECK: note: please report this issue to the owners of 'ImportAsMember'
73+
// CHECK: ImportAsMember.h:[[@LINE-1]]:{{[0-9]+}}: warning: imported declaration 'IAMBadInnerInt' could not be mapped to 'IAMNonexistent.Inner' [#ClangDeclarationImport]
74+
// CHECK: note: please report this issue to the owners of 'ImportAsMember' [#ClangDeclarationImport]
7575
typedef int IAMBadInnerIntAPINotes;
7676
// CHECK: ImportAsMember.h:[[@LINE-1]]:{{[0-9]+}}: warning: imported declaration 'IAMBadInnerIntAPINotes' could not be mapped to 'IAMNonexistent.Inner2'
7777
// CHECK: note: please report this issue to the owners of 'ImportAsMember'

test/ClangImporter/attr-swift_name.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@ func test(_ i: Int) {
2020
// We only see these five warnings because Clang can catch the other invalid
2121
// cases, and marks the attribute as invalid ahead of time.
2222

23-
// CHECK: warning: too few parameters in swift_name attribute (expected 2; got 1)
23+
// CHECK: warning: too few parameters in swift_name attribute (expected 2; got 1) [#ClangDeclarationImport]
2424
// CHECK: + (instancetype)g:(id)x outParam:(int *)foo SWIFT_NAME(init(g:));
2525
// CHECK-NOT: warning:
2626
// CHECK: note: please report this issue to the owners of 'ObjCIRExtras'
2727
// CHECK-NOT: warning:
2828

29-
// CHECK: warning: cycle detected while resolving 'CircularName' in swift_name attribute for 'CircularName'
29+
// CHECK: warning: cycle detected while resolving 'CircularName' in swift_name attribute for 'CircularName' [#ClangDeclarationImport]
3030
// CHECK: SWIFT_NAME(CircularName.Inner) @interface CircularName : NSObject @end
3131
// CHECK-NOT: {{warning|note}}:
3232
// CHECK: note: please report this issue to the owners of 'ObjCIRExtras'
3333
// CHECK-NOT: warning:
3434

35-
// CHECK: warning: cycle detected while resolving 'MutuallyCircularNameB' in swift_name attribute for 'MutuallyCircularNameA'
35+
// CHECK: warning: cycle detected while resolving 'MutuallyCircularNameB' in swift_name attribute for 'MutuallyCircularNameA' [#ClangDeclarationImport]
3636
// CHECK: SWIFT_NAME(MutuallyCircularNameB.Inner) @interface MutuallyCircularNameA : NSObject @end
3737
// CHECK-NOT: {{warning|note}}:
3838
// CHECK: note: while resolving 'MutuallyCircularNameA' in swift_name attribute for 'MutuallyCircularNameB'

test/ClangImporter/duplicate_mainactor.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
// REQUIRES: concurrency
66
// REQUIRES: objc_interop
77

8-
// CHECK: DoubleMainActor.h:{{[0-9]+}}:{{[0-9]+}}: warning: this attribute for global actor '@MainActor' is invalid; the declaration already has attribute for global actor '@UIActor'
8+
// CHECK: DoubleMainActor.h:{{[0-9]+}}:{{[0-9]+}}: warning: this attribute for global actor '@MainActor' is invalid; the declaration already has attribute for global actor '@UIActor' [#ClangDeclarationImport]
99

10-
protocol P : DoubleMainActor {}
10+
protocol P : DoubleMainActor {}

test/IDE/print_omit_needless_words.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@
314314
// CHECK-OMIT-NEEDLESS-WORDS-NEXT: @available(swift, obsoleted: 3, renamed: "veryCarefullyBurn()")
315315
// CHECK-OMIT-NEEDLESS-WORDS-NEXT: func veryCarefullyBurnGarbage4DTypeRefMask_t()
316316

317-
// CHECK-OMIT-NEEDLESS-WORDS-DIAGS: inconsistent Swift name for Objective-C property 'conflictingProp1' in 'OMWSub' ('waggleProp1' in 'OMWWaggle' vs. 'wiggleProp1' in 'OMWSuper')
317+
// CHECK-OMIT-NEEDLESS-WORDS-DIAGS: inconsistent Swift name for Objective-C property 'conflictingProp1' in 'OMWSub' ('waggleProp1' in 'OMWWaggle' vs. 'wiggleProp1' in 'OMWSuper') [#ClangDeclarationImport]
318318

319319
// Don't drop the 'error'.
320320
// CHECK-ERRORS: func tryAndReturnError(_: ()) throws

test/Interop/Cxx/class/nonescapable-errors.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,16 @@ public func importInvalid(_ x: Invalid) {
111111
// CHECK: error: a function with a ~Escapable result needs a parameter to depend on
112112
// CHECK-NO-LIFETIMES: test.swift:11:32: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
113113
public func noAnnotations() -> View {
114-
// CHECK: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies
115-
// CHECK-NO-LIFETIMES: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies
114+
// CHECK: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
115+
// CHECK-NO-LIFETIMES: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
116116
f(nil)
117-
// CHECK: nonescapable.h:20:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies
118-
// CHECK-NO-LIFETIMES: nonescapable.h:20:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies
117+
// CHECK: nonescapable.h:20:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
118+
// CHECK-NO-LIFETIMES: nonescapable.h:20:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
119119
// No duplicate warning for f2:
120120
// CHECK-NOT: nonescapable.h:20
121121
f2(nil, nil)
122-
// CHECK: nonescapable.h:24:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated
123-
// CHECK-NO-LIFETIMES: nonescapable.h:24:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated
122+
// CHECK: nonescapable.h:24:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
123+
// CHECK-NO-LIFETIMES: nonescapable.h:24:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
124124
// CHECK-NO-LIFETIMES: nonescapable.h:24:6: error: a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'
125125
g(nil)
126126
h1(nil)

test/Interop/Cxx/foreign-reference/Inputs/cxx-functions-and-methods-returning-frt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ __attribute__((swift_attr("unsafe")));
179179

180180
// C++ APIs returning cxx frts (for testing diagnostics)
181181
struct StructWithAPIsReturningCxxFrt {
182-
static FRTStruct *_Nonnull StaticMethodReturningCxxFrt(); // expected-warning {{'StaticMethodReturningCxxFrt' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
182+
static FRTStruct *_Nonnull StaticMethodReturningCxxFrt(); // expected-warning {{'StaticMethodReturningCxxFrt' should be annotated with either SWIFT_RETURNS_RETAINED or SWIFT_RETURNS_UNRETAINED as it is returning a SWIFT_SHARED_REFERENCE}}
183183
static FRTStruct *_Nonnull StaticMethodReturningCxxFrtWithAnnotation()
184184
__attribute__((swift_attr("returns_retained")));
185185
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Imported Clang Declaration Warnings (`ClangDeclarationImport`)
2+
3+
4+
This diagnostic group covers all warnings related to malformed APIs that are imported into Swift from C, C++, and Obj-C headers.
5+
6+
As one example of a potential malformed API diagnostic, suppose a Clang module dependency contained the following declaration:
7+
8+
```
9+
typedef int NotificationIdentifier
10+
__attribute__((swift_name("Notification.Identifier")))
11+
```
12+
13+
The Swift compiler would emit the following warning if no type named `Notification` could be found:
14+
15+
```
16+
warning: imported declaration 'NotificationIdentifier' could not be mapped to 'Notification.Identifier’
17+
```

0 commit comments

Comments
 (0)