Skip to content

Commit e5ed233

Browse files
authored
Merge pull request #83540 from Xazax-hun/fix-bridging-header-reverse-interop
[cxx-interop] Fix crash when using bridging headers in reverse interop
2 parents 0247760 + 581e601 commit e5ed233

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/AST/SwiftNameTranslation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,10 @@ bool swift::cxx_translation::isObjCxxOnly(const clang::Decl *D,
271271
// requirements and the language options to check if we should actually
272272
// consider the module to have ObjC constructs.
273273
const auto &langOpts = D->getASTContext().getLangOpts();
274+
// TODO: have a reasonable guess for headers specified via
275+
// `-import-objc-header`.
276+
if (!D->hasOwningModule())
277+
return false;
274278
auto clangModule = D->getOwningModule()->getTopLevelModule();
275279
bool requiresObjC = false;
276280
for (auto req : clangModule->Requirements)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-swift-frontend -typecheck %t/use-cxx-types.swift -typecheck -module-name UseCxx -emit-clang-header-path %t/UseCxx.h -I %t -enable-experimental-cxx-interop -clang-header-expose-decls=all-public -import-objc-header %t/header.h
5+
6+
// RUN: %target-interop-build-clangxx -std=c++20 -c %t/use-swift-cxx-types.cpp -I %t -o %t/swift-cxx-execution.o -g
7+
// RUN: %target-interop-build-swift %t/use-cxx-types.swift -o %t/swift-cxx-execution -Xlinker %t/swift-cxx-execution.o -module-name UseCxx -Xfrontend -entry-point-function-name -Xfrontend swiftMain -I %t -g -import-objc-header %t/header.h
8+
9+
//--- header.h
10+
struct CxxTy {
11+
int field;
12+
};
13+
14+
//--- use-cxx-types.swift
15+
public func foo() -> CxxTy {
16+
CxxTy()
17+
}
18+
19+
//--- use-swift-cxx-types.cpp
20+
21+
#include "header.h"
22+
#include "UseCxx.h"
23+
24+
int main() {
25+
auto obj = UseCxx::foo();
26+
}

0 commit comments

Comments
 (0)