Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apple LLVM 5.0 pragma optimize

What is the equivalent of GCC's #pragma GCC optimize("O0") or VS's #pragma optimize("", off) in Apple LLVM 5.0 compiler?

I need it to disable optimizations for just a section of code.

like image 982
Mircea Ispas Avatar asked Nov 04 '13 13:11

Mircea Ispas


2 Answers

From a brief search it doesn't look like clang/llvm supports such a pragma at this time. If you don't want to turn off optimizations for an entire file I suggest factoring what you don't want optimized into a separate file and setting -O0 on it separately.

like image 126
Jon Shier Avatar answered Oct 16 '22 16:10

Jon Shier


Actually there is now a way to do that by specifying an __attribute__ ((optnone)) to the function that wraps the code you don't want to be optimized.

For instance I'm using it to have a clear benchmark of an inline function

static void BM_notoptimizedfunction(benchmark::State& state) __attribute__ ((optnone)) {
    // your code here won't be optimized by clang
}

And that's it !

like image 41
dulaccc Avatar answered Oct 16 '22 14:10

dulaccc