Skip to content

Instantly share code, notes, and snippets.

@daniel-j-h
Created October 6, 2015 12:23
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daniel-j-h/0a1c1414a68d4a67d4b4 to your computer and use it in GitHub Desktop.
Save daniel-j-h/0a1c1414a68d4a67d4b4 to your computer and use it in GitHub Desktop.
Defeating the Optimizer --- Chandler Carruth' CppCon2015 Tricks
static void escape(void* p) {
asm volatile("" : : "g"(p) : "memory");
}
static void clobber() {
asm volatile("" : : : "memory");
}
@johnmcfarlane
Copy link

Does anyone know the equivalent trick for the Visual C++ compiler?

@TheMarex
Copy link

VC can do something like:

#pragma optimize( "", off )
template<typename T>
static void escape(T&& v) {
   T local = v;
}
#pragma optimize( "", on )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment