Skip to content

Commit 9a150fb

Browse files
beccadaxmilseman
authored andcommitted
[PrintAsObjC] Disable -Watimport-in-framework-header warning in generated headers (#20086)
This is a new warning in clang when you use @import in a framework header. That’s often a mistake, but it isn’t in our generated -Swift.h headers. If we’re building with a clang that supports this warning, we’ll now emit a pragma to disable it.
1 parent 90767d0 commit 9a150fb

File tree

6 files changed

+28
-10
lines changed

6 files changed

+28
-10
lines changed

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,6 +2729,10 @@ class ModuleWriter {
27292729
void writeImports(raw_ostream &out) {
27302730
out << "#if __has_feature(modules)\n";
27312731

2732+
out << "#if __has_warning(\"-Watimport-in-framework-header\")\n"
2733+
<< "#pragma clang diagnostic ignored \"-Watimport-in-framework-header\"\n"
2734+
<< "#endif\n";
2735+
27322736
// Sort alphabetically for determinism and consistency.
27332737
SmallVector<ImportModuleTy, 8> sortedImports{imports.begin(),
27342738
imports.end()};

test/PrintAsObjC/arc-conventions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %target-build-swift -c %s -parse-as-library -force-single-frontend-invocation -o %t/swift.o -emit-objc-header-path %t/swift.h
33

4-
// RUN: %target-clang -c -Weverything -Werror -Wno-unused-macros -Wno-incomplete-module -fobjc-arc -fmodules %S/Inputs/arc-conventions.m -o %t/main.o -I %t
4+
// RUN: %clang -c %target-cc-options -isysroot %sdk -Weverything -Werror -Wno-unused-macros -Wno-incomplete-module -fobjc-arc -fmodules %S/Inputs/arc-conventions.m -o %t/main.o -I %t
55
// RUN: %target-build-swift %t/swift.o %t/main.o -o %t/main
66
// RUN: %target-codesign %t/main
77
// RUN: %target-run %t/main | %FileCheck %S/Inputs/arc-conventions.m
88

9-
// RUN: %target-clang -c -Weverything -Werror -Wno-unused-macros -Wno-incomplete-module -fno-objc-arc -fmodules %S/Inputs/arc-conventions.m -o %t/main.o -I %t
9+
// RUN: %clang -c %target-cc-options -isysroot %sdk -Weverything -Werror -Wno-unused-macros -Wno-incomplete-module -fno-objc-arc -fmodules %S/Inputs/arc-conventions.m -o %t/main.o -I %t
1010
// RUN: %target-build-swift %t/swift.o %t/main.o -o %t/main2
1111
// RUN: %target-codesign %t/main2
1212
// RUN: %target-run %t/main2 | %FileCheck %S/Inputs/arc-conventions.m

test/PrintAsObjC/empty.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
// CHECK: # define OBJC_DESIGNATED_INITIALIZER
3636

3737
// CHECK-LABEL: #if __has_feature(modules)
38+
// CHECK-NEXT: #if __has_warning
39+
// CHECK-NEXT: #pragma clang diagnostic
40+
// CHECK-NEXT: #endif
3841
// CHECK-NEXT: #endif
3942

4043

test/PrintAsObjC/imports.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/Inputs/custom-modules/ -F %S/Inputs/ -parse-as-library %t/imports.swiftmodule -typecheck -emit-objc-header-path %t/imports.h -import-objc-header %S/../Inputs/empty.h -disable-objc-attr-requires-foundation-module
66
// RUN: %FileCheck %s < %t/imports.h
77
// RUN: %FileCheck -check-prefix=NEGATIVE %s < %t/imports.h
8-
// RUN: %check-in-clang %t/imports.h -I %S/Inputs/custom-modules/ -F %S/Inputs/
8+
// RUN: %check-in-clang %t/imports.h -I %S/Inputs/custom-modules/ -F %S/Inputs/ -Watimport-in-framework-header
99

1010
// REQUIRES: objc_interop
1111

test/PrintAsObjC/mixed-framework-fwd.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
// REQUIRES: objc_interop
1919

2020
// CHECK-LABEL: #if __has_feature(modules)
21+
// CHECK-NEXT: #if __has_warning
22+
// CHECK-NEXT: #pragma clang diagnostic
23+
// CHECK-NEXT: #endif
2124
// CHECK-NEXT: @import Foundation;
2225
// CHECK-NEXT: #endif
2326

test/PrintAsObjC/mixed-framework.swift

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
1-
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -F %S/Inputs/ -module-name Mixed -import-underlying-module -parse-as-library %s -typecheck -emit-objc-header-path %t/mixed.h
3-
// RUN: %FileCheck -check-prefix=CHECK -check-prefix=FRAMEWORK %s < %t/mixed.h
4-
// RUN: %check-in-clang -F %S/Inputs/ %t/mixed.h
1+
// RUN: %empty-directory(%t.framework)
2+
// RUN: %empty-directory(%t.framework/Headers)
3+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -F %S/Inputs/ -module-name Mixed -import-underlying-module -parse-as-library %s -typecheck -emit-objc-header-path %t.framework/Headers/mixed.h
4+
// RUN: %FileCheck -check-prefix=CHECK -check-prefix=FRAMEWORK %s < %t.framework/Headers/mixed.h
5+
// RUN: %check-in-clang -Watimport-in-framework-header -F %S/Inputs/ %t.framework/Headers/mixed.h
56

6-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -module-name Mixed -import-objc-header %S/Inputs/Mixed.framework/Headers/Mixed.h %s -typecheck -emit-objc-header-path %t/mixed-header.h
7-
// RUN: %FileCheck -check-prefix=CHECK -check-prefix=HEADER %s < %t/mixed-header.h
8-
// RUN: %check-in-clang -include %S/Inputs/Mixed.framework/Headers/Mixed.h %t/mixed-header.h
7+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -module-name Mixed -import-objc-header %S/Inputs/Mixed.framework/Headers/Mixed.h %s -typecheck -emit-objc-header-path %t.framework/Headers/mixed-header.h
8+
// RUN: %FileCheck -check-prefix=CHECK -check-prefix=HEADER %s < %t.framework/Headers/mixed-header.h
9+
// RUN: %check-in-clang -Watimport-in-framework-header -include %S/Inputs/Mixed.framework/Headers/Mixed.h %t.framework/Headers/mixed-header.h
910

1011
// REQUIRES: objc_interop
1112

13+
// CHECK: #pragma clang diagnostic push
14+
1215
// CHECK-LABEL: #if __has_feature(modules)
16+
// CHECK-NEXT: #if __has_warning("-Watimport-in-framework-header")
17+
// CHECK-NEXT: #pragma clang diagnostic ignored "-Watimport-in-framework-header"
18+
// CHECK-NEXT: #endif
1319
// CHECK-NEXT: @import Foundation;
1420
// CHECK-NEXT: #endif
1521

@@ -32,3 +38,5 @@ public class Dummy: NSNumber {
3238
// HEADER: @property (nonatomic) NSInteger extraData;
3339
@objc public internal(set) var extraData: Int = 0
3440
} // CHECK: @end
41+
42+
// CHECK: #pragma clang diagnostic pop

0 commit comments

Comments
 (0)