Skip to content

[android][test] Fix a handful of tests and disable one CxxToSwiftToCxx bridging test #65968

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 1 commit into from
Aug 17, 2023
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
7 changes: 4 additions & 3 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1459,9 +1459,10 @@ void ToolChain::getClangLibraryPath(const ArgList &Args,
getResourceDirPath(LibPath, Args, /*Shared=*/true);
// Remove platform name.
llvm::sys::path::remove_filename(LibPath);
llvm::sys::path::append(LibPath, "clang", "lib",
T.isOSDarwin() ? "darwin"
: getPlatformNameForTriple(T));
StringRef platformName = "darwin";
if (!T.isOSDarwin())
platformName = T.isAndroid() ? "linux" : getPlatformNameForTriple(T);
llvm::sys::path::append(LibPath, "clang", "lib", platformName);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a translation of swiftlang/swift-driver#1372, see that pull for more info.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can use llvm::Triple::getOSName instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can use llvm::Triple::getOSName instead.

Just looked into this: clang uses ToolChain::getOSLibName() instead, which has this same darwin override. We can't call that without instantiating a clang::ToolChain() though, and given all the ceremony you added to do so elsewhere, that would end up with more lines.

@compnerd, I don't think that clang method is worth invoking, let me know if you disagree.

}

/// Get the runtime library link path, which is platform-specific and found
Expand Down
2 changes: 0 additions & 2 deletions test/Driver/link-time-opt.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// REQUIRES: lld_lto

// RUN: %swiftc_driver -driver-print-jobs %S/../Inputs/empty.swift -lto=llvm-thin -target x86_64-unknown-linux-gnu | %FileCheck %s --check-prefix=CHECK-SIMPLE-THIN --check-prefix=CHECK-SIMPLE-THIN-linux-gnu
// RUN: %swiftc_driver -driver-print-jobs %S/../Inputs/empty.swift -lto=llvm-thin -target x86_64-unknown-windows-msvc | %FileCheck %s --check-prefix=CHECK-SIMPLE-THIN --check-prefix=CHECK-SIMPLE-THIN-windows-msvc

Expand Down
2 changes: 0 additions & 2 deletions test/Driver/lto-output-mode-clash.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// REQUIRES: lld_lto

// RUN: %swiftc_driver -driver-print-jobs %S/../Inputs/empty.swift -lto=llvm-full -static -emit-library -target x86_64-apple-macosx10.9 | %FileCheck %s
// RUN: %swiftc_driver -driver-print-jobs %S/../Inputs/empty.swift -lto=llvm-full -emit-library -target x86_64-apple-macosx10.9 | %FileCheck %s
// RUN: %swiftc_driver -driver-print-jobs %S/../Inputs/empty.swift -lto=llvm-full -c -target x86_64-apple-macosx10.9 | %FileCheck %s
Expand Down
1 change: 0 additions & 1 deletion test/Driver/static-stdlib-linux-lld.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Statically link a "hello world" program
// REQUIRES: OS=linux-gnu
// REQUIRES: static_stdlib
// REQUIRES: lld_lto
print("hello world!")
// RUN: %empty-directory(%t)
// RUN: %target-swiftc_driver -static-stdlib -use-ld=lld %import-static-libdispatch -o %t/static-stdlib-lld %s
Expand Down
2 changes: 2 additions & 0 deletions test/IRGen/section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
// ASM-NOT: .section
// ASM: $s7section3fooyyF:
// ASM-linux-gnu: .section{{.*}}__TEXT,__mysection
// ASM-linux-android: .section{{.*}}__TEXT,__mysection
// ASM-linux-androideabi: .section{{.*}}__TEXT,__mysection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now tested this and made sure it works.

// ASM-NOT: .section
// ASM: $s7section2g0Sivp:
// ASM-NOT: .section
Expand Down
10 changes: 3 additions & 7 deletions test/Interop/Cxx/class/constructors-copy-irgen-android.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@ import Constructors
import TypeClassification

