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

Reads to volatiles are not mapped to read_volatile #292

Open
chrysn opened this issue Sep 3, 2020 · 0 comments
Open

Reads to volatiles are not mapped to read_volatile #292

chrysn opened this issue Sep 3, 2020 · 0 comments

Comments

@chrysn
Copy link
Contributor

chrysn commented Sep 3, 2020

The RIOT-OS code base I'm translating as part of the efforts around rust-lang/rust-bindgen#1344 contains a function like

 static inline kernel_pid_t thread_getpid(void)
 {
     extern volatile kernel_pid_t sched_active_pid;
 
     return sched_active_pid;
 }

My previous manual translation of this was unsafe { ::core::ptr::read_volatile(&bindgen_generated_symbols::sched_active_pid) }. When translating with c2rust transpile comile_commands.json --preserve-unused-functions --emit-modules --emit-no-std (using #291), I get

#[inline]
pub unsafe extern "C" fn thread_getpid() -> kernel_pid_t {
    extern "C" {
        #[link_name = "sched_active_pid"]
        static mut sched_active_pid_0: kernel_pid_t;
    }
    return sched_active_pid;
}

which, in my understanding, allows the compiler to mush together multiple calls in a single function. That's not particularly bad for get_pid (which won't change in code that the Rust compiler will see as contiguous), but other functions will depend on the read to be volatile.

(I'm not fuly sure whether that's a bug in C2Rust, me expecting things it can't know or just the lack of a flag, but after looking through the docs and existing issues, I'm hoping for the former).

@kkysen kkysen changed the title Reads to volatiles are not mapped to read_volatile Reads to volatiles are not mapped to read_volatile Jun 29, 2022
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

1 participant