Skip to content

Commit 995d719

Browse files
Rollup merge of #52734 - nagisa:sparcfix, r=oli-obk
sparc ABI issue - structure returning from function is returned in 64bit registers (with tests) Fixes #52638 Supersedes #52730 cc @psumbera
2 parents d1e549c + cc2bd71 commit 995d719

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/librustc_target/abi/call/sparc64.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,7 @@ fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>)
5757
let size = ret.layout.size;
5858
let bits = size.bits();
5959
if bits <= 256 {
60-
let unit = if bits <= 8 {
61-
Reg::i8()
62-
} else if bits <= 16 {
63-
Reg::i16()
64-
} else if bits <= 32 {
65-
Reg::i32()
66-
} else {
67-
Reg::i64()
68-
};
69-
60+
let unit = Reg::i64();
7061
ret.cast_to(Uniform {
7162
unit,
7263
total: size

src/test/codegen/sparc-struct-abi.rs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
//
11+
// Checks that we correctly codegen extern "C" functions returning structs.
12+
// See issue #52638.
13+
14+
// compile-flags: -O --target=sparc64-unknown-linux-gnu --crate-type=rlib
15+
#![feature(no_core, lang_items)]
16+
#![no_core]
17+
18+
#[lang="sized"]
19+
trait Sized { }
20+
#[lang="freeze"]
21+
trait Freeze { }
22+
#[lang="copy"]
23+
trait Copy { }
24+
25+
#[repr(C)]
26+
pub struct Bool {
27+
b: bool,
28+
}
29+
30+
// CHECK: define i64 @structbool()
31+
// CHECK-NEXT: start:
32+
// CHECK-NEXT: ret i64 72057594037927936
33+
#[no_mangle]
34+
pub extern "C" fn structbool() -> Bool {
35+
Bool { b: true }
36+
}

0 commit comments

Comments
 (0)