Debug build optimizes variables out
Describe the bug If I build SeisSol as Debug some variables get optimized out.
Expected behavior No variables get optimized out in Debug builds.
To Reproduce Steps to reproduce the behavior:
- Current Master
- Intel Compiler
- On SuperMUC-NG
Does it happen in the Fortran or C++ code?
C++
When I manually add -O0 it works.
maybe we can try something like below in the main CMakeLists.txt?
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_compile_options(SeisSol-lib PUBLIC "-g")
endif()
or something like
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()
here https://github.com/SeisSol/SeisSol/blob/b98133c397244e8f0bcb0e38e6a2d163b039409e/CMakeLists.txt#L296-L306
There's also CMAKE_CXX_FLAGS_DEBUG. Apparently Cmake doesn't set -O0 (but I thought it was default anyway on most compilers?)
Apparently, gcc recommends -0g (see here)
but I thought it was default anyway on most compilers?
You are right. Maybe it is not a case for Intel compiler.
@sebwolf-de, have you tried the changes that I suggested? If it works we can probably add them to the master branch
According to the man pages, -O0 is default for gcc and -02 is default for intel. You can find the latter under the documentation for the argument -ftrapuv:
which changes the default optimization level from O2 to -O0 (Linux and macOS*) or /Od (Windows). You can override this effect by explicitly specifying an O option setting.
So we should add to CMAKE_CXX_FLAGS_DEBUG: -O0 for intel, -Og for gcc (maybe?). Not sure what to set for clang, it supports -Og but this defaults to -O1. So we should probably choose -O0 as well? https://clang.llvm.org/docs/CommandGuide/clang.html#cmdoption-o0
@ravil-mobile thanks for your suggestions, but the -g was already set before, it was rather a matter of the -O flags