[compiler-rt] r221826 - PR21518: Use unsigned arithmetic for trapping add/sub functions.

Bob Wilson bob.wilson at apple.com
Wed Nov 12 15:01:24 PST 2014


Author: bwilson
Date: Wed Nov 12 17:01:24 2014
New Revision: 221826

URL: http://llvm.org/viewvc/llvm-project?rev=221826&view=rev
Log:
PR21518: Use unsigned arithmetic for trapping add/sub functions.

The code in {add,sub}v.i3 routines does not trap when it should, because
it performs the actual add/subtract operation in signed arithmetic,
rather than unsigned.

Patch by Francois-Xavie Coudert!

Modified:
    compiler-rt/trunk/lib/builtins/addvdi3.c
    compiler-rt/trunk/lib/builtins/addvsi3.c
    compiler-rt/trunk/lib/builtins/addvti3.c
    compiler-rt/trunk/lib/builtins/subvdi3.c
    compiler-rt/trunk/lib/builtins/subvsi3.c
    compiler-rt/trunk/lib/builtins/subvti3.c

Modified: compiler-rt/trunk/lib/builtins/addvdi3.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/addvdi3.c?rev=221826&r1=221825&r2=221826&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/addvdi3.c (original)
+++ compiler-rt/trunk/lib/builtins/addvdi3.c Wed Nov 12 17:01:24 2014
@@ -21,7 +21,7 @@
 COMPILER_RT_ABI di_int
 __addvdi3(di_int a, di_int b)
 {
-    di_int s = a + b;
+    di_int s = (du_int) a + (du_int) b;
     if (b >= 0)
     {
         if (s < a)

Modified: compiler-rt/trunk/lib/builtins/addvsi3.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/addvsi3.c?rev=221826&r1=221825&r2=221826&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/addvsi3.c (original)
+++ compiler-rt/trunk/lib/builtins/addvsi3.c Wed Nov 12 17:01:24 2014
@@ -21,7 +21,7 @@
 COMPILER_RT_ABI si_int
 __addvsi3(si_int a, si_int b)
 {
-    si_int s = a + b;
+    si_int s = (su_int) a + (su_int) b;
     if (b >= 0)
     {
         if (s < a)

Modified: compiler-rt/trunk/lib/builtins/addvti3.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/addvti3.c?rev=221826&r1=221825&r2=221826&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/addvti3.c (original)
+++ compiler-rt/trunk/lib/builtins/addvti3.c Wed Nov 12 17:01:24 2014
@@ -23,7 +23,7 @@
 COMPILER_RT_ABI ti_int
 __addvti3(ti_int a, ti_int b)
 {
-    ti_int s = a + b;
+    ti_int s = (tu_int) a + (tu_int) b;
     if (b >= 0)
     {
         if (s < a)

Modified: compiler-rt/trunk/lib/builtins/subvdi3.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/subvdi3.c?rev=221826&r1=221825&r2=221826&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/subvdi3.c (original)
+++ compiler-rt/trunk/lib/builtins/subvdi3.c Wed Nov 12 17:01:24 2014
@@ -21,7 +21,7 @@
 COMPILER_RT_ABI di_int
 __subvdi3(di_int a, di_int b)
 {
-    di_int s = a - b;
+    di_int s = (du_int) a - (du_int) b;
     if (b >= 0)
     {
         if (s > a)

Modified: compiler-rt/trunk/lib/builtins/subvsi3.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/subvsi3.c?rev=221826&r1=221825&r2=221826&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/subvsi3.c (original)
+++ compiler-rt/trunk/lib/builtins/subvsi3.c Wed Nov 12 17:01:24 2014
@@ -21,7 +21,7 @@
 COMPILER_RT_ABI si_int
 __subvsi3(si_int a, si_int b)
 {
-    si_int s = a - b;
+    si_int s = (su_int) a - (su_int) b;
     if (b >= 0)
     {
         if (s > a)

Modified: compiler-rt/trunk/lib/builtins/subvti3.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/builtins/subvti3.c?rev=221826&r1=221825&r2=221826&view=diff
==============================================================================
--- compiler-rt/trunk/lib/builtins/subvti3.c (original)
+++ compiler-rt/trunk/lib/builtins/subvti3.c Wed Nov 12 17:01:24 2014
@@ -23,7 +23,7 @@
 COMPILER_RT_ABI ti_int
 __subvti3(ti_int a, ti_int b)
 {
-    ti_int s = a - b;
+    ti_int s = (tu_int) a - (tu_int) b;
     if (b >= 0)
     {
         if (s > a)





More information about the llvm-commits mailing list