[geos-devel] Effects of using -g and -O2 together

Mateusz Loskot mateusz at loskot.net
Thu Jul 6 13:04:17 EDT 2006


Hi,

I noticed that GEOS' ./configure scripts called with
--enable-cassert=yes (GEOS equivalent of --enable-debug=yes)
sets CFLAGS as follows:

CFLAGS = -g -O2 -Wall -ansi -pedantic -Wno-long-long

As you see, this will produce debug version of optimized code.
It is not forbidden, but according to GCC manual, it can produce
some side and unexpected effects:

http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Debugging-Options.html#Debugging-Options
"GCC allows you to use -g with -O. The shortcuts taken by optimized code
may occasionally produce surprising results: some variables you declared
may not exist at all; flow of control may briefly move where you did not
expect it; some statements may not be executed because they compute
constant results or their values were already at hand; some statements
may execute in different places because they were moved out of loops."

I'd suggest to remove -O2 option if --enable-cassert is passed to
./configure.

What do you think?

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the geos-devel mailing list