Trouble disabling LLVM optimizations via pragma

有些话、适合烂在心里 提交于 2019-11-28 00:17:51

问题


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)?


回答1:


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.



来源:https://stackoverflow.com/questions/5625624/trouble-disabling-llvm-optimizations-via-pragma

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!