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

Volatile loads and stores aren't honored #166

Open
yvt opened this issue Apr 25, 2022 · 1 comment · May be fixed by #167
Open

Volatile loads and stores aren't honored #166

yvt opened this issue Apr 25, 2022 · 1 comment · May be fixed by #167
Labels
bug Something isn't working

Comments

@yvt
Copy link
Contributor

yvt commented Apr 25, 2022

#[no_mangle]
pub unsafe fn assign_answer(x: *mut u32) {
    x.read_volatile();
    x.write_volatile(42);
    x.write_volatile(42);
}

In the code generated by cg_llvm, all volatile loads and stores are preserved.

0000000000001100 <assign_answer>:
    1100:       8b 07                   mov    (%rdi),%eax
    1102:       c7 07 2a 00 00 00       movl   $0x2a,(%rdi)
    1108:       c7 07 2a 00 00 00       movl   $0x2a,(%rdi)
    110e:       c3                      ret    
    110f:       90                      nop

In the code generated by cg_gcc, the load whose result is discarded is eliminated, and the overlapping stores are combined into one.

0000000000001100 <assign_answer>:
    1100:       c7 07 2a 00 00 00       movl   $0x2a,(%rdi)
    1106:       c3                      ret    
    1107:       66 0f 1f 84 00 00 00    nopw   0x0(%rax,%rax,1)
    110e:       00 00 
@yvt
Copy link
Contributor Author

yvt commented Apr 25, 2022

Looks like the volatile qualification is incorrectly applied to the pointer type instead of its pointee.

fn volatile_load(&mut self, _ty: Type<'gcc>, ptr: RValue<'gcc>) -> RValue<'gcc> {
// TODO(antoyo): use ty.
let ptr = self.context.new_cast(None, ptr, ptr.get_type().make_volatile());
ptr.dereference(None).to_rvalue()
}

@antoyo antoyo added the bug Something isn't working label Apr 25, 2022
@yvt yvt linked a pull request Apr 26, 2022 that will close this issue
@YakoYakoYokuYoku YakoYakoYokuYoku mentioned this issue Dec 24, 2023
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants