make doNotOptimizeAway work with clang
authorMainak Mandal <mmandal@fb.com>
Wed, 26 Aug 2015 17:42:59 +0000 (10:42 -0700)
committerSara Golemon <sgolemon@fb.com>
Mon, 31 Aug 2015 20:24:55 +0000 (13:24 -0700)
Summary: Projects depending on benchmark library fail to build with clang with the following error
```
./folly/Benchark.h:263:16: error: inline asm not supported yet: don't know how to handle tied indirect register inputs
```

I am not an expert here, just tried to take an approach similar to the MSVC compiler clause

Reviewed By: @andralex, @yfeldblum

Differential Revision: D2368670

folly/Benchmark.h

index 3478d10f11cf22ac3ce428290cbc2fa0b1c2c29e..c25ca2800f2907b62da7250553036b9881bb2c8c 100644 (file)
@@ -257,11 +257,19 @@ void doNotOptimizeAway(T&& datum) {
 
 #pragma optimize("", on)
 
+#elif defined(__clang__)
+
+template <class T>
+__attribute__((__optnone__)) void doNotOptimizeAway(T&& datum) {
+}
+
 #else
+
 template <class T>
 void doNotOptimizeAway(T&& datum) {
   asm volatile("" : "+r" (datum));
 }
+
 #endif
 
 } // namespace folly