jfbastien / jfbastien/stdconsume
Pointers escaping is probably bad
- Dominant language
- C++
- Stars
- 0
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
Consider:
#include "consume.h"
int global;
int foo(dependent_ptr dp) {
if (dp.value() == &global)
return *dp.value();
return 0;
}
Once you've got the int* from dependent_ptr::value, I think that's visible to the compiler and provably equivalent to dp, allowing nasty optimizations. For example Clang on arm64 gives:
__Z3foo13dependent_ptrIiE: ; @_Z3foo13dependent_ptrIiE
ldr x8, [x0]
adrp x9, _global@PAGE
add x9, x9, _global@PAGEOFF
ldr w10, [x9]
cmp x8, x9
csel w0, w10, wzr, eq
ret
I believe this drops the consume ordering on x0 since w10 is loaded independently.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.