[cfe-dev] Possible error in EmitCXXNewAllocSize

Eli Friedman eli.friedman at gmail.com
Sat Apr 9 11:45:12 PDT 2011


On Sat, Apr 9, 2011 at 11:25 AM, Daniel Schwartz-Narbonne
<dstwo at princeton.edu> wrote:
> I was looking through the code for this function, and on line 533,
> where you check whether an overflow occurred, you say
>      DidOverflow = CGF.Builder.CreateAnd(DidOverflow, AddDidOverflow);
> Shouldn't this be an OR?  Doesn't the error occur if either the
> multiplication or the addition overflowed?

You're right; testcase demonstrating the overflow:
struct A { char x[1<<16]; ~A(); };
A* f() { int x = 1<<16; return new A[x]; };

Run this through "clang -x c++ - -o - -S -m32 -emit-llvm -O2", and you
get "tail call noalias i8* @_Znaj(i32 4)".

-Eli




More information about the cfe-dev mailing list