// ITANIUM_ARM-LABEL: define protected swiftcc void @"$s7MySwift35copyWithUserProvidedCopyConstructorySo03Has{{cdeF0V_ACtACF|efgH0V_ADtADF}}"
// ITANIUM_ARM-SAME: (%TSo30HasUserProvidedCopyConstructorV* {{.*}}[[ARG0:%.*]], %TSo30HasUserProvidedCopyConstructorV* {{.*}}[[ARG1:%.*]], %TSo30HasUserProvidedCopyConstructorV* {{.*}}[[ARG2:%.*]])
// ITANIUM_ARM: [[ARG0_AS_STRUCT:%.*]] = bitcast %TSo30HasUserProvidedCopyConstructorV* [[ARG0]] to %struct.HasUserProvidedCopyConstructor*
// ITANIUM_ARM: [[ARG2_AS_STRUCT:%.*]] = bitcast %TSo30HasUserProvidedCopyConstructorV* [[ARG2]] to %struct.HasUserProvidedCopyConstructor*
// ITANIUM_ARM: call void @_ZN30HasUserProvidedCopyConstructorC2ERKS_(%struct.HasUserProvidedCopyConstructor* [[ARG0_AS_STRUCT]], %struct.HasUserProvidedCopyConstructor* [[ARG2_AS_STRUCT]])
// ITANIUM_ARM: [[ARG1_AS_STRUCT:%.*]] = bitcast %TSo30HasUserProvidedCopyConstructorV* [[ARG1]] to %struct.HasUserProvidedCopyConstructor*
// ITANIUM_ARM: [[ARG2_AS_STRUCT:%.*]] = bitcast %TSo30HasUserProvidedCopyConstructorV* [[ARG2]] to %struct.HasUserProvidedCopyConstructor*
// ITANIUM_ARM: call void @_ZN30HasUserProvidedCopyConstructorC2ERKS_(%struct.HasUserProvidedCopyConstructor* [[ARG1_AS_STRUCT]], %struct.HasUserProvidedCopyConstructor* [[ARG2_AS_STRUCT]])
// ITANIUM_ARM-SAME: (ptr {{.*}}[[ARG0:%.*]], ptr {{.*}}[[ARG1:%.*]], ptr {{.*}}[[ARG2:%.*]])
// ITANIUM_ARM: call void @_ZN30HasUserProvidedCopyConstructorC2ERKS_(ptr [[ARG0]], ptr [[ARG2]])
// ITANIUM_ARM: call void @_ZN30HasUserProvidedCopyConstructorC2ERKS_(ptr [[ARG1]], ptr [[ARG2]])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These constructor tests started failing recently and had to be updated for Android similarly to #67092.

// ITANIUM_ARM: ret void

public func copyWithUserProvidedCopyConstructor(_ x: HasUserProvidedCopyConstructor)
Expand Down
20 changes: 8 additions & 12 deletions test/Interop/Cxx/class/constructors-irgen-android.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import Constructors
import TypeClassification

public func createHasVirtualBase() -> HasVirtualBase {
// ITANIUM_ARM: define protected swiftcc void @"$s7MySwift20createHasVirtualBaseSo0deF0VyF"(%TSo14HasVirtualBaseV* noalias nocapture sret({{.*}}) %0)
// ITANIUM_ARM: define protected swiftcc void @"$s7MySwift20createHasVirtualBaseSo0deF0VyF"(ptr noalias nocapture sret({{.*}}) %0)
// To verify that the thunk is inlined, make sure there's no intervening
// `define`, i.e. the call to the C++ constructor happens in
// createHasVirtualBase(), not some later function.
// ITANIUM_ARM-NOT: define
// Note `this` return type.
// ITANIUM_ARM: call void @_ZN14HasVirtualBaseC1E7ArgType(%struct.HasVirtualBase* %{{[0-9]+}}, i64 %{{[0-9]+}})
// ITANIUM_ARM: call void @_ZN14HasVirtualBaseC1E7ArgType(ptr %{{[0-9]+}}, i64 %{{[0-9]+}})
return HasVirtualBase(ArgType())
}

public func createImplicitDefaultConstructor() -> ImplicitDefaultConstructor {
// ITANIUM_ARM: define protected swiftcc i32 @"$s7MySwift32createImplicitDefaultConstructorSo0deF0VyF"()
// ITANIUM_ARM-NOT: define
// Note `this` return type.
// ITANIUM_ARM: call void @_ZN26ImplicitDefaultConstructorC2Ev(%struct.ImplicitDefaultConstructor* %{{[0-9]+}})
// ITANIUM_ARM: call void @_ZN26ImplicitDefaultConstructorC2Ev(ptr %{{[0-9]+}})
return ImplicitDefaultConstructor()
}

Expand All @@ -32,11 +32,8 @@ public func createStructWithSubobjectCopyConstructorAndValue() {
// ITANIUM_ARM: [[MEMBER:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV
// ITANIUM_ARM: [[OBJ:%.*]] = alloca %TSo42StructWithSubobjectCopyConstructorAndValueV
// ITANIUM_ARM: [[TMP:%.*]] = alloca %TSo33StructWithCopyConstructorAndValueV
// ITANIUM_ARM: [[MEMBER_AS_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]] to %struct.StructWithCopyConstructorAndValue*
// ITANIUM_ARM: call void @_ZN33StructWithCopyConstructorAndValueC2Ev(%struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT]])
// ITANIUM_ARM: [[TMP_STRUCT:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[TMP]] to %struct.StructWithCopyConstructorAndValue*
// ITANIUM_ARM: [[MEMBER_AS_STRUCT_2:%.*]] = bitcast %TSo33StructWithCopyConstructorAndValueV* [[MEMBER]] to %struct.StructWithCopyConstructorAndValue*
// ITANIUM_ARM: call void @_ZN33StructWithCopyConstructorAndValueC2ERKS_(%struct.StructWithCopyConstructorAndValue* [[TMP_STRUCT]], %struct.StructWithCopyConstructorAndValue* [[MEMBER_AS_STRUCT_2]])
// ITANIUM_ARM: call void @_ZN33StructWithCopyConstructorAndValueC2Ev(ptr [[MEMBER]])
// ITANIUM_ARM: call void @_ZN33StructWithCopyConstructorAndValueC2ERKS_(ptr [[TMP]], ptr [[MEMBER]])
// ITANIUM_ARM: ret void
let member = StructWithCopyConstructorAndValue()
let obj = StructWithSubobjectCopyConstructorAndValue(member: member)
Expand All @@ -45,11 +42,10 @@ public func createStructWithSubobjectCopyConstructorAndValue() {
public func createTemplatedConstructor() {
// ITANIUM_ARM-LABEL: define protected swiftcc void @"$s7MySwift26createTemplatedConstructoryyF"()
// ITANIUM_ARM: [[OBJ:%.*]] = alloca %TSo20TemplatedConstructorV
// ITANIUM_ARM: [[IVAL:%.*]] = load i64, i64*
// ITANIUM_ARM: [[OBJ_AS_STRUCT:%.*]] = bitcast %TSo20TemplatedConstructorV* [[OBJ]] to %struct.TemplatedConstructor*
// ITANIUM_ARM: call void @_ZN20TemplatedConstructorC2I7ArgTypeEET_(%struct.TemplatedConstructor* [[OBJ_AS_STRUCT]], i64 [[IVAL]])
// ITANIUM_ARM: [[IVAL:%.*]] = load i64, ptr
// ITANIUM_ARM: call void @_ZN20TemplatedConstructorC2I7ArgTypeEET_(ptr [[OBJ]], i64 [[IVAL]])
// ITANIUM_ARM: ret void

// ITANIUM_ARM-LABEL: define {{.*}}void @_ZN20TemplatedConstructorC2I7ArgTypeEET_(%struct.TemplatedConstructor* {{.*}}, i64 {{.*}})
// ITANIUM_ARM-LABEL: define {{.*}}void @_ZN20TemplatedConstructorC2I7ArgTypeEET_(ptr {{.*}}, i64 {{.*}})
let templated = TemplatedConstructor(ArgType())
}
2 changes: 1 addition & 1 deletion test/Interop/Cxx/class/copy-move-assignment-irgen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public func copyAssign() {
// CHECK: call {{void|ptr}} @{{_ZN31NonTrivialCopyAndCopyMoveAssignC1Ev|_ZN31NonTrivialCopyAndCopyMoveAssignC2Ev|"\?\?0NonTrivialCopyAndCopyMoveAssign@@QEAA@XZ"}}(ptr %[[COPY_INSTANCE:.*]])
// CHECK: call {{void|ptr}} @{{_ZN31NonTrivialCopyAndCopyMoveAssignC1Ev|_ZN31NonTrivialCopyAndCopyMoveAssignC2Ev|"\?\?0NonTrivialCopyAndCopyMoveAssign@@QEAA@XZ"}}(ptr %[[COPY_INSTANCE2:.*]])
// CHECK: call {{void|ptr}} @{{_ZN31NonTrivialCopyAndCopyMoveAssignD1Ev|_ZN31NonTrivialCopyAndCopyMoveAssignD2Ev|"\?\?1NonTrivialCopyAndCopyMoveAssign@@QEAA@XZ"}}(ptr %[[COPY_INSTANCE]])
// CHECK: call {{void|ptr}} @{{_ZN31NonTrivialCopyAndCopyMoveAssignC1EOS_|_ZN31NonTrivialCopyAndCopyMoveAssignC2EOS_|_ZN31NonTrivialCopyAndCopyMoveAssignC1ERKS_Tm|_ZN31NonTrivialCopyAndCopyMoveAssignC2ERKS_Tm|"\?\?0NonTrivialCopyAndCopyMoveAssign@@QEAA@AEBU0@@Z"}}(
// CHECK: call {{void|(noundef )?ptr}} @{{_ZN31NonTrivialCopyAndCopyMoveAssignC1EOS_|_ZN31NonTrivialCopyAndCopyMoveAssignC2EOS_|_ZN31NonTrivialCopyAndCopyMoveAssignC1ERKS_Tm|_ZN31NonTrivialCopyAndCopyMoveAssignC2ERKS_Tm|"\?\?0NonTrivialCopyAndCopyMoveAssign@@QEAA@AEBU0@@Z"}}(
// CHECK-SAME: %[[COPY_INSTANCE]],
// CHECK-SAME: ptr
// CHECK-SAME: %[[COPY_INSTANCE2]])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public:
std::vector<SimplePOD * _Nullable> getMutPODPtrItems() const;
};

// CHECK: func getPODItems() -> std{{\.__1\.|\.}}vector<SimplePOD, allocator<SimplePOD>>
// CHECK: func getFRTItems() -> std{{\.__1\.|\.}}vector<FRTType, allocator<FRTType>>
// CHECK: func getPODPtrItems() -> std{{\.__1\.|\.}}vector<UnsafePointer<SimplePOD>, allocator<UnsafePointer<SimplePOD>>>
// CHECK: func getMutPODPtrItems() -> std{{\.__1\.|\.}}vector<UnsafeMutablePointer<SimplePOD>, allocator<UnsafeMutablePointer<SimplePOD>>>
// CHECK: func getPODItems() -> std{{\.__(ndk)?1\.|\.}}vector<SimplePOD, allocator<SimplePOD>>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise fails on Android with this error:

/home/ubuntu/jenkins/workspace/oss-swift-RA-linux-ubuntu-16.04-android-arm64/swift/test/Interop/Cxx/stdlib/use-cxxstdlib-types-in-module-interface.swift:43:11: error: CHECK: expected string not found in input
// CHECK: func getPODItems() -> std{{\.__1\.|\.}}vector<SimplePOD, allocator<SimplePOD>>
          ^
<stdin>:1:1: note: scanning from here

^
<stdin>:16:2: note: possible intended match here
 func getPODItems() -> std.__ndk1.vector<SimplePOD, allocator<SimplePOD>>
 ^

// CHECK: func getFRTItems() -> std{{\.__(ndk)?1\.|\.}}vector<FRTType, allocator<FRTType>>
// CHECK: func getPODPtrItems() -> std{{\.__(ndk)?1\.|\.}}vector<UnsafePointer<SimplePOD>, allocator<UnsafePointer<SimplePOD>>>
// CHECK: func getMutPODPtrItems() -> std{{\.__(ndk)?1\.|\.}}vector<UnsafeMutablePointer<SimplePOD>, allocator<UnsafeMutablePointer<SimplePOD>>>
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ import ClassTemplateNonTypeParameter
let p = MagicIntPair()
let t = MagicIntTriple()

// CHECK: @"${{s4main1pSo0034MagicArrayInt32_UInt_2_zoAFhhiEngcVvp|s4main1pSo0036MagicArrayInt32_UInt64_2_JsAEiFiuomcVvp}}"
// CHECK: @"${{s4main1tSo0034MagicArrayInt32_UInt_3_zoAFhhiEngcVvp|s4main1tSo0036MagicArrayInt32_UInt64_3_JsAEiFiuomcVvp}}"
// CHECK: @"${{s4main1pSo0034MagicArrayInt32_UInt_2_zoAFhhiEngcVvp|s4main1pSo0036MagicArrayInt32_UInt(64|32)_2_JsAEiFiuomcVvp}}"
// CHECK: @"${{s4main1tSo0034MagicArrayInt32_UInt_3_zoAFhhiEngcVvp|s4main1tSo0036MagicArrayInt32_UInt(64|32)_3_JsAEiFiuomcVvp}}"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new test fails on 32-bit arches like Android armv7, but these two changes got it passing there too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@egorzhdan, you added this new test recently, please review this change to get it working on 32-bit platforms.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

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

// XFAIL: OS=linux-android, OS=linux-androideabi

//--- header.h

struct Trivial {
Expand Down
2 changes: 1 addition & 1 deletion test/Interpreter/llvm_link_time_opt.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// UNSUPPORTED: OS=windows-msvc
// static library is not well supported yet on Windows

// REQUIRES: lld_lto
// XFAIL: OS=linux-android, OS=linux-androideabi
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This started failing recently on the community Android CI, as the LLVM 14 toolchain in the Android LTS NDK 25c doesn't support opaque pointers much:

error: Opaque pointers are only supported in -opaque-pointers mode (Producer: 'LLVM13.0.0git' Reader: 'LLVM 14.0.6git')

That flag wasn't added till clang 15, llvm/llvm-project@d69e9f9d89783, so this won't work till the next NDK, which will include clang 17. It currently works natively in the Termux app, where I use LLVM 16.


// For LTO, the linker dlopen()'s the libLTO library, which is a scenario that
// ASan cannot work in ("Interceptors are not working, AddressSanitizer is
Expand Down
2 changes: 1 addition & 1 deletion test/Reflection/conformance_descriptors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// CHECK: CONFORMANCES:
// CHECK: =============
// CHECK-DAG: 16ConformanceCheck10SomeStructV6${{[0-9a-f]*}}yXZ0c6NestedD06${{[0-9a-f]*}}LLV (ConformanceCheck.SomeStruct.(unknown context at ${{[0-9a-f]*}}).(SomeNestedStruct in ${{[0-9a-f]*}})) : ConformanceCheck.MyProto
// CHECK-DAG: 16ConformanceCheck10SomeStructV{{[56]}}${{[0-9a-f]*}}yXZ0c6NestedD0{{[56]}}${{[0-9a-f]*}}LLV (ConformanceCheck.SomeStruct.(unknown context at ${{[0-9a-f]*}}).(SomeNestedStruct in ${{[0-9a-f]*}})) : ConformanceCheck.MyProto
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why this started failing all of a sudden, as the length of this symbol on Android was 6 and it passed before, but lately it is 5, so this change gets it passing again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@artemcm, this test is disabled on all other arm64 platforms, is this the reason? Should I just disable it for Android AArch64 too?

// CHECK-DAG: 16ConformanceCheck3fooV3barV3bazV3quxV4quuxV5corgeV6graultV6garplyV5waldoV4fredV5plughV5xyzzyV4thudV18SomeConformingTypeV (ConformanceCheck.foo.bar.baz.qux.quux.corge.grault.garply.waldo.fred.plugh.xyzzy.thud.SomeConformingType) : ConformanceCheck.MyProto
// CHECK-DAG: 16ConformanceCheck7StructAV (ConformanceCheck.StructA) : ConformanceCheck.MyProto, Swift.Hashable, Swift.Equatable
// CHECK-DAG: 16ConformanceCheck2E4O (ConformanceCheck.E4) : ConformanceCheck.P1, ConformanceCheck.P2, ConformanceCheck.P3
Expand Down
2 changes: 0 additions & 2 deletions test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,6 @@ swift_backtrace = os.environ.get('SWIFT_BACKTRACE')
if swift_backtrace:
config.environment['SWIFT_BACKTRACE'] = swift_backtrace

config.available_features.add('lld_lto')
Copy link
Member Author

@finagolfin finagolfin Jul 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was used to avoid issues on Android by @kateinoigakukun in #32430, but I enabled it for Android too when the NDK switched to lld, #39921. I left this feature in then because I didn't know if anyone else needed it, but looking into that commit history for the first time now, it should be fine to remove this feature, since it's always enabled now.


threading = lit_config.params.get('threading', 'none')
config.available_features.add('threading_{}'.format(threading))
if threading != "none":
Expand Down