Can different optimization levels lead to functionally different code?

前端 未结 13 1923
[愿得一人]
[愿得一人] 2020-12-13 12:39

I am curious about the liberties that a compiler has when optimizing. Let\'s limit this question to GCC and C/C++ (any version, any flavour of standard):

Is it possi

13条回答
  •  悲哀的现实
    2020-12-13 13:07

    Got some interesting example in my OS course today. We analized some software mutex that could be damaged on optimization because the compiler does not know about the parallel execution.

    The compiler can reorder statements that do not operate on dependent data. As I already statet in parallelized code this dependencie is hidden for the compiler so it could break. The example I gave would lead to some hard times in debugging as the threadsafety is broken and your code behaves unpredictable because of OS-scheduling issues and concurrent access errors.

提交回复
热议问题