title: "Escape" and "Clobber" equivalent in MSVC
body: <p>In <a href="https://youtu.be/nXaxk27zwlk?t=42m42s">Chandler Carruth's CppCon 2015 talk</a> he introduces two magical functions for defeating the optimizer without any extra performance penalties.</p>
  
  <p>For reference, here are the functions (using GNU-style inline assembly):</p>
  
  <pre><code>void escape(void* p)
  {
      asm volatile("" : : "g"(p) : "memory");
  }
  
  void clobber()
  {
      asm volatile("" : : : "memory");
  }
  </code></pre>
  
  <p>It works on any compiler which supports GNU-style inline assembly (GCC, Clang, Intel's compiler, possibly others). However, he mentions it doesn't work in MSVC.</p>
  
  <p>Examining <a href="https://github.com/google/benchmark/blob/master/include/benchmark/benchmark_api.h">Google Benchmark's implementation</a>, it seems they use a reinterpret cast to a <code>volatile const char&amp;</code> and passes it to a function hidden in a different translation unit on non-gcc/clang compilers.</p>
  
  <pre><code>template &lt;class Tp&gt;
  inline BENCHMARK_ALWAYS_INLINE void DoNotOptimize(Tp const&amp; value) {
      internal::UseCharPointer(&amp;reinterpret_cast&lt;char const volatile&amp;&gt;(value));
  }
  
  // some other translation unit
  void UseCharPointer(char const volatile*) {}
  </code></pre>
  
  <p>However, there are two concerns I have with this:</p>
  
  <ol>
  <li>I'm potentially incurring a function call</li>
  <li>There is the possibility a "clever" link-time optimizer might recognize UseCharPointer is small, inline it, then discard all the code I wanted kept around, or a "clever" optimizer might be allowed to perform other re-orderings I don't want it to.</li>
  </ol>
  
  <p>Is there any lower-level equivalent in MSVC to the GNU-style assembly functions? Or is this the best it gets on MSVC?</p>