Skip to content

Commit 0e8e60c

Browse files
committed
Merge branch 'master' into sync_from_rust_2023_11_17
2 parents a6493c1 + c6bc7ec commit 0e8e60c

File tree

7 files changed

+65
-19
lines changed

7 files changed

+65
-19
lines changed

Cargo.lock

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build_sysroot/build_sysroot.sh

+4
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ fi
2828
# Copy files to sysroot
2929
mkdir -p sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
3030
cp -r target/$TARGET_TRIPLE/$sysroot_channel/deps/* sysroot/lib/rustlib/$TARGET_TRIPLE/lib/
31+
# Copy the source files to the sysroot (Rust for Linux needs this).
32+
source_dir=sysroot/lib/rustlib/src/rust
33+
mkdir -p $source_dir
34+
cp -r sysroot_src/library/ $source_dir

build_system/src/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ fn build_sysroot(
194194
copier,
195195
)?;
196196

197+
// Copy the source files to the sysroot (Rust for Linux needs this).
198+
let sysroot_src_path = "sysroot/lib/rustlib/src/rust";
199+
fs::create_dir_all(&sysroot_src_path)
200+
.map_err(|error| format!("Failed to create directory `{}`: {:?}", sysroot_src_path, error))?;
201+
run_command(&[&"cp", &"-r", &"sysroot_src/library/", &sysroot_src_path], None)?;
202+
197203
Ok(())
198204
}
199205

failing-ui-tests12.txt

+1
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ tests/ui/target-feature/missing-plusminus.rs
3838
tests/ui/sse2.rs
3939
tests/ui/codegen/issue-79865-llvm-miscompile.rs
4040
tests/ui/intrinsics/intrinsics-integer.rs
41+
tests/ui/std-backtrace.rs

src/base.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::env;
33
use std::time::Instant;
44

55
use gccjit::{
6-
Context,
76
FunctionType,
87
GlobalKind,
98
};
@@ -18,8 +17,9 @@ use rustc_codegen_ssa::mono_item::MonoItemExt;
1817
use rustc_codegen_ssa::traits::DebugInfoMethods;
1918
use rustc_session::config::DebugInfo;
2019
use rustc_span::Symbol;
20+
use rustc_target::spec::PanicStrategy;
2121

22-
use crate::{LockedTargetInfo, gcc_util};
22+
use crate::{LockedTargetInfo, gcc_util, new_context};
2323
use crate::GccContext;
2424
use crate::builder::Builder;
2525
use crate::context::CodegenCx;
@@ -88,20 +88,18 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, target_info: Lock
8888
fn module_codegen(tcx: TyCtxt<'_>, (cgu_name, target_info): (Symbol, LockedTargetInfo)) -> ModuleCodegen<GccContext> {
8989
let cgu = tcx.codegen_unit(cgu_name);
9090
// Instantiate monomorphizations without filling out definitions yet...
91-
let context = Context::default();
91+
let context = new_context(&tcx);
9292

93-
context.add_command_line_option("-fexceptions");
94-
context.add_driver_option("-fexceptions");
93+
if tcx.sess.panic_strategy() == PanicStrategy::Unwind {
94+
context.add_command_line_option("-fexceptions");
95+
context.add_driver_option("-fexceptions");
96+
}
9597

9698
let disabled_features: HashSet<_> = tcx.sess.opts.cg.target_feature.split(',')
9799
.filter(|feature| feature.starts_with('-'))
98100
.map(|string| &string[1..])
99101
.collect();
100102

101-
if tcx.sess.target.arch == "x86" || tcx.sess.target.arch == "x86_64" {
102-
context.add_command_line_option("-masm=intel");
103-
}
104-
105103
if !disabled_features.contains("avx") && tcx.sess.target.arch == "x86_64" {
106104
// NOTE: we always enable AVX because the equivalent of llvm.x86.sse2.cmp.pd in GCC for
107105
// SSE2 is multiple builtins, so we use the AVX __builtin_ia32_cmppd instead.

src/int.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
7676
a >> b
7777
}
7878
}
79+
else if a_type.is_vector() && a_type.is_vector() {
80+
a >> b
81+
}
7982
else if a_native && !b_native {
8083
self.gcc_lshr(a, self.gcc_int_cast(b, a_type))
8184
}
@@ -144,7 +147,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
144147
fn additive_operation(&self, operation: BinaryOp, a: RValue<'gcc>, mut b: RValue<'gcc>) -> RValue<'gcc> {
145148
let a_type = a.get_type();
146149
let b_type = b.get_type();
147-
if self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type) {
150+
if (self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type)) || (a_type.is_vector() && b_type.is_vector()) {
148151
if a_type != b_type {
149152
if a_type.is_vector() {
150153
// Vector types need to be bitcast.
@@ -158,6 +161,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
158161
self.context.new_binary_op(None, operation, a_type, a, b)
159162
}
160163
else {
164+
debug_assert!(a_type.dyncast_array().is_some());
165+
debug_assert!(b_type.dyncast_array().is_some());
161166
let signed = a_type.is_compatible_with(self.i128_type);
162167
let func_name =
163168
match (operation, signed) {
@@ -189,10 +194,12 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
189194
fn multiplicative_operation(&self, operation: BinaryOp, operation_name: &str, signed: bool, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
190195
let a_type = a.get_type();
191196
let b_type = b.get_type();
192-
if self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type) {
197+
if (self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type)) || (a_type.is_vector() && b_type.is_vector()) {
193198
self.context.new_binary_op(None, operation, a_type, a, b)
194199
}
195200
else {
201+
debug_assert!(a_type.dyncast_array().is_some());
202+
debug_assert!(b_type.dyncast_array().is_some());
196203
let sign =
197204
if signed {
198205
""
@@ -337,6 +344,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
337344
pub fn operation_with_overflow(&self, func_name: &str, lhs: RValue<'gcc>, rhs: RValue<'gcc>) -> (RValue<'gcc>, RValue<'gcc>) {
338345
let a_type = lhs.get_type();
339346
let b_type = rhs.get_type();
347+
debug_assert!(a_type.dyncast_array().is_some());
348+
debug_assert!(b_type.dyncast_array().is_some());
340349
let param_a = self.context.new_parameter(None, a_type, "a");
341350
let param_b = self.context.new_parameter(None, b_type, "b");
342351
let result_field = self.context.new_field(None, a_type, "result");
@@ -496,7 +505,11 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
496505
pub fn gcc_xor(&self, a: RValue<'gcc>, b: RValue<'gcc>) -> RValue<'gcc> {
497506
let a_type = a.get_type();
498507
let b_type = b.get_type();
499-
if self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type) {
508+
if a_type.is_vector() && b_type.is_vector() {
509+
let b = self.bitcast_if_needed(b, a_type);
510+
a ^ b
511+
}
512+
else if self.is_native_int_type_or_bool(a_type) && self.is_native_int_type_or_bool(b_type) {
500513
a ^ b
501514
}
502515
else {
@@ -527,6 +540,9 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
527540
a << b
528541
}
529542
}
543+
else if a_type.is_vector() && a_type.is_vector() {
544+
a << b
545+
}
530546
else if a_native && !b_native {
531547
self.gcc_shl(a, self.gcc_int_cast(b, a_type))
532548
}
@@ -690,6 +706,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
690706
let a_native = self.is_native_int_type_or_bool(a_type);
691707
let b_native = self.is_native_int_type_or_bool(b_type);
692708
if a_type.is_vector() && b_type.is_vector() {
709+
let b = self.bitcast_if_needed(b, a_type);
693710
self.context.new_binary_op(None, operation, a_type, a, b)
694711
}
695712
else if a_native && b_native {
@@ -748,6 +765,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
748765
return self.context.new_cast(None, value, dest_typ);
749766
}
750767

768+
debug_assert!(value_type.dyncast_array().is_some());
751769
let name_suffix =
752770
match self.type_kind(dest_typ) {
753771
TypeKind::Float => "tisf",
@@ -781,6 +799,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
781799
return self.context.new_cast(None, value, dest_typ);
782800
}
783801

802+
debug_assert!(value_type.dyncast_array().is_some());
784803
let name_suffix =
785804
match self.type_kind(value_type) {
786805
TypeKind::Float => "sfti",

src/lib.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ extern crate rustc_errors;
3939
extern crate rustc_fluent_macro;
4040
extern crate rustc_fs_util;
4141
extern crate rustc_hir;
42+
#[cfg(feature="master")]
43+
extern crate rustc_interface;
4244
extern crate rustc_macros;
4345
extern crate rustc_metadata;
4446
extern crate rustc_middle;
@@ -86,7 +88,7 @@ use std::sync::atomic::Ordering;
8688

8789
use gccjit::{Context, OptimizationLevel};
8890
#[cfg(feature="master")]
89-
use gccjit::TargetInfo;
91+
use gccjit::{TargetInfo, Version};
9092
#[cfg(not(feature="master"))]
9193
use gccjit::CType;
9294
use errors::LTONotSupported;
@@ -244,17 +246,33 @@ impl CodegenBackend for GccCodegenBackend {
244246
}
245247
}
246248

249+
fn new_context<'gcc, 'tcx>(tcx: &TyCtxt<'tcx>) -> Context<'gcc> {
250+
let context = Context::default();
251+
if tcx.sess.target.arch == "x86" || tcx.sess.target.arch == "x86_64" {
252+
context.add_command_line_option("-masm=intel");
253+
}
254+
#[cfg(feature="master")]
255+
{
256+
let version = Version::get();
257+
let version = format!("{}.{}.{}", version.major, version.minor, version.patch);
258+
context.set_output_ident(&format!("rustc version {} with libgccjit {}",
259+
rustc_interface::util::rustc_version_str().unwrap_or("unknown version"),
260+
version,
261+
));
262+
}
263+
// TODO(antoyo): check if this should only be added when using -Cforce-unwind-tables=n.
264+
context.add_command_line_option("-fno-asynchronous-unwind-tables");
265+
context
266+
}
267+
247268
impl ExtraBackendMethods for GccCodegenBackend {
248269
fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind) -> Self::Module {
249270
let mut mods = GccContext {
250-
context: Context::default(),
271+
context: new_context(&tcx),
251272
should_combine_object_files: false,
252273
temp_dir: None,
253274
};
254275

255-
if tcx.sess.target.arch == "x86" || tcx.sess.target.arch == "x86_64" {
256-
mods.context.add_command_line_option("-masm=intel");
257-
}
258276
unsafe { allocator::codegen(tcx, &mut mods, module_name, kind, alloc_error_handler_kind); }
259277
mods
260278
}

0 commit comments

Comments
 (0)