I work with a large and rather mature project in C ++ (10+ years of development, 150k + SLOC, 3k + test cases, www.sumo-sim.org ). We recently discovered that program behavior changes unexpectedly when you enter one seemingly innocent print statement (std :: cout <"foo \ n";) in a specific place. The objdump output also shows large changes in the generated code, depending on the presence of this print statement. A.
We currently believe this is due to undefined behavior and compiler optimization (as described in a message from John Reger ). This assumption is supported by our observation that the effect of print approval depends on the level of optimization. Since the application runs on a single concurrency thread, this should not be a problem.
To debug undefined behavior, we used clang with flags -fsanitize = undefined, unsigned-interger-overflow, address, integer and got rid of all these problems. We also fixed all the problems indicated by clang static analyzer , but the problem remains (curious with gcc, clang and msvc, but with slightly different results).
Now we are losing sight of how best to continue our debugging efforts. Due to the non-local nature of the consequences of a print statement, we donโt even know where to start with a code review.
Question 1: What tools would you recommend for conducting a static and temporary analysis of potential problem points (similar to the clang tools described above)?
Question 2: What mechanisms, besides a combination of undefined behavior + compiler optimization, are likely candidates for the observed effect (non-functional statements that change the behavior of the program)?
source share