forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a constructor thunk if required to add additional constructor
arguments. Also add more IR tests and make various other changes.
- Loading branch information
1 parent
e606727
commit b2c5a3e
Showing
7 changed files
with
182 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,42 @@ | ||
// RUN: %target-swift-frontend -I %S/Inputs -enable-cxx-interop -emit-ir %s | %FileCheck %s | ||
// Target-specific tests for C++ constructor call code generation. | ||
|
||
// RUN: %swift -module-name Swift -target x86_64-apple-macosx10.9 -dump-clang-diagnostics -I %S/Inputs -enable-cxx-interop -emit-ir %s -parse-stdlib -parse-as-library -disable-legacy-type-info | %FileCheck %s -check-prefix=ITANIUM_X64 | ||
// RUN: %swift -module-name Swift -target armv7-none-linux-androideabi -dump-clang-diagnostics -I %S/Inputs -enable-cxx-interop -emit-ir %s -parse-stdlib -parse-as-library -disable-legacy-type-info | %FileCheck %s -check-prefix=ITANIUM_ARM | ||
// RUN: %swift -module-name Swift -target x86_64-unknown-windows-msvc -dump-clang-diagnostics -I %S/Inputs -enable-cxx-interop -emit-ir %s -parse-stdlib -parse-as-library -disable-legacy-type-info | %FileCheck %s -check-prefix=MICROSOFT_X64 | ||
|
||
import CxxConstructors | ||
|
||
// Note: | ||
// - The `this` parameter should carry a `noalias` attribute, as it is | ||
// guaranteed that nothing will alias the object before it has been fully | ||
// constructed. It should also carry an `sret` attribute to indicate that this | ||
// is an out parameter for a structure being returned by the function. | ||
// - The `this` parameter should _not_ carry a `nocapture` attribute (unlike | ||
// Swift constructors that return their result indirectly) because the C++ has | ||
// explicit access to `this` and may capture it. | ||
// CHECK: call void @_ZN20ConstructorWithParamC2Ei(%struct.ConstructorWithParam* noalias sret %{{[0-9]+}}, i32 42) | ||
let _ = ConstructorWithParam(42) | ||
typealias Void = () | ||
|
||
public func createHasVirtualBase() -> HasVirtualBase { | ||
// - The `this` parameter should carry a `noalias` attribute, as it is | ||
// guaranteed that nothing will alias the object before it has been fully | ||
// constructed. It should also carry an `sret` attribute to indicate that | ||
// this is an out parameter for a structure being returned by the function. | ||
// Note that this doesn't apply on ABIs (Itanium ARM, Microsoft x64) | ||
// where we insert an (inlined) thunk; in this case, we're getting the | ||
// attributes of the constructor that was generated by Clang, which doesn't | ||
// insert these attributes. | ||
// | ||
// - The `this` parameter should _not_ carry a `nocapture` attribute (unlike | ||
// Swift constructors that return their result indirectly) because the C++ | ||
// constructor has explicit access to `this` and may capture it. | ||
// | ||
// ITANIUM_X64: define swiftcc { i8*, i32 } @"$ss20createHasVirtualBaseSo0bcD0VyF"() | ||
// ITANIUM_X64-NOT: define | ||
// ITANIUM_X64: call void @_ZN14HasVirtualBaseC1E7ArgType(%struct.HasVirtualBase* noalias sret %{{[0-9]+}}, i32 %{{[0-9]+}}) | ||
// | ||
// ITANIUM_ARM: define protected swiftcc { i8*, i32 } @"$ss20createHasVirtualBaseSo0bcD0VyF"() | ||
// 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 %struct.HasVirtualBase* @_ZN14HasVirtualBaseC1E7ArgType(%struct.HasVirtualBase* %{{[0-9]+}}, [1 x i32] %{{[0-9]+}}) | ||
// | ||
// MICROSOFT_X64: define dllexport swiftcc { i8*, i32 } @"$ss20createHasVirtualBaseSo0bcD0VyF"() | ||
// MICROSOFT_X64-NOT: define | ||
// Note `this` return type and implicit "most derived" argument. | ||
// MICROSOFT_X64: call %struct.HasVirtualBase* @"??0HasVirtualBase@@QEAA@UArgType@@@Z"(%struct.HasVirtualBase* %{{[0-9]+}}, i32 %{{[0-9]+}}, i32 1) | ||
return HasVirtualBase(ArgType()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters