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

Possible compiler bug with const_fn (Calling a function with bad signature) #39543

Closed
johalun opened this Issue Feb 4, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@johalun
Copy link

johalun commented Feb 4, 2017

Error when building following:

Tested with:

rustc 1.16.0-nightly (7821a9b99 2017-01-23)

Build with:

xargo build --target x86_64-kernel-freebsd

this code

#![no_std]
#![feature(const_fn)]
#![feature(lang_items)]
#![allow(dead_code)]
#![allow(unused_imports)]

extern crate spin;

use spin::Mutex;
use core::cell::UnsafeCell;
use core::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};

// Compile error
// static mut Y1: Mutex<i32> = Mutex::new(0i32);

// No compile error (requires making Mutex members public in spin crate)
static mut Y2: Mutex<i32> = Mutex
{
    lock: ATOMIC_BOOL_INIT,
    data: UnsafeCell::new(0i32),
};

#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
#[lang = "eh_unwind_resume"]
extern "C" fn eh_unwind_resume() {}
#[lang = "panic_fmt"]
extern "C" fn panic_impl(_: core::fmt::Arguments, _: &'static str, _: u32) -> ! {loop {}}

causes error:

Assertion failed: ((Args.size() == FTy->getNumParams() || (FTy->isVarArg() && Args.size() > FTy->getNumParams())) && "Calling a function with bad signature!"), function init, file /buildslave/rust-buildbot/slave/nightly-dist-rustc-cross-host-linux/build/src/llvm/lib/IR/Instructions.cpp, line 258.

Target configuration (x86_64-kernel-freebsd.json)

{
	"llvm-target": "x86_64-unknown-freebsd",
	"target-endian": "little",
	"target-pointer-width": "64",
	"os": "none",
	"arch": "x86_64",
	"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128",
	"pre-link-args": [ "-m64" ],
	"cpu": "x86-64",
	"features": "+soft-float,-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2",
	"disable-redzone":         true,
	"custom-unwind-resume":    true,
	"eliminate-frame-pointer": true,
	"linker-is-gnu":           true,
	"no-compiler-rt":          true,
	"archive-format":          "gnu",
	"code-model":              "kernel",
	"relocation-model":        "static"
}
@johalun

This comment has been minimized.

Copy link
Author

johalun commented Feb 5, 2017

I've been digging a bit further and the follow code simplifies things a bit.

#![no_std]
#![feature(const_fn)]
#![feature(lang_items)]
#![allow(dead_code)]
#![allow(unused_imports)]
#![feature(optin_builtin_traits)]

use core::sync::atomic::{AtomicBool, Ordering, ATOMIC_BOOL_INIT};

pub struct UnsafeCell<T: ?Sized> {
    value: T,
}
impl<T> UnsafeCell<T> {
    pub const fn new(value: T) -> UnsafeCell<T> {
        UnsafeCell { value: value }
    }
}

pub struct Mut<T: ?Sized> {
    data: UnsafeCell<T>
}
impl<T> Mut<T> {
    pub const fn new(user_data: T) -> Mut<T>
    {
        Mut
        {
            // data: UnsafeCell { value: user_data }, // no error
            data: UnsafeCell::new(user_data),  // compile error
        }
    }
}
static mut X: UnsafeCell<i32> = UnsafeCell::new(0i32); // no error
static mut Y: Mut<i32> = Mut::new(0i32); // error if use Unsafecell::new()

#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
#[lang = "eh_unwind_resume"]
extern "C" fn eh_unwind_resume() {}
#[lang = "panic_fmt"]
extern "C" fn panic_impl(_: core::fmt::Arguments, _: &'static str, _: u32) -> ! {
    loop {}
}

@johalun

This comment has been minimized.

Copy link
Author

johalun commented Feb 7, 2017

I think I found the problem. After I played around with the target config json file I found the "custom-unwind-resume": true caused the error.

Keeping it true while adding

[profile.dev]
panic = "abort"
[profile.release]
panic = "abort"

to Cargo.toml seem to have solved the problem. I though I had added that but apparently lost it somewhere on the way....

@johalun johalun closed this Feb 7, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.