Skip to content

Commit

Permalink
exercises/pointer-revocation: make arg volatile
Browse files Browse the repository at this point in the history
Otherwise the compiler can see that we're only using obj1->arg and so won't
necessarily reload it (and might not even store it) as we wish for
demonstration.
  • Loading branch information
nwf authored Sep 9, 2020
1 parent ff95344 commit d778719
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/exercises/pointer-revocation/temporal-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ fn2(uintptr_t arg)

struct obj {
char buf[32];
/* Volatile so that the compiler will always reload it */
/*
* The following are marked volatile to ensure the compiler doesn't
* constant propagate fn (making aliasing not work) and to ensure
* neither stores to them are optimised away entirely as dead due
* to calling free.
*/
void (* volatile fn)(uintptr_t);
uintptr_t arg;
volatile uintptr_t arg;
};

int
Expand Down

0 comments on commit d778719

Please sign in to comment.