Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble disabling LLVM optimizations via pragma

I have a chunk of code that crashes unless I build with optimizations off. I'm building with LLVM compiler 2.0

I would like to turn off optimizations by wrapping the offending code with a #pragma compiler directive; or turn off optimizations for an entire file.

I've been digging in the clang manual and code; but nothing jumps out at me.

Does anyone know how to change the optimizations for a single CU (as opposed to for the entire app)?

like image 226
Dave Avatar asked Apr 11 '11 18:04

Dave


1 Answers

You can set per-file compiler flags in Xcode. In Xcode 4 (which I assume you're using because of the LLVM 2.0 reference), first select the project in the left-hand project browser. Go to the Build Phases tab and expand the Compile Sources build phase.

In there, you can set per-file compiler flags, so you could try going to the offending file and entering in -O0 as a flag to try and disable optimizations for just that file.

GCC has some attributes you can set for this, as pointed out by Johannes in his answer here, but these might not be in LLVM. Also, from the comments there, it appears that these are not even in Apple's customized GCC used for building iOS applications.

like image 86
Brad Larson Avatar answered Oct 16 '22 00:10

Brad Larson