This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Pointer wraparound warning


On Fri, 02 May 2008 17:50:53 -0700 Ian Lance Taylor (ILT) wrote:

ILT> "Udo A. Steinberg" <us15@os.inf.tu-dresden.de> writes:
ILT> 
ILT> > gcc now complains about the following code snippet, saying...
ILT> > warning: assuming pointer wraparound does not occur when comparing
ILT> > P +- C1 with P +- C2
ILT> 
ILT> Presumably only when you use -Wstrict-overflow=N where N >= 3.  At
ILT> that level false positives are likely.

Actually it warns at N >= 2. I'm using gcc version 4.4.0 20080428
(experimental) via: g++ -Os -Wstrict-overflow=2 foo.cpp

ILT> > In the first snippet ptr never points outside x[], so the compiler
ILT> > shouldn't warn. What am I missing here?
ILT> 
ILT> Nothing.  The compiler could be smarter here.  pointer_may_wrap_p in
ILT> fold-const.c could handle TREE_CODE (TREE_TYPE (base)) == ARRAY_TYPE.

That would be nice.

ILT> By the way, the compiler doesn't warn here:

[...]

ILT> because it doesn't know that putc doesn't change x, so it can't
ILT> optimize away the comparison.

Ahh ok! Thanks for the explanation.

Cheers,

	- Udo


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]