Skip to content

[5.9][interop][SwiftToCxx] remove extraneous semicolon when emitting 'prag… #65752

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
6 changes: 3 additions & 3 deletions lib/PrintAsClang/PrintAsClang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ writeImports(raw_ostream &out, llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
bool includeUnderlying = false;
StringRef importDirective =
useCxxImport ? "#pragma clang module import" : "@import";
StringRef importDirectiveLineEnd = useCxxImport ? "\n" : ";\n";
for (auto import : sortedImports) {
if (auto *swiftModule = import.dyn_cast<ModuleDecl *>()) {
if (useCxxImport) {
Expand All @@ -464,7 +465,7 @@ writeImports(raw_ostream &out, llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
continue;
}
if (seenImports.insert(Name).second) {
out << importDirective << ' ' << Name.str() << ";\n";
out << importDirective << ' ' << Name.str() << importDirectiveLineEnd;
if (frontendOpts.EmitClangHeaderWithNonModularIncludes) {
if (const clang::Module *underlyingClangModule =
swiftModule->findUnderlyingClangModule()) {
Expand All @@ -487,8 +488,7 @@ writeImports(raw_ostream &out, llvm::SmallPtrSetImpl<ImportModuleTy> &imports,
"top-level modules should use a normal swift::ModuleDecl");
out << importDirective << ' ';
ModuleDecl::ReverseFullNameIterator(clangModule).printForward(out);
out << ";\n";

out << importDirectiveLineEnd;
if (frontendOpts.EmitClangHeaderWithNonModularIncludes) {
collectClangModuleHeaderIncludes(
clangModule, fileManager, requiredTextualIncludes, visitedModules,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@

// RUN: %check-interop-cxx-header-in-clang(%t/full-cxx-swift-cxx-bridging.h -Wno-reserved-identifier)

// FIXME: test in C++ with modules (but libc++ modularization is preventing this)
// Check that the generated header can be
// built with Clang modules enabled in C++.

// RUN: %target-interop-build-clangxx -fsyntax-only -x c++-header %t/full-cxx-swift-cxx-bridging.h -std=gnu++20 -c -fmodules -fcxx-modules -I %t

//--- header.h

Expand Down Expand Up @@ -149,7 +152,7 @@ public func takeTrivialInout(_ x: inout Trivial) {
// CHECK-NEXT: #if __has_warning("-Watimport-in-framework-header")
// CHECK-NEXT: #pragma clang diagnostic ignored "-Watimport-in-framework-header"
// CHECK-NEXT:#endif
// CHECK-NEXT: #pragma clang module import CxxTest;
// CHECK-NEXT: #pragma clang module import CxxTest
// CHECK-NEXT: #endif


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// RUN: %empty-directory(%t)
// RUN: split-file %S/bridge-cxx-struct-back-to-cxx.swift %t

// RUN: %target-swift-frontend -typecheck %t/use-cxx-types.swift -typecheck -module-name UseCxxTy -emit-clang-header-path %t/UseCxxTy.h -I %t -enable-experimental-cxx-interop -clang-header-expose-decls=all-public -disable-availability-checking
// RUN: echo "#include \"header.h\"" > %t/full-cxx-swift-cxx-bridging.h
// RUN: cat %t/UseCxxTy.h >> %t/full-cxx-swift-cxx-bridging.h

// Check that the generated header can be
// built with Clang modules enabled in ObjC++.

// REQUIRES: objc_interop

// RUN: %target-interop-build-clangxx -fsyntax-only -x objective-c++-header %t/full-cxx-swift-cxx-bridging.h -std=gnu++20 -c -fmodules -fcxx-modules -I %t