jfbastien / jfbastien/stdconsume

Pointers escaping is probably bad

Open
#1 0 comments 1 reaction 0 assignees View on GitHub
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.