GCC: program doesn't work with compilation option -O3

后端 未结 16 1617
感动是毒
感动是毒 2020-12-16 20:12

I\'m writing a C++ program that doesn\'t work (I get a segmentation fault) when I compile it with optimizations (options -O1, -O2, -O3, etc.), but it works just fine when I

16条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 20:48

    It is very seldom the compiler fault, but compiler do have bugs in them, and them often manifest themselves at different optimization levels (if there is a bug in an optimization pass, for example).

    In general when reporting programming problems: provide a minimal code sample to demonstrate the issue, such that people can just save the code to a file, compile and run it. Make it as easy as possible to reproduce your problem.

    Also, try different versions of GCC (compiling your own GCC is very easy, especially on Linux). If possible, try with another compiler. Intel C has a compiler which is more or less GCC compatible (and free for non-commercial use, I think). This will help pinpointing the problem.

提交回复
热议问题