-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #122781 - nikic:ppc-abi-fix, r=cuviper
Fix argument ABI for overaligned structs on ppc64le When passing a 16 (or higher) aligned struct by value on ppc64le, it needs to be passed as an array of `i128` rather than an array of `i64`. This will force the use of an even starting doubleword. For the case of a 16 byte struct with alignment 16 it is important that `[1 x i128]` is used instead of `i128` -- apparently, the latter will get treated similarly to `[2 x i64]`, not exhibiting the correct ABI. Add a `force_array` flag to `Uniform` to support this. The relevant clang code can be found here: https://github.com/llvm/llvm-project/blob/fe2119a7b08b6e468b2a67768904ea85b1bf0a45/clang/lib/CodeGen/Targets/PPC.cpp#L878-L884 https://github.com/llvm/llvm-project/blob/fe2119a7b08b6e468b2a67768904ea85b1bf0a45/clang/lib/CodeGen/Targets/PPC.cpp#L780-L784 I think the corresponding psABI wording is this: > Fixed size aggregates and unions passed by value are mapped to as > many doublewords of the parameter save area as the value uses in > memory. Aggregrates and unions are aligned according to their > alignment requirements. This may result in doublewords being > skipped for alignment. In particular the last sentence. Though I didn't find any wording for Clang's behavior of clamping the alignment to 16. Fixes #122767. r? `@cuviper`
- Loading branch information
Showing
15 changed files
with
156 additions
and
41 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
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
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Test that structs aligned to 128 bits are passed with the correct ABI on powerpc64le. | ||
// This is similar to aarch64-struct-align-128.rs, but for ppc. | ||
|
||
//@ compile-flags: --target powerpc64le-unknown-linux-gnu | ||
//@ needs-llvm-components: powerpc | ||
|
||
#![feature(no_core, lang_items)] | ||
#![crate_type = "lib"] | ||
#![no_core] | ||
|
||
#[lang="sized"] | ||
trait Sized { } | ||
#[lang="freeze"] | ||
trait Freeze { } | ||
#[lang="copy"] | ||
trait Copy { } | ||
|
||
#[repr(C)] | ||
pub struct Align8 { | ||
pub a: u64, | ||
pub b: u64, | ||
} | ||
|
||
#[repr(transparent)] | ||
pub struct Transparent8 { | ||
a: Align8 | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Wrapped8 { | ||
a: Align8, | ||
} | ||
|
||
extern "C" { | ||
// CHECK: declare void @test_8([2 x i64], [2 x i64], [2 x i64]) | ||
fn test_8(a: Align8, b: Transparent8, c: Wrapped8); | ||
} | ||
|
||
#[repr(C)] | ||
#[repr(align(16))] | ||
pub struct Align16 { | ||
pub a: u64, | ||
pub b: u64, | ||
} | ||
|
||
#[repr(transparent)] | ||
pub struct Transparent16 { | ||
a: Align16 | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Wrapped16 { | ||
pub a: Align16, | ||
} | ||
|
||
extern "C" { | ||
// It's important that this produces [1 x i128] rather than just i128! | ||
// CHECK: declare void @test_16([1 x i128], [1 x i128], [1 x i128]) | ||
fn test_16(a: Align16, b: Transparent16, c: Wrapped16); | ||
} | ||
|
||
#[repr(C)] | ||
#[repr(align(32))] | ||
pub struct Align32 { | ||
pub a: u64, | ||
pub b: u64, | ||
pub c: u64, | ||
} | ||
|
||
#[repr(transparent)] | ||
pub struct Transparent32 { | ||
a: Align32 | ||
} | ||
|
||
#[repr(C)] | ||
pub struct Wrapped32 { | ||
pub a: Align32, | ||
} | ||
|
||
extern "C" { | ||
// CHECK: declare void @test_32([2 x i128], [2 x i128], [2 x i128]) | ||
fn test_32(a: Align32, b: Transparent32, c: Wrapped32); | ||
} | ||
|
||
pub unsafe fn main( | ||
a1: Align8, a2: Transparent8, a3: Wrapped8, | ||
b1: Align16, b2: Transparent16, b3: Wrapped16, | ||
c1: Align32, c2: Transparent32, c3: Wrapped32, | ||
) { | ||
test_8(a1, a2, a3); | ||
test_16(b1, b2, b3); | ||
test_32(c1, c2, c3); | ||
} |