Skip to content

Commit e91bf6c

Browse files
committed
Auto merge of #69478 - avr-rust:avr-support-upstream, r=jonas-schievink
Enable AVR as a Tier 3 target upstream Tracking issue: #44052. Things intentionally left out of the initial upstream: * The `target_cpu` flag I have made the cleanup suggestions by @jplatte and @jplatte in avr-rust@043550d. Anybody feel free to give the branch a test and see how it fares, or make suggestions on the code patch itself.
2 parents 14027f3 + 0340359 commit e91bf6c

File tree

24 files changed

+201
-6
lines changed

24 files changed

+201
-6
lines changed

config.toml.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
# the same format as above, but since these targets are experimental, they are
7070
# not built by default and the experimental Rust compilation targets that depend
7171
# on them will not work unless the user opts in to building them.
72-
#experimental-targets = ""
72+
#experimental-targets = "AVR"
7373

7474
# Cap the number of parallel linker invocations when compiling LLVM.
7575
# This can be useful when building LLVM with debug info, which significantly

src/bootstrap/native.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl Step for Llvm {
144144

145145
let llvm_exp_targets = match builder.config.llvm_experimental_targets {
146146
Some(ref s) => s,
147-
None => "",
147+
None => "AVR",
148148
};
149149

150150
let assertions = if builder.config.llvm_assertions { "ON" } else { "OFF" };

src/libcore/ptr/mod.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,14 +1345,24 @@ macro_rules! fnptr_impls_safety_abi {
13451345
#[stable(feature = "fnptr_impls", since = "1.4.0")]
13461346
impl<Ret, $($Arg),*> fmt::Pointer for $FnTy {
13471347
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1348-
fmt::Pointer::fmt(&(*self as *const ()), f)
1348+
// HACK: The intermediate cast as usize is required for AVR
1349+
// so that the address space of the source function pointer
1350+
// is preserved in the final function pointer.
1351+
//
1352+
// https://github.com/avr-rust/rust/issues/143
1353+
fmt::Pointer::fmt(&(*self as usize as *const ()), f)
13491354
}
13501355
}
13511356

13521357
#[stable(feature = "fnptr_impls", since = "1.4.0")]
13531358
impl<Ret, $($Arg),*> fmt::Debug for $FnTy {
13541359
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1355-
fmt::Pointer::fmt(&(*self as *const ()), f)
1360+
// HACK: The intermediate cast as usize is required for AVR
1361+
// so that the address space of the source function pointer
1362+
// is preserved in the final function pointer.
1363+
//
1364+
// https://github.com/avr-rust/rust/issues/143
1365+
fmt::Pointer::fmt(&(*self as usize as *const ()), f)
13561366
}
13571367
}
13581368
}

src/librustc_ast_passes/feature_gate.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ impl<'a> PostExpansionVisitor<'a> {
121121
"amdgpu-kernel ABI is experimental and subject to change"
122122
);
123123
}
124+
"avr-interrupt" | "avr-non-blocking-interrupt" => {
125+
gate_feature_post!(
126+
&self,
127+
abi_avr_interrupt,
128+
span,
129+
"avr-interrupt and avr-non-blocking-interrupt ABIs are experimental and subject to change"
130+
);
131+
}
124132
"efiapi" => {
125133
gate_feature_post!(
126134
&self,

src/librustc_codegen_llvm/abi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
375375
match self.conv {
376376
Conv::C | Conv::Rust => llvm::CCallConv,
377377
Conv::AmdGpuKernel => llvm::AmdGpuKernel,
378+
Conv::AvrInterrupt => llvm::AvrInterrupt,
379+
Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt,
378380
Conv::ArmAapcs => llvm::ArmAapcsCallConv,
379381
Conv::Msp430Intr => llvm::Msp430Intr,
380382
Conv::PtxKernel => llvm::PtxKernel,

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub enum CallConv {
4545
X86_64_Win64 = 79,
4646
X86_VectorCall = 80,
4747
X86_Intr = 83,
48+
AvrNonBlockingInterrupt = 84,
49+
AvrInterrupt = 85,
4850
AmdGpuKernel = 91,
4951
}
5052

src/librustc_feature/active.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ declare_features! (
574574
/// No longer treat an unsafe function as an unsafe block.
575575
(active, unsafe_block_in_unsafe_fn, "1.45.0", Some(71668), None),
576576

577+
/// Allows `extern "avr-interrupt" fn()` and `extern "avr-non-blocking-interrupt" fn()`.
578+
(active, abi_avr_interrupt, "1.45.0", Some(69664), None),
579+
577580
// -------------------------------------------------------------------------
578581
// feature-group-end: actual feature gates
579582
// -------------------------------------------------------------------------

src/librustc_llvm/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ fn main() {
7878
"arm",
7979
"aarch64",
8080
"amdgpu",
81+
"avr",
8182
"mips",
8283
"powerpc",
8384
"systemz",

src/librustc_llvm/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ pub fn initialize_available_targets() {
7676
LLVMInitializeAMDGPUAsmPrinter,
7777
LLVMInitializeAMDGPUAsmParser
7878
);
79+
init_target!(
80+
llvm_component = "avr",
81+
LLVMInitializeAVRTargetInfo,
82+
LLVMInitializeAVRTarget,
83+
LLVMInitializeAVRTargetMC,
84+
LLVMInitializeAVRAsmPrinter,
85+
LLVMInitializeAVRAsmParser
86+
);
7987
init_target!(
8088
llvm_component = "mips",
8189
LLVMInitializeMipsTargetInfo,

src/librustc_middle/ty/layout.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,6 +2529,8 @@ where
25292529
Msp430Interrupt => Conv::Msp430Intr,
25302530
X86Interrupt => Conv::X86Intr,
25312531
AmdGpuKernel => Conv::AmdGpuKernel,
2532+
AvrInterrupt => Conv::AvrInterrupt,
2533+
AvrNonBlockingInterrupt => Conv::AvrNonBlockingInterrupt,
25322534

25332535
// These API constants ought to be more specific...
25342536
Cdecl => Conv::C,

0 commit comments

Comments
 (0)