about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAntoni Boucher <bouanto@zoho.com>2023-10-17 19:43:20 -0400
committerAntoni Boucher <bouanto@zoho.com>2023-10-17 20:55:54 -0400
commit9d5e0ba1f51f61ba8ccaa6c37eef25ac497ea70c (patch)
tree7aeeef8581371b5c699036d2f9855ebf7bb8a6ab /src
parente5fa9f869287f85ddc6b3d72457d8c56669638f6 (diff)
downloadrust-9d5e0ba1f51f61ba8ccaa6c37eef25ac497ea70c.tar.gz
rust-9d5e0ba1f51f61ba8ccaa6c37eef25ac497ea70c.zip
Fixes including fixing compilation for --no-default-features
Diffstat (limited to 'src')
-rw-r--r--src/abi.rs9
-rw-r--r--src/context.rs33
-rw-r--r--src/declare.rs2
3 files changed, 31 insertions, 13 deletions
diff --git a/src/abi.rs b/src/abi.rs
index 5600f1ba8a9..f601cd95f2a 100644
--- a/src/abi.rs
+++ b/src/abi.rs
@@ -1,4 +1,6 @@
-use gccjit::{FnAttribute, ToLValue, ToRValue, Type};
+#[cfg(feature = "master")]
+use gccjit::FnAttribute;
+use gccjit::{ToLValue, ToRValue, Type};
 use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeMethods};
 use rustc_data_structures::fx::FxHashSet;
 use rustc_middle::bug;
@@ -101,6 +103,7 @@ pub struct FnAbiGcc<'gcc> {
     pub arguments_type: Vec<Type<'gcc>>,
     pub is_c_variadic: bool,
     pub on_stack_param_indices: FxHashSet<usize>,
+    #[cfg(feature = "master")]
     pub fn_attributes: Vec<FnAttribute<'gcc>>,
 }
 
@@ -129,6 +132,7 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
                     cx.type_void()
                 }
             };
+        #[cfg(feature = "master")]
         let mut non_null_args = Vec::new();
 
         #[cfg(feature = "master")]
@@ -190,14 +194,13 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
         } else {
             vec![FnAttribute::NonNull(non_null_args)]
         };
-        #[cfg(not(feature = "master"))]
-        let fn_attrs = Vec::new();
 
         FnAbiGcc {
             return_type,
             arguments_type: argument_tys,
             is_c_variadic: self.c_variadic,
             on_stack_param_indices,
+            #[cfg(feature = "master")]
             fn_attributes: fn_attrs,
         }
     }
diff --git a/src/context.rs b/src/context.rs
index b01ac7b57af..243556a0e52 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -132,7 +132,21 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
         let create_type = |ctype, rust_type| {
             let layout = tcx.layout_of(ParamEnv::reveal_all().and(rust_type)).unwrap();
             let align = layout.align.abi.bytes();
-            context.new_c_type(ctype).get_aligned(align)
+            #[cfg(feature="master")]
+            {
+                context.new_c_type(ctype).get_aligned(align)
+            }
+            #[cfg(not(feature="master"))]
+            {
+                // Since libgccjit 12 doesn't contain the fix to compare aligned integer types,
+                // only align u128 and i128.
+                if layout.ty.int_size_and_signed(tcx).0.bytes() == 16 {
+                    context.new_c_type(ctype).get_aligned(align)
+                }
+                else {
+                    context.new_c_type(ctype)
+                }
+            }
         };
 
         let i8_type = create_type(CType::Int8t, tcx.types.i8);
@@ -271,16 +285,15 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
     }
 
     pub fn is_native_int_type(&self, typ: Type<'gcc>) -> bool {
-        // TODO: cache those types to not query libgccjit everytime this is called.
         let types = [
-            self.context.new_c_type(CType::UInt8t),
-            self.context.new_c_type(CType::UInt16t),
-            self.context.new_c_type(CType::UInt32t),
-            self.context.new_c_type(CType::UInt64t),
-            self.context.new_c_type(CType::Int8t),
-            self.context.new_c_type(CType::Int16t),
-            self.context.new_c_type(CType::Int32t),
-            self.context.new_c_type(CType::Int64t),
+            self.u8_type,
+            self.u16_type,
+            self.u32_type,
+            self.u64_type,
+            self.i8_type,
+            self.i16_type,
+            self.i32_type,
+            self.i64_type,
         ];
 
         for native_type in types {
diff --git a/src/declare.rs b/src/declare.rs
index 0b583c074dd..247454fa58e 100644
--- a/src/declare.rs
+++ b/src/declare.rs
@@ -85,10 +85,12 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
             arguments_type,
             is_c_variadic,
             on_stack_param_indices,
+            #[cfg(feature="master")]
             fn_attributes,
         } = fn_abi.gcc_type(self);
         let func = declare_raw_fn(self, name, () /*fn_abi.llvm_cconv()*/, return_type, &arguments_type, is_c_variadic);
         self.on_stack_function_params.borrow_mut().insert(func, on_stack_param_indices);
+        #[cfg(feature="master")]
         for fn_attr in fn_attributes {
             func.add_attribute(fn_attr);
         }