-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade Rust base (aa35e73b) #137
Conversation
- libarena - librustc_allocator - librustc_borrowck - librustc_codegen_ssa - librustc_codegen_utils - librustc_driver - librustc_errors - librustc_incremental - librustc_metadata - librustc_passes - librustc_privacy - librustc_resolve - librustc_save_analysis - librustc_target - librustc_traits - libsyntax - libsyntax_ext - libsyntax_pos
- libfmt_macros - librustdoc
This avoids the dependency on host libraries such as libgcc_s which may be undesirable in some deployment environments where these aren't available.
When using the `rustfix-coverage` flag, some tests currently fail because they define a different error-format than `json`. The current implementation crashes when encountering those tests. Since we don't care about non-json test output when collecting the coverage data, we handle those tests by returning an empty `Vec` instead.
…n in the rustc book.
Functions with uninhabited return values are already marked `noreturn`, but we were still generating return instructions for this. When running with `-C passes=lint`, LLVM prints: Unusual: Return statement in function with noreturn attribute The LLVM manual makes a stronger statement about `noreturn` though: > This produces undefined behavior at runtime if the function ever does dynamically return. We now emit an `abort` anywhere that would have tried to return an uninhabited value.
Revert rust-lld place changes Fixes rust-lang#59661. Instead of rust-lang#59668 it reverts only failed part.
Problem
; ModuleID = 'bugpoint-reduced-simplified.bc'
source_filename = "core.37hoedwx-cgu.0"
target datalayout = "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8"
target triple = "avr-unknown-unknown"
define void @"_ZN4core3ptr87_$LT$impl$u20$core..fmt..Debug$u20$for$u20$unsafe$u20$fn$LP$A$RP$$u20$.$GT$$u20$Ret$GT$3fmt17h0fdf8ca7140def9bE"() unnamed_addr addrspace(1) #0 {
start:
%0 = addrspacecast {} addrspace(1)* undef to {}*
store {}* %0, {}** undef, align 1
ret void
}
attributes #0 = { "target-cpu"="atmega328p" }
!llvm.module.flags = !{!0}
!0 = !{i32 2, !"Debug Info Version", i32 3} |
Problem
|
The first problem looks like a program address space zero bug. The second one sounds like the regular.
Yeah, the glacial "Move to GitHub"... I reckon we should fork github.com/llvm/llvm-project, add our branches, leave both repositories up, set the old avr-rust/llvm repo as read-only and go from there. |
That’s actually already done and used by this branch. |
When I compile the "ran out of registers" bug on LLVM master. it passes. |
Submitted a fix for upstream code review D62775. |
I now think that the At the moment, the AVR backend does not support |
Here is the full IR generated from libcore. This was generated along the lines of |
The IR triggering the For some reason, the $ cat ~/libcore.ll |rg "define.*addrspace.*%self"
define internal zeroext i1 @"_ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17hbd9cadb576049f93E"({ i8*, i8* } ({}*) addrspace(1)*** noalias nocapture readonly align 1 dereferenceable(2) %self, %"fmt::Formatter"* align 1 dereferenceable(27) %f) unnamed_addr addrspace(1) #6 { |
Here is the function that is failing. It is the debug implementation for either |
Here is the IR of the failing function ; <&T as core::fmt::Debug>::fmt
; Function Attrs: uwtable
define internal zeroext i1 @"_ZN42_$LT$$RF$T$u20$as$u20$core..fmt..Debug$GT$3fmt17hbd9cadb576049f93E"({ i8*, i8* } ({}*) addrspace(1)*** noalias nocapture readonly align 1 dereferenceable(2) %self, %"fmt::Formatter"* align 1 dereferenceable(27) %f) unnamed_addr addrspace(1) #6 {
start:
%buf.i.i.i.i = alloca [128 x i8], align 1
%0 = bitcast { i8*, i8* } ({}*) addrspace(1)*** %self to {} addrspace(1)***
%1 = load {} addrspace(1)**, {} addrspace(1)*** %0, align 1, !nonnull !456
%2 = load {} addrspace(1)*, {} addrspace(1)** %1, align 1, !alias.scope !5154, !nonnull !456
%3 = addrspacecast {} addrspace(1)* %2 to {}*
%4 = ptrtoint {}* %3 to i16
%5 = getelementptr inbounds %"fmt::Formatter", %"fmt::Formatter"* %f, i16 0, i32 7, i32 0
%6 = load i8, i8* %5, align 1, !range !2, !noalias !5157
%7 = getelementptr inbounds %"fmt::Formatter", %"fmt::Formatter"* %f, i16 0, i32 7, i32 1
%8 = load i16, i16* %7, align 1, !noalias !5157
%9 = bitcast %"fmt::Formatter"* %f to i32*
%10 = load i32, i32* %9, align 1, !noalias !5157
%11 = and i32 %10, 4
%12 = icmp eq i32 %11, 0
br i1 %12, label %bb6.i.i, label %bb2.i.i
bb2.i.i: ; preds = %start
%13 = or i32 %10, 8
store i32 %13, i32* %9, align 1, !noalias !5157
%14 = icmp eq i8 %6, 0
br i1 %14, label %bb3.i.i, label %bb6.i.i
bb3.i.i: ; preds = %bb2.i.i
store i16 6, i16* %7, align 1, !noalias !5157
store i8 1, i8* %5, align 1, !noalias !5157
br label %bb6.i.i
bb6.i.i: ; preds = %bb3.i.i, %bb2.i.i, %start
%15 = phi i32 [ %10, %start ], [ %13, %bb3.i.i ], [ %13, %bb2.i.i ]
%16 = or i32 %15, 4
store i32 %16, i32* %9, align 1, !noalias !5157
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %buf.i.i.i.i, i16 0, i16 0
call addrspace(1) void @llvm.lifetime.start.p0i8(i64 128, i8* nonnull %17), !noalias !5160
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %buf.i.i.i.i, i16 0, i16 128
br label %bb15.i.i.i.i
bb15.i.i.i.i: ; preds = %bb15.i.i.i.i, %bb6.i.i
%iter.sroa.4.0.i.i.i.i = phi i8* [ %18, %bb6.i.i ], [ %19, %bb15.i.i.i.i ]
%x.0.i.i.i.i = phi i16 [ %4, %bb6.i.i ], [ %20, %bb15.i.i.i.i ]
%curr.0.i.i.i.i = phi i16 [ 128, %bb6.i.i ], [ %26, %bb15.i.i.i.i ]
%19 = getelementptr inbounds i8, i8* %iter.sroa.4.0.i.i.i.i, i16 -1
%20 = lshr i16 %x.0.i.i.i.i, 4
%21 = trunc i16 %x.0.i.i.i.i to i8
%22 = and i8 %21, 15
%23 = icmp ult i8 %22, 10
%24 = or i8 %22, 48
%25 = add nuw nsw i8 %22, 87
%_0.0.i15.i.i.i.i = select i1 %23, i8 %24, i8 %25
store i8 %_0.0.i15.i.i.i.i, i8* %19, align 1, !noalias !5160
%26 = add nsw i16 %curr.0.i.i.i.i, -1
%27 = icmp eq i16 %20, 0
br i1 %27, label %bb43.i.i.i.i, label %bb15.i.i.i.i
bb43.i.i.i.i: ; preds = %bb15.i.i.i.i
%28 = icmp ugt i16 %26, 128
br i1 %28, label %bb1.i.i.i.i.i.i.i, label %"_ZN4core3ptr87_$LT$impl$u20$core..fmt..Debug$u20$for$u20$unsafe$u20$fn$LP$A$RP$$u20$.$GT$$u20$Ret$GT$3fmt17ha5a3565824dd93e2E.exit"
bb1.i.i.i.i.i.i.i: ; preds = %bb43.i.i.i.i
; call core::slice::slice_index_order_fail
tail call addrspace(1) void @_ZN4core5slice22slice_index_order_fail17h1a521a1329c8fcf9E(i16 %26, i16 128) #17, !noalias !5160
unreachable
"_ZN4core3ptr87_$LT$impl$u20$core..fmt..Debug$u20$for$u20$unsafe$u20$fn$LP$A$RP$$u20$.$GT$$u20$Ret$GT$3fmt17ha5a3565824dd93e2E.exit": ; preds = %bb43.i.i.i.i
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %buf.i.i.i.i, i16 0, i16 %26
%30 = sub i16 129, %curr.0.i.i.i.i
%_3.sroa.0.0._3.sroa.0.0..cast.i.i.i.i.i = bitcast i8* %29 to [0 x i8]*
; call core::fmt::Formatter::pad_integral
%31 = call zeroext addrspace(1) i1 @_ZN4core3fmt9Formatter12pad_integral17h8cbb788acd2ae784E(%"fmt::Formatter"* nonnull align 1 dereferenceable(27) %f, i1 zeroext true, [0 x i8]* noalias nonnull readonly align 1 bitcast (<{ [2 x i8] }>* @anon.1eadd1440c2e72f10a9c27e27f9e4574.191 to [0 x i8]*), i16 2, [0 x i8]* noalias nonnull readonly align 1 %_3.sroa.0.0._3.sroa.0.0..cast.i.i.i.i.i, i16 %30), !noalias !5160
call addrspace(1) void @llvm.lifetime.end.p0i8(i64 128, i8* nonnull %17), !noalias !5160
store i8 %6, i8* %5, align 1, !noalias !5157
store i16 %8, i16* %7, align 1, !noalias !5157
store i32 %10, i32* %9, align 1, !noalias !5157
ret i1 %31
} |
It seems like LLVM/Rust is choking because when debug printing function pointers. This is the shoddy IR %3 = addrspacecast {} addrspace(1)* %2 to {}*
%4 = ptrtoint {}* %3 to i16 In order to convert an Think of it like this On AVR, you cannot convert a PROGMEM function pointer into a RAM pointer (the physical memory spaces are disjoint). Also, it probably makes more sense to print the PROGMEM function pointer when debug printing functions. We should just go I am not sure if it is possible to implement the We need to modify Rust so that it does not attempt this address space conversion and instead use |
That code is here; but it doesn't do anything too weird, so any changes may need to be lower down. |
The underlying issue is that |
Here is the // MIR for `ptr::<impl at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2625:9: 2630:10>::fmt`
// source = MirSource { instance: Item(DefId(0/0:9218 ~ core[fd1a]::ptr[0]::{{impl}}[235]::fmt[0])), promoted: None }
// pass_name = TypeckMir
// disambiguator = before
fn ptr::<impl at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2625:9: 2630:10>::fmt(_1: &for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret, _2: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> {
let mut _0: result::Result<(), fmt::Error>; // return place
let mut _3: &*const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret;
let mut _4: &*const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret;
let _5: *const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret;
let mut _6: for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret;
let mut _7: &mut fmt::Formatter<'_>;
bb0: {
StorageLive(_3); // bb0[0]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:35: 2627:59
StorageLive(_4); // bb0[1]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:35: 2627:59
StorageLive(_5); // bb0[2]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:36: 2627:59
StorageLive(_6); // bb0[3]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:37: 2627:42
_6 = (*_1); // bb0[4]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:37: 2627:42
_5 = move _6 as *const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret (Misc); // bb0[5]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:36: 2627:59
StorageDead(_6); // bb0[6]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:58: 2627:59
_4 = &_5; // bb0[7]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:35: 2627:59
_3 = &(*_4); // bb0[8]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:35: 2627:59
StorageLive(_7); // bb0[9]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:61: 2627:62
_7 = &mut (*_2); // bb0[10]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:61: 2627:62
_0 = const fmt::Pointer::fmt(move _3, move _7) -> [return: bb2, unwind: bb1]; // bb0[11]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:17: 2627:63
// ty::Const
// + ty: for<'r, 's, 't0> fn(&'r *const for<'t1> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'t1>, ...) -> Ret, &'s mut fmt::Formatter<'t0>) -> result::Result<(), fmt::Error> {<*const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret as fmt::Pointer>::fmt}
// + val: Scalar(Bits { size: 0, bits: 0 })
// mir::Constant
// + span: /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:17: 2627:34
// + ty: for<'r, 's, 't0> fn(&'r *const for<'t1> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'t1>, ...) -> Ret, &'s mut fmt::Formatter<'t0>) -> result::Result<(), fmt::Error> {<*const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret as fmt::Pointer>::fmt}
// + literal: Const { ty: for<'r, 's, 't0> fn(&'r *const for<'t1> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'t1>, ...) -> Ret, &'s mut fmt::Formatter<'t0>) -> result::Result<(), fmt::Error> {<*const for<'r> unsafe extern "C" fn(A, B, C, D, ffi::VaList<'r>, ...) -> Ret as fmt::Pointer>::fmt}, val: Scalar(Bits { size: 0, bits: 0 }) }
}
bb1 (cleanup): {
resume; // bb1[0]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2626:13: 2629:14
}
bb2: {
StorageDead(_7); // bb2[0]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:62: 2627:63
StorageDead(_3); // bb2[1]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2627:62: 2627:63
StorageDead(_4); // bb2[2]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2629:13: 2629:14
StorageDead(_5); // bb2[3]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2629:13: 2629:14
return; // bb2[4]: scope 0 at /home/dylan/projects/avr-rust/rust/src/libcore/ptr.rs:2629:14: 2629:14
}
} |
Raised #143 for the addrspace issue. |
This PR (currently at 8b7240e) can successfully compile the blink program in release mode. When I try to compile in debug mode, I get errorsl ike this:
Sounds like avr-llvm/llvm#163. |
007b5cd
to
8b7240e
Compare
I've raised PR #144, which is another rebase on top of this. I've also cherry-picked some commits at the top of avr-support that hadn't been pulled into this branch. |
Superseded by #144 . |
No description provided.