diff --git a/configure b/configure index ac392d2fda..6f1b7cd83d 100755 --- a/configure +++ b/configure @@ -5194,8 +5194,19 @@ if test "$gcov" = "yes" ; then LDFLAGS="-fprofile-arcs -ftest-coverage $LDFLAGS" elif test "$fortify_source" = "yes" ; then CFLAGS="-O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $CFLAGS" -elif test "$debug" = "no"; then - CFLAGS="-O2 $CFLAGS" +elif test "$debug" = "yes"; then + if compile_prog "-Og" ""; then + CFLAGS="-Og $CFLAGS" + elif compile_prog "-O1" ""; then + CFLAGS="-O1 $CFLAGS" + fi + # Workaround GCC false-positive Wuninitialized bugs with Og or O1: + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=24639 + if cc_has_warning_flag "-Wno-maybe-uninitialized"; then + CFLAGS="-Wno-maybe-uninitialized $CFLAGS" + fi +else + CFLAGS="-O2 $CFLAGS" fi ##########################################