Switching off optimization for a specific function in gcc 4.2.2

前端 未结 7 2205
执笔经年
执笔经年 2020-12-16 16:24

Is it possible to switch off optimization of a specific function? A friend of mine has the problem that the gcc optimization makes some (unknown to me) µ-controller-code not

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 16:35

    Short of putting the function in its own file, I don't think there is any way to turn off optimization on a function by function level using earlier versions of GCC. But instead of switching off the optimization for this one function, you could try selecting switching off certain types of optimizations in the whole program. While you have identified a bug in this particular function, this likely points to the existence of other undiscovered bugs.

    As others pointed out, it's likely that the culprit is optimizations regarding 'strict aliasing'. While in the long run you probably should fix the code in question, in the short run you could play with adding '-fno-strict-aliasing' to your command line. At -O2 and above, the compiler makes certain assumptions about interactions between pointers. Adding this option tells it not to make these assumptions.

    If this fails, and if for some reason the code cannot be fixed, you could then try disabling other optimization options.

提交回复
热议问题