Skip to content

Commit 0f69250

Browse files
authored
Merge pull request #36198 from beccadax/a-swift-by-any-other-name-would-warn-as-bleat
Fix rebranch SwiftNameAttr warning regression
2 parents 85bbf70 + 4e0905a commit 0f69250

File tree

8 files changed

+49
-5
lines changed

8 files changed

+49
-5
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,7 @@ void ClangImporter::Implementation::addBridgeHeaderTopLevelDecls(
391391
BridgeHeaderTopLevelDecls.push_back(D);
392392
}
393393

394-
bool ClangImporter::Implementation::shouldIgnoreBridgeHeaderTopLevelDecl(
395-
clang::Decl *D) {
396-
// Ignore forward references;
394+
bool importer::isForwardDeclOfType(const clang::Decl *D) {
397395
if (auto *ID = dyn_cast<clang::ObjCInterfaceDecl>(D)) {
398396
if (!ID->isThisDeclarationADefinition())
399397
return true;
@@ -407,6 +405,11 @@ bool ClangImporter::Implementation::shouldIgnoreBridgeHeaderTopLevelDecl(
407405
return false;
408406
}
409407

408+
bool ClangImporter::Implementation::shouldIgnoreBridgeHeaderTopLevelDecl(
409+
clang::Decl *D) {
410+
return importer::isForwardDeclOfType(D);
411+
}
412+
410413
ClangImporter::ClangImporter(ASTContext &ctx,
411414
DependencyTracker *tracker,
412415
DWARFImporterDelegate *dwarfImporterDelegate)

lib/ClangImporter/ImporterImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,10 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
14621462

14631463
namespace importer {
14641464

1465+
/// Whether this is a forward declaration of a type. We ignore forward
1466+
/// declarations in certain cases, and instead process the real declarations.
1467+
bool isForwardDeclOfType(const clang::Decl *decl);
1468+
14651469
/// Whether we should suppress the import of the given Clang declaration.
14661470
bool shouldSuppressDeclImport(const clang::Decl *decl);
14671471

lib/ClangImporter/SwiftLookupTable.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2039,7 +2039,12 @@ void importer::finalizeLookupTable(
20392039
auto decl = entry.get<clang::NamedDecl *>();
20402040
auto swiftName = decl->getAttr<clang::SwiftNameAttr>();
20412041

2042-
if (swiftName) {
2042+
if (swiftName
2043+
// Clang didn't previously attach SwiftNameAttrs to forward
2044+
// declarations, but this changed and we started diagnosing spurious
2045+
// warnings on @class declarations. Suppress them.
2046+
// FIXME: Can we avoid processing these decls in the first place?
2047+
&& !importer::isForwardDeclOfType(decl)) {
20432048
clang::SourceLocation diagLoc = swiftName->getLocation();
20442049
if (!diagLoc.isValid())
20452050
diagLoc = decl->getLocation();

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
Name: ImportAsMember
2+
Classes:
3+
- Name: IAMPrivateChild
4+
SwiftName: IAMPrivateParent.Child
25
Globals:
36
- Name: IAMStruct1APINoteVar
47
SwiftName: Struct1.newApiNoteVar

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,9 @@ typedef int IAMBadInnerIntAPINotes;
7676
// CHECK: ImportAsMember.h:[[@LINE-1]]:{{[0-9]+}}: warning: imported declaration 'IAMBadInnerIntAPINotes' could not be mapped to 'IAMNonexistent.Inner2'
7777
// CHECK: ImportAsMember.h:[[@LINE-2]]:{{[0-9]+}}: note: please report this issue to the owners of 'ImportAsMember'
7878

79+
@interface IAMPrivateParent @end
80+
@interface IAMPrivateChild
81+
- (instancetype)init;
82+
@end
83+
7984
#endif // IMPORT_AS_MEMBER_H
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef IMPORT_AS_MEMBER_PRIVATE_H
2+
#define IMPORT_AS_MEMBER_PRIVATE_H
3+
4+
#include <ImportAsMember.h>
5+
6+
@class IAMPrivateChild;
7+
// CHECK-NOT: ImportAsMember_Private.h:[[@LINE-1]]:{{[0-9]+}}: warning: imported declaration 'IAMPrivateChild' could not be mapped to 'IAMPrivateParent.Child'
8+
9+
#endif // IMPORT_AS_MEMBER_PRIVATE_H

test/ClangImporter/Inputs/custom-modules/module.map

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ module ImportAsMember {
113113
}
114114
}
115115

116+
// FIXME: This probably ought to be in a module_private.map, but that causes
117+
// hundreds of clang warnings.
118+
module ImportAsMember_Private {
119+
export *
120+
121+
module A {
122+
header "ImportAsMember_Private.h"
123+
}
124+
}
125+
116126
module ObjCIRExtras {
117127
header "ObjCIRExtras.h"
118128
export *

test/ClangImporter/import-as-member.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// RUN: %empty-directory(%t.mcp)
2-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -typecheck -F %S/Inputs/frameworks -I %S/Inputs/custom-modules -module-cache-path %t.mcp %s 2>&1 | %FileCheck %S/Inputs/custom-modules/ImportAsMember.h
2+
3+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -typecheck -F %S/Inputs/frameworks -I %S/Inputs/custom-modules -module-cache-path %t.mcp %s >%t.txt 2>&1
4+
// RUN: %FileCheck %S/Inputs/custom-modules/ImportAsMember.h <%t.txt
5+
// RUN: %FileCheck %S/Inputs/custom-modules/ImportAsMember_Private.h <%t.txt
6+
37
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -typecheck -F %S/Inputs/frameworks -I %S/Inputs/custom-modules -module-cache-path %t.mcp %s -verify
48

59
import ImportAsMember
10+
import ImportAsMember_Private
611
import ImportAsMemberSubmodules
712

813
let _: IAMSOuter.Inner?

0 commit comments

Comments
 (0)