Skip to content

Instantly share code, notes, and snippets.

@dannas
Created April 15, 2020 09:26
Show Gist options
  • Save dannas/bd863593511bf65fd221236344980591 to your computer and use it in GitHub Desktop.
Save dannas/bd863593511bf65fd221236344980591 to your computer and use it in GitHub Desktop.
// Unfinished example of clobber and doNotOptimize functions.
// https://godbolt.org/z/CkZ9Bh
void f() {
int val;
//asm volatile("" : : "r,m"(val) : "memory");
//asm volatile("" : : "rm"(val) : "memory");
asm volatile("" : "+m"(val) : : "memory");
val = 1;
asm volatile("" : : : "memory");
val = 2;
asm volatile("" : : : "memory");
}
extern int ExternInt;
extern int ExternInt2;
void g() {
ExternInt = 1;
asm volatile("" : : : "memory");
ExternInt = 2;
}
void redundant_read() {
int x;
asm volatile("" : "+m"(x) : : "memory");
x = ExternInt;
asm volatile("" : : : "memory");
x = ExternInt2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment