Skip to content

[6.2][cxx-interop] Fix crash when using bridging headers in reverse interop #83592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/AST/SwiftNameTranslation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ bool swift::cxx_translation::isObjCxxOnly(const clang::Decl *D,
// requirements and the language options to check if we should actually
// consider the module to have ObjC constructs.
const auto &langOpts = D->getASTContext().getLangOpts();
// TODO: have a reasonable guess for headers specified via
// `-import-objc-header`.
if (!D->hasOwningModule())
return false;
auto clangModule = D->getOwningModule()->getTopLevelModule();
bool requiresObjC = false;
for (auto req : clangModule->Requirements)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// 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

// RUN: %target-interop-build-clangxx -std=c++20 -c %t/use-swift-cxx-types.cpp -I %t -o %t/swift-cxx-execution.o -g
// 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

//--- header.h
struct CxxTy {
int field;
};

//--- use-cxx-types.swift
public func foo() -> CxxTy {
CxxTy()
}

//--- use-swift-cxx-types.cpp

#include "header.h"
#include "UseCxx.h"

int main() {
auto obj = UseCxx::foo();
}