Skip to content
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

thumbv6m: debug assertion in divmoddi4 #150

Closed
japaric opened this issue Mar 13, 2017 · 13 comments
Closed

thumbv6m: debug assertion in divmoddi4 #150

japaric opened this issue Mar 13, 2017 · 13 comments

Comments

@japaric
Copy link
Member

japaric commented Mar 13, 2017

#[test]
fn divmoddi4() {
    let (a, b) = (4165187992, 3876330169);
    let mut rem = 0;
    let c = __divmoddi4(a, b, &mut rem_);
}
$ qemu-arm target/thumbv6m-linux-eabi/debug/divmoddi4-04f11ecf75829660
running 1 tests
test divmoddi4 ...
panicked at 'attempt to multiply with overflow', /home/japaric/.cargo/git/checkouts/compiler-builtins-ec094dc45a0179c8/9681358/src/int/udiv.rs:95
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
[1]    21208 illegal hardware instruction (core dumped)  qemu-arm target/thumbv6m-linux-eabi/debug/divmoddi4-04f11ecf75829660

thumbv7m targets don't have this problem.

@japaric
Copy link
Member Author

japaric commented Mar 13, 2017

Another case that results in an assertion (1750458948, 2611493155) with divdi3.

@japaric
Copy link
Member Author

japaric commented Apr 10, 2017

Testing all these intrinsics fail due to this debug assertion

  • divdi3
  • divmoddi4
  • moddi3
  • modsi3
  • udivmoddi4
  • udivmodsi4
  • umoddi3
  • umodsi3

@parched
Copy link
Contributor

parched commented Jun 8, 2017

This is probably fix by rust-lang/llvm#79

@parched
Copy link
Contributor

parched commented Jun 17, 2017

@japaric I think this should be fixed in the latest nightly now that rust-lang/rust#42410 has landed.

@japaric
Copy link
Member Author

japaric commented Jun 17, 2017

I tested with rustc 1.19.0-nightly (fe7227f6c 2017-06-16) and I'm still seeing the debug assertion. I'll try again with the next nightly release.

@parched
Copy link
Contributor

parched commented Jun 17, 2017

Ok, that commit had the fix in, so this must be caused by something else.

@parched
Copy link
Contributor

parched commented Jun 18, 2017

@japaric I'd like to debug this, how exactly did you run the test? Do I have to build all of std with Xargo for thumbv6m-linux-eabi?

@japaric
Copy link
Member Author

japaric commented Jun 18, 2017

@parched I actually ran the whole test suite with sh ci/run.sh thumbv6m-linux-eabi. But you can run a single custom test like this:

$ edit tests/custom.rs && cat $_
#![feature(compiler_builtins_lib)]
#![no_std]

extern crate compiler_builtins;
extern crate utest_cortex_m_qemu;
#[macro_use]
extern crate utest_macros;

macro_rules! panic {
    ($($tt:tt)*) => {
        upanic!($($tt)*);
    };
}

use compiler_builtins::int::sdiv::__divmoddi4;

#[test]
fn divmoddi4() {
    let (a, b) = (4165187992, 3876330169);
    let mut rem = 0;
    let c = __divmoddi4(a, b, &mut rem);
}
$ xargo test --test custom --target thumbv6m-linux-eabi --features 'mem gen-tests' --no-run
$ qemu-arm target/thumbv6m-linux-eabi/debug/custom-6bc70d2d2f80ab1e
running 1 tests
test divmoddi4 ...
panicked at 'attempt to multiply with overflow', src/int/udiv.rs:95
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
[1]    27726 illegal hardware instruction (core dumped)  qemu-arm target/thumbv6m-linux-eabi/debug/custom-6bc70d2d2f80ab1e

@parched
Copy link
Contributor

parched commented Jun 20, 2017

Ok, I've debugged it and looks like LLVM bug for unsigned multiplication with overflow. I'll make a patch.

@japaric
Copy link
Member Author

japaric commented Jun 20, 2017

Thanks for investigating and working on this @parched ❤️

@parched
Copy link
Contributor

parched commented Jun 20, 2017

No problem, the fix has been accepted upstream. Once rust-lang/llvm#85 is merged and rust is updated hopefully this will be fixed.

bors added a commit to rust-lang/rust that referenced this issue Jun 23, 2017
Update LLVM to fix unsigned multiplication overflow

check for some targets, notably ARMv6-M.

Fixes rust-lang/compiler-builtins#150
@parched
Copy link
Contributor

parched commented Jun 23, 2017

@japaric Do some tests need to be re-enabled now?

@japaric
Copy link
Member Author

japaric commented Jun 23, 2017

@parched Yes. I'll send a PR later today. (I suspect a nightly with the fix may not be out yet.)

japaric added a commit that referenced this issue Jun 28, 2017
bors added a commit that referenced this issue Jun 28, 2017
enable tests now that #150 has been fixed

cc @parched
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants