5 ms·
It seems to "optimize out" volatile reads if the result is not used.
by foxfluff 5y ago
It seems to "optimize out" volatile reads if the result is not used.
- TickleSteve 5y agoIf true, that would be a bug. You dont want to remove register reads from devices for example if the device requires it.
- tialaramex 5y agoIt looks to me like they're turned into the appropriate Rust intrinsic. Do you have an example where the read vanishes? Notice that it's very easy for C programmers to write code they think is performing a volatile read, but isn't, whereas obviously the intrinsics reduce the scope for this error in the Rust (it is also, though that's not relevant here, easy to write C code that depends on imaginary semantics of volatile access and so the code doesn't actually always work, or it works but not for the reason the programmer expected)
- foxfluff 5y agoIf you believe there is no volatile read in this code, I'd like to understand why. void func(volatile unsigned *a) { *a; }
- tialaramex 5y agoNope, I agree that's a volatile read, and indeed the web page doesn't emit the appropriate intrinsic, nor indeed do small modifications that result in a read of the pointer, cause the intrinsic to be used as I'd anticipated. Definitely something to be wary of. I assure you the c2rust source code does know about volatile access and Rust's intrinsics (I was looking at that code for other reasons), so if you work with this stuff I'd encourage talking to the people who wrote it to find out what the situation is.