On Wed, 2023-08-09 at 11:14 +0200, Luís Carlos Carneiro Gonçalves via Gcc wrote: > Without -O3 and -O2 the OpenCL gave consistently good results without > returning any error. > > I think my code is Ok but I open to criticism.
By "has a bug" we don't necessarily mean something that is obviously wrong and fails every time like trying to dereference a null pointer. We mean, you are making an assumption about how the compiler will compile your code, that is not guaranteed by the standard. Because it's not guaranteed, when you enable optimizations the compiler is free to rearrange things in ways you maybe don't expect, but are allowed by the language definition. > If you are open to help me I can send all the sources. I doubt anyone here has the time or energy to read and debug "all the sources" for you. If you reduce your code to a small example that shows the error, then post that to the correct mailing list as Jonathan suggested. Then someone may be able to point out your mistake. Or, maybe it really is a bug in the optimizer. Such things are very rare but have been known to happen. In my long experience as a programmer, however, "the compiler has a bug" has NEVER been a winning bet.