[llvm-commits] [PATCH] -fno-strict-overflow/-fwrapv: allow pointer arithmetic to be defined as wrapping instead of undefined on overflow

Török Edwin edwintorok at gmail.com
Sun Feb 1 12:32:29 PST 2009


Hi,

gcc provides -fwrapv and -fno-strict-overflow that allows pointer +
unsigned to be treated as possibly wrapping, instead of undefined ->
can't happen (the default with -fstrict-overflow, -O2, -O3 or -Os).

Currently LLVM's Instcombine pass changes this:
%15 = getelementptr i8* %buf, i64 %size
%16 = icmp ult i8* %15, %buf

into this:
   %3 = getelementptr i8* %buf, i64 %size
       %4 = icmp slt i64 %size, 0 

Which is fine for usual C programs, since pointer arithmetic overflow is
undefined.

However I think that the Linnux kernel needs -fwrapv/-fstrict-overflow
for gcc anyway (see http://bugzilla.kernel.org/show_bug.cgi?id=12597),
and it would be good if LLVM would support that too.
For signed integer I understand that in LLVM it is already defined as
wrapping, so only pointer arithmetic remains.

I wrote a patch (attached), I'd like to know if you agree with this
patch, or would like to see some other solution.

When LTO will be supported on Linux, it'll also mean that
-fno-strict-overflow/-fwrapv will have to be passed to the linker as well,
(and to libLTO).

Best regards,
--Edwin
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: patch1
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090201/c08ab89e/attachment.ksh>


More information about the llvm-commits mailing list