Skip to content

Backport some fixes for C++ interop tests on 5.4 #37379

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
merged 6 commits into from
May 17, 2021
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
41 changes: 32 additions & 9 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,21 +520,44 @@ importer::getNormalInvocationArguments(
invocationArgStrs.push_back(
"-Werror=non-modular-include-in-framework-module");

bool EnableCXXInterop = LangOpts.EnableCXXInterop;

if (LangOpts.EnableObjCInterop) {
bool EnableCXXInterop = LangOpts.EnableCXXInterop;
invocationArgStrs.insert(
invocationArgStrs.end(),
{"-x", EnableCXXInterop ? "objective-c++" : "objective-c",
EnableCXXInterop ? "-std=gnu++17" : "-std=gnu11", "-fobjc-arc"});
invocationArgStrs.insert(invocationArgStrs.end(), {"-fobjc-arc"});
// TODO: Investigate whether 7.0 is a suitable default version.
if (!triple.isOSDarwin())
invocationArgStrs.insert(invocationArgStrs.end(),
{"-fobjc-runtime=ios-7.0"});
invocationArgStrs.insert(invocationArgStrs.end(), {
"-x", EnableCXXInterop ? "objective-c++" : "objective-c"
});
} else {
bool EnableCXXInterop = LangOpts.EnableCXXInterop;
invocationArgStrs.insert(invocationArgStrs.end(),
{"-x", EnableCXXInterop ? "c++" : "c",
EnableCXXInterop ? "-std=gnu++17" : "-std=gnu11"});
invocationArgStrs.insert(invocationArgStrs.end(), {
"-x", EnableCXXInterop ? "c++" : "c"
});
}

{
const clang::LangStandard &stdcxx =
#if defined(CLANG_DEFAULT_STD_CXX)
*clang::LangStandard::getLangStandardForName(CLANG_DEFAULT_STD_CXX);
#else
clang::LangStandard::getLangStandardForKind(
clang::LangStandard::lang_gnucxx14);
#endif

const clang::LangStandard &stdc =
#if defined(CLANG_DEFAULT_STD_C)
*clang::LangStandard::getLangStandardForName(CLANG_DEFAULT_STD_C);
#else
clang::LangStandard::getLangStandardForKind(
clang::LangStandard::lang_gnu11);
#endif

invocationArgStrs.insert(invocationArgStrs.end(), {
(Twine("-std=") + StringRef(EnableCXXInterop ? stdcxx.getName()
: stdc.getName())).str()
});
}

// Set C language options.
Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/cxx_interop.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -typecheck %s -I %S/Inputs/custom-modules -module-cache-path %t -enable-cxx-interop
// RUN: %target-swiftxx-frontend -typecheck %s -I %S/Inputs/custom-modules

import CXXInterop

Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/cxx_interop_ir.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -module-name cxx_ir -I %S/Inputs/custom-modules -module-cache-path %t -enable-cxx-interop -emit-ir -o - -primary-file %s | %FileCheck %s
// RUN: %target-swiftxx-frontend -module-name cxx_ir -I %S/Inputs/custom-modules -emit-ir -o - -primary-file %s | %FileCheck %s

import CXXInterop

Expand Down
2 changes: 1 addition & 1 deletion test/ClangImporter/enum-cxx.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -emit-ir -primary-file %s -I %S/Inputs/custom-modules -module-cache-path %t -enable-cxx-interop -o - | %FileCheck %s
// RUN: %target-swiftxx-frontend -emit-ir -primary-file %s -I %S/Inputs/custom-modules -o - | %FileCheck %s

import CXXInterop

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %s -I %S/Inputs -Xcc -std=c99 -emit-ir -o - | %FileCheck %s -check-prefix C99 --implicit-check-not notCalled
// RUN: %target-swift-frontend %s -I %S/Inputs -enable-cxx-interop -emit-ir -o - | %FileCheck %s -check-prefix CXX --implicit-check-not notCalled
// RUN: %target-swiftxx-frontend %s -I %S/Inputs -emit-ir -o - | %FileCheck %s -check-prefix CXX --implicit-check-not notCalled

import EmitCalledInlineFunction

Expand Down
12 changes: 12 additions & 0 deletions test/Interop/Cxx/class/Inputs/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,47 +1,59 @@
module AccessSpecifiers {
header "access-specifiers.h"
requires cplusplus
}

module TypeClassification {
header "type-classification.h"
requires cplusplus
}

module Constructors {
header "constructors.h"
requires cplusplus
}

module ConstructorsObjC {
header "constructors-objc.h"
requires cplusplus
}

module LoadableTypes {
header "loadable-types.h"
requires cplusplus
}

module MemberwiseInitializer {
header "memberwise-initializer.h"
requires cplusplus
}

module MemoryLayout {
header "memory-layout.h"
requires cplusplus
}

module MemberVariables {
header "member-variables.h"
requires cplusplus
}

module ProtocolConformance {
header "protocol-conformance.h"
requires cplusplus
}

module SynthesizedInitializers {
header "synthesized-initializers.h"
requires cplusplus
}

module DebugInfo {
header "debug-info.h"
requires cplusplus
}

module NestedRecords {
header "nested-records.h"
requires cplusplus
}
2 changes: 1 addition & 1 deletion test/Interop/Cxx/class/constructors-silgen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -I %S/Inputs -enable-cxx-interop -emit-silgen %s | %FileCheck %s
// RUN: %target-swiftxx-frontend -I %S/Inputs -emit-silgen %s | %FileCheck %s

import Constructors

Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/class/debug-info-irgen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -enable-cxx-interop -I %S/Inputs %s -emit-ir -g | %FileCheck %s
// RUN: %target-swiftxx-frontend -I %S/Inputs %s -emit-ir -g | %FileCheck %s

// Validate that we don't crash when trying to deserialize C++ type debug info.
// Note, however, that the actual debug info is not generated, see SR-13223.
Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/class/memory-layout-silgen.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -I %S/Inputs -enable-cxx-interop -emit-ir -o - %s | %FileCheck %s
// RUN: %target-swiftxx-frontend -I %S/Inputs -emit-ir -o - %s | %FileCheck %s

import MemoryLayout

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -enable-cxx-interop -I %S/Inputs %s -emit-ir | %FileCheck %s
// RUN: %target-swiftxx-frontend -I %S/Inputs %s -emit-ir | %FileCheck %s

// Verify that non-trival/address-only C++ classes are constructed and accessed
// correctly. Make sure that we correctly IRGen functions that construct
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -I %S/Inputs -enable-cxx-interop -emit-silgen %s | %FileCheck %s
// RUN: %target-swiftxx-frontend -I %S/Inputs -emit-silgen %s | %FileCheck %s

import TypeClassification

Expand Down
1 change: 1 addition & 0 deletions test/Interop/Cxx/enum/Inputs/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module BoolEnums {
header "bool-enums.h"
requires cplusplus
}
1 change: 1 addition & 0 deletions test/Interop/Cxx/extern-var/Inputs/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module ExternVar {
header "extern-var.h"
requires cplusplus
}
2 changes: 1 addition & 1 deletion test/Interop/Cxx/extern-var/extern-var.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-clang -c %S/Inputs/extern-var.cpp -I %S/Inputs -o %t/extern-var.o
// RUN: %target-clangxx -c %S/Inputs/extern-var.cpp -I %S/Inputs -o %t/extern-var.o
// RUN: %target-build-swift %s -I %S/Inputs -o %t/extern-var %t/extern-var.o -Xfrontend -enable-cxx-interop
// RUN: %target-codesign %t/extern-var
// RUN: %target-run %t/extern-var
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
module UserA {
header "user-a.h"
export *
requires cplusplus
}

module UserB {
header "user-b.h"
export *
requires cplusplus
}

module UserC {
header "user-c.h"
export *
requires cplusplus
}

module DeclA {
header "decl-a.h"
export *
requires cplusplus
}

module DeclB {
header "decl-b.h"
export *
requires cplusplus
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s -enable-cxx-interop
// RUN: %target-swiftxx-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s

// Swift should consider all sources for a decl and recognize that the
// decl is not hidden behind @_implementationOnly in all modules.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s -enable-cxx-interop
// RUN: %target-swiftxx-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s

// Swift should consider all sources for a decl and recognize that the
// decl is not hidden behind @_implementationOnly in all modules.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: not %target-swift-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs -enable-cxx-interop %s 2>&1 | %FileCheck %s
// RUN: not %target-swiftxx-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s 2>&1 | %FileCheck %s

// This test checks that Swift recognizes that the DeclA and DeclB provide
// different implementations for `getFortySomething()`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// RUN: %empty-directory(%t)
// RUN: mkdir %t/use_module_a %t/use_module_b
// RUN: %target-swift-frontend -enable-library-evolution -swift-version 5 -emit-module -o %t/use_module_a/UseModuleA.swiftmodule %S/Inputs/use-module-a.swift -I %S/Inputs -enable-cxx-interop
// RUN: %target-swift-frontend -enable-library-evolution -swift-version 5 -emit-module -o %t/use_module_b/UseModuleB.swiftmodule %S/Inputs/use-module-b.swift -I %S/Inputs -enable-cxx-interop
// RUN: %target-swiftxx-frontend -enable-library-evolution -swift-version 5 -emit-module -o %t/use_module_a/UseModuleA.swiftmodule %S/Inputs/use-module-a.swift -I %S/Inputs
// RUN: %target-swiftxx-frontend -enable-library-evolution -swift-version 5 -emit-module -o %t/use_module_b/UseModuleB.swiftmodule %S/Inputs/use-module-b.swift -I %S/Inputs

// RUN: %target-swift-frontend -typecheck -swift-version 5 -I %t/use_module_a -I %t/use_module_b -I %S/Inputs -enable-cxx-interop %s
// RUN: %target-swiftxx-frontend -typecheck -swift-version 5 -I %t/use_module_a -I %t/use_module_b -I %S/Inputs %s

// Swift should consider all sources for a decl and recognize that the
// decl is not hidden behind @_implementationOnly in all modules.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// RUN: %empty-directory(%t)
// RUN: mkdir %t/use_module_a %t/use_module_b
// RUN: %target-swift-frontend -enable-library-evolution -swift-version 5 -emit-module -o %t/use_module_a/UseModuleA.swiftmodule %S/Inputs/use-module-a.swift -I %S/Inputs -enable-cxx-interop
// RUN: %target-swift-frontend -enable-library-evolution -swift-version 5 -emit-module -o %t/use_module_b/UseModuleB.swiftmodule %S/Inputs/use-module-b.swift -I %S/Inputs -enable-cxx-interop
// RUN: %target-swiftxx-frontend -enable-library-evolution -swift-version 5 -emit-module -o %t/use_module_a/UseModuleA.swiftmodule %S/Inputs/use-module-a.swift -I %S/Inputs
// RUN: %target-swiftxx-frontend -enable-library-evolution -swift-version 5 -emit-module -o %t/use_module_b/UseModuleB.swiftmodule %S/Inputs/use-module-b.swift -I %S/Inputs

// RUN: %target-swift-frontend -typecheck -swift-version 5 -I %t/use_module_a -I %t/use_module_b -I %S/Inputs -enable-cxx-interop %s
// RUN: %target-swiftxx-frontend -typecheck -swift-version 5 -I %t/use_module_a -I %t/use_module_b -I %S/Inputs %s


// Swift should consider all sources for a decl and recognize that the
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs -enable-cxx-interop %s
// RUN: %target-swiftxx-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s

// Swift should consider all sources for a decl and recognize that the
// decl is not hidden behind @_implementationOnly in all modules.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs -enable-cxx-interop %s
// RUN: %target-swiftxx-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s

// Swift should consider all sources for a decl and recognize that the
// decl is not hidden behind @_implementationOnly in all modules.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s -enable-cxx-interop
// RUN: %target-swiftxx-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s

// Swift should consider all sources for a decl and recognize that the
// decl is not hidden behind @_implementationOnly in all modules.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s -enable-cxx-interop
// RUN: %target-swiftxx-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s

// Swift should consider all sources for a decl and recognize that the
// decl is not hidden behind @_implementationOnly in all modules.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: not %target-swift-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs -enable-cxx-interop %s 2>&1 | %FileCheck %s
// RUN: not %target-swiftxx-frontend -emit-module -o %t/FortyTwo.swiftmodule -I %S/Inputs %s 2>&1 | %FileCheck %s

// This test checks that forward declarations are not considered
// when determining the visibility of the decl.
Expand Down
4 changes: 4 additions & 0 deletions test/Interop/Cxx/operators/Inputs/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
module MemberInline {
header "member-inline.h"
requires cplusplus
}

module MemberOutOfLine {
header "member-out-of-line.h"
requires cplusplus
}

module NonMemberInline {
header "non-member-inline.h"
requires cplusplus
}

module NonMemberOutOfLine {
header "non-member-out-of-line.h"
requires cplusplus
}
2 changes: 1 addition & 1 deletion test/Interop/Cxx/operators/member-out-of-line.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-clang -c %S/Inputs/member-out-of-line.cpp -I %S/Inputs -o %t/member-out-of-line.o -std=c++17
// RUN: %target-clangxx -c %S/Inputs/member-out-of-line.cpp -I %S/Inputs -o %t/member-out-of-line.o
// RUN: %target-build-swift %s -I %S/Inputs -o %t/member-out-of-line %t/member-out-of-line.o -Xfrontend -enable-cxx-interop
// RUN: %target-codesign %t/member-out-of-line
// RUN: %target-run %t/member-out-of-line
Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/operators/non-member-out-of-line.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-clang -c %S/Inputs/non-member-out-of-line.cpp -I %S/Inputs -o %t/non-member-out-of-line.o -std=c++17
// RUN: %target-clangxx -c %S/Inputs/non-member-out-of-line.cpp -I %S/Inputs -o %t/non-member-out-of-line.o
// RUN: %target-build-swift %s -I %S/Inputs -o %t/non-member-out-of-line %t/non-member-out-of-line.o -Xfrontend -enable-cxx-interop
// RUN: %target-codesign %t/non-member-out-of-line
// RUN: %target-run %t/non-member-out-of-line
Expand Down
1 change: 1 addition & 0 deletions test/Interop/Cxx/reference/Inputs/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module Reference {
header "reference.h"
requires cplusplus
}
2 changes: 1 addition & 1 deletion test/Interop/Cxx/reference/reference.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-clang -c %S/Inputs/reference.cpp -I %S/Inputs -o %t/reference.o -std=c++17
// RUN: %target-clangxx -c %S/Inputs/reference.cpp -I %S/Inputs -o %t/reference.o
// RUN: %target-build-swift %s -I %S/Inputs -o %t/reference %t/reference.o -Xfrontend -enable-cxx-interop
// RUN: %target-codesign %t/reference
// RUN: %target-run %t/reference
Expand Down
5 changes: 5 additions & 0 deletions test/Interop/Cxx/static/Inputs/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
module StaticVar {
header "static-var.h"
requires cplusplus
}

module StaticLocalVar {
header "static-local-var.h"
requires cplusplus
}

module StaticMemberVar {
header "static-member-var.h"
requires cplusplus
}

module InlineStaticMemberVar {
header "inline-static-member-var.h"
requires cplusplus
}

module StaticMemberFunc {
header "static-member-func.h"
requires cplusplus
}
5 changes: 3 additions & 2 deletions test/Interop/Cxx/static/constexpr-static-member-var.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// RUN: %empty-directory(%t)
// RUN: %target-clang -c %S/Inputs/static-member-var.cpp -I %S/Inputs -o %t/static-member-var.o -std=c++17
// RUN: %target-build-swift %s -I %S/Inputs -o %t/statics %t/static-member-var.o -Xfrontend -enable-cxx-interop
// RUN: %target-clangxx -c %S/Inputs/static-member-var.cpp -I %S/Inputs -o %t/static-member-var.o
// NOTE: we must use `-O` here to ensure that the constexpr value is inlined and no undefined reference remains.
// RUN: %target-build-swift -O %s -I %S/Inputs -o %t/statics %t/static-member-var.o -Xfrontend -enable-cxx-interop
// RUN: %target-codesign %t/statics
// RUN: %target-run %t/statics
//
Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/static/inline-static-member-var.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-clang -c %S/Inputs/inline-static-member-var.cpp -I %S/Inputs -o %t/inline-static-member-var.o -std=c++17
// RUN: %target-clangxx -c %S/Inputs/inline-static-member-var.cpp -I %S/Inputs -o %t/inline-static-member-var.o
// RUN: %target-build-swift %s -I %S/Inputs -o %t/statics %t/inline-static-member-var.o -Xfrontend -enable-cxx-interop
// RUN: %target-codesign %t/statics
// RUN: %target-run %t/statics 2&>1
Expand Down
2 changes: 1 addition & 1 deletion test/Interop/Cxx/static/static-local-var.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %empty-directory(%t)
// RUN: %target-clang -c %S/Inputs/static-local-var.cpp -I %S/Inputs -o %t/static-local-var.o
// RUN: %target-clangxx -c %S/Inputs/static-local-var.cpp -I %S/Inputs -o %t/static-local-var.o
// RUN: %target-build-swift %s -I %S/Inputs -o %t/statics %t/static-local-var.o -Xfrontend -enable-cxx-interop
// RUN: %target-codesign %t/statics
// RUN: %target-run %t/statics
Expand Down
Loading