Should --enable-debug set CFLAGS to -O0 instead of -O2? - Mailing list pgsql-hackers

From Chao Li
Subject Should --enable-debug set CFLAGS to -O0 instead of -O2?
Date
Msg-id CAEoWx2me6o8kHXx8CLdqymeeYkLD=kPKVi9wbx8_PTPO8cM_jw@mail.gmail.com
Whole thread Raw
Responses Re: Should --enable-debug set CFLAGS to -O0 instead of -O2?
List pgsql-hackers
Hi,

I noticed that "./configure --enable-debug" will set "-O2" to CFLAGS. To better debug/trace the code, I have to manually change "-O2" to "-O0" in src/Makefile.global.

In the script "configure" line 5254 through 5259, I see this comment:

# C[XX]FLAGS are selected so:
# If the user specifies something in the environment, that is used.
# else: If the template file set something, that is used.
# else: If coverage was enabled, don't set anything.
# else: If the compiler is GCC, then we use -O2.
# else: If the compiler is something else, then we use -O, unless debugging.


The last line, "unless debugging", my first impression is that should apply to GCC. However, the following code shows the GCC always use "-O2".

elif test "$GCC" = yes; then
CFLAGS="-O2"
else
# if the user selected debug mode, don't use -O
if test "$enable_debug" != yes; then
CFLAGS="-O"
fi
fi

For GCC, we need to use "-O0" for best debugging experience. Why here always uses "-O2" for GCC regardless debugging?

If confirmed a bug, I'd like a submit a patch to fix that.

Thanks,
Chao Li (Evan)
============
HighGo Inc.

pgsql-hackers by date:

Previous
From: Chao Li
Date:
Subject: Re: Cannot login CommitFests due to cool-off period
Next
From: Tom Lane
Date:
Subject: Re: Should --enable-debug set CFLAGS to -O0 instead of -O2?