Skip to content

Commit 2467b67

Browse files
authored
Merge pull request #906 from folkertdev/va-arg
implement `va_start` and `va_arg`
2 parents 8d7b443 + f9c093a commit 2467b67

5 files changed

Lines changed: 27 additions & 19 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,18 @@ dependencies = [
5656

5757
[[package]]
5858
name = "gccjit"
59-
version = "3.3.0"
59+
version = "3.4.0"
6060
source = "registry+https://github.com/rust-lang/crates.io-index"
61-
checksum = "26b73d18b642ce16378af78f89664841d7eeafa113682ff5d14573424eb0232a"
61+
checksum = "8b2c6ee720b5459292678267e9ffed8229b11e0e27fc5ecf7618634dc6272fa4"
6262
dependencies = [
6363
"gccjit_sys",
6464
]
6565

6666
[[package]]
6767
name = "gccjit_sys"
68-
version = "1.3.0"
68+
version = "1.4.0"
6969
source = "registry+https://github.com/rust-lang/crates.io-index"
70-
checksum = "ee689456c013616942d5aef9a84d613cefcc3b335340d036f3650fc1a7459e15"
70+
checksum = "0cea2ed05e093fd90bd21fa03a7d09e07f62103ce94de21859f048c9a6c18e42"
7171
dependencies = [
7272
"libc",
7373
]

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ default = ["master"]
2020
[dependencies]
2121
object = { version = "0.37.0", default-features = false, features = ["std", "read"] }
2222
tempfile = "3.20"
23-
gccjit = { version = "3.3.0", features = ["dlopen"] }
23+
gccjit = { version = "3.4.0", features = ["dlopen"] }
2424
#gccjit = { git = "https://github.com/rust-lang/gccjit.rs", branch = "error-dlopen", features = ["dlopen"] }
2525

2626
# Local copy.

src/builder.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::convert::TryFrom;
44
use std::ops::Deref;
55

66
use gccjit::{
7-
BinaryOp, Block, ComparisonOp, Context, Function, LValue, Location, RValue, ToRValue, Type,
8-
UnaryOp,
7+
BinaryOp, Block, CType, ComparisonOp, Context, Function, LValue, Location, RValue, ToRValue,
8+
Type, UnaryOp,
99
};
1010
use rustc_abi as abi;
1111
use rustc_abi::{Align, HasDataLayout, Size, TargetDataLayout, WrappingRange};
@@ -1513,8 +1513,10 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
15131513
variable.to_rvalue()
15141514
}
15151515

1516-
fn va_arg(&mut self, _list: RValue<'gcc>, _ty: Type<'gcc>) -> RValue<'gcc> {
1517-
unimplemented!();
1516+
fn va_arg(&mut self, list: RValue<'gcc>, ty: Type<'gcc>) -> RValue<'gcc> {
1517+
let va_list_type = self.context.new_c_type(CType::VaList);
1518+
let list = self.context.new_cast(self.location, list, va_list_type.make_pointer());
1519+
self.context.new_va_arg(self.location, list, ty)
15181520
}
15191521

15201522
#[cfg(feature = "master")]

src/intrinsic/mod.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod simd;
44
#[cfg(feature = "master")]
55
use std::iter;
66

7-
use gccjit::{ComparisonOp, Function, FunctionType, RValue, ToRValue, Type, UnaryOp};
7+
use gccjit::{CType, ComparisonOp, Function, FunctionType, RValue, ToRValue, Type, UnaryOp};
88
use rustc_abi::{Align, BackendRepr, HasDataLayout, WrappingRange};
99
use rustc_codegen_ssa::base::wants_msvc_seh;
1010
use rustc_codegen_ssa::common::IntPredicate;
@@ -362,7 +362,9 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
362362
unimplemented!();
363363
}
364364
sym::va_arg => {
365-
unimplemented!();
365+
let va_list = args[0].immediate();
366+
let gcc_type = self.immediate_backend_type(result.layout);
367+
self.va_arg(va_list, gcc_type)
366368
}
367369

368370
sym::volatile_load | sym::unaligned_volatile_load => {
@@ -691,8 +693,18 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
691693
self.context.new_rvalue_from_int(self.int_type, 0)
692694
}
693695

694-
fn va_start(&mut self, _va_list: RValue<'gcc>) {
695-
unimplemented!();
696+
fn va_start(&mut self, va_list: RValue<'gcc>) {
697+
let func = self.context.get_builtin_function("__builtin_va_start");
698+
699+
let va_list_type = self.context.new_c_type(CType::VaList);
700+
let va_list = self.context.new_cast(self.location, va_list, va_list_type.make_pointer());
701+
702+
// Pre-C23 requires that the last "normal" argument was passed to va_start.
703+
// Just pass 0, this appears to be handled correctly.
704+
let last_normal_arg = self.context.new_rvalue_from_int(self.int_type, 0);
705+
706+
let call = self.context.new_call(self.location, func, &[va_list, last_normal_arg]);
707+
self.block.add_eval(self.location, call);
696708
}
697709

698710
fn retag_reg(&mut self, _ptr: Self::Value, _info: &RetagInfo<Self::Value>) -> Self::Value {

tests/failing-ui-tests.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ tests/ui/linkage-attr/raw-dylib/elf/glibc-x86_64.rs
7474
tests/ui/explicit-tail-calls/recursion-etc.rs
7575
tests/ui/explicit-tail-calls/indexer.rs
7676
tests/ui/explicit-tail-calls/drop-order.rs
77-
tests/ui/c-variadic/valid.rs
78-
tests/ui/c-variadic/inherent-method.rs
79-
tests/ui/c-variadic/trait-method.rs
8077
tests/ui/explicit-tail-calls/become-cast-return.rs
8178
tests/ui/explicit-tail-calls/become-indirect-return.rs
8279
tests/ui/panics/panic-abort-backtrace-without-debuginfo.rs
@@ -97,15 +94,12 @@ tests/ui/eii/linking/same-symbol.rs
9794
tests/ui/eii/privacy1.rs
9895
tests/ui/eii/default/call_impl.rs
9996
tests/ui/eii/linking/track_caller_cross_crate.rs
100-
tests/ui/c-variadic/copy.rs
10197
tests/ui/asm/x86_64/global_asm_escape.rs
10298
tests/ui/lto/all-crates.rs
103-
tests/ui/consts/const-eval/c-variadic.rs
10499
tests/ui/eii/default/call_default_panics.rs
105100
tests/ui/explicit-tail-calls/indirect.rs
106101
tests/ui/traits/inheritance/self-in-supertype.rs
107102
tests/ui/fmt/fmt_debug/shallow.rs
108-
tests/ui/c-variadic/roundtrip.rs
109103
tests/ui/eii/eii_impl_with_contract.rs
110104
tests/ui/eii/static/cross_crate_decl.rs
111105
tests/ui/eii/static/cross_crate_def.rs

0 commit comments

Comments
 (0)