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!
llvm-svn: 221826
diff --git a/compiler-rt/lib/builtins/addvdi3.c b/compiler-rt/lib/builtins/addvdi3.c
index db45a27..0da3894 100644
--- a/compiler-rt/lib/builtins/addvdi3.c
+++ b/compiler-rt/lib/builtins/addvdi3.c
@@ -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)
diff --git a/compiler-rt/lib/builtins/addvsi3.c b/compiler-rt/lib/builtins/addvsi3.c
index 81f515c..94ca726 100644
--- a/compiler-rt/lib/builtins/addvsi3.c
+++ b/compiler-rt/lib/builtins/addvsi3.c
@@ -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)
diff --git a/compiler-rt/lib/builtins/addvti3.c b/compiler-rt/lib/builtins/addvti3.c
index 79b9611..c224de6 100644
--- a/compiler-rt/lib/builtins/addvti3.c
+++ b/compiler-rt/lib/builtins/addvti3.c
@@ -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)
diff --git a/compiler-rt/lib/builtins/subvdi3.c b/compiler-rt/lib/builtins/subvdi3.c
index 0f1f924..71fc70f 100644
--- a/compiler-rt/lib/builtins/subvdi3.c
+++ b/compiler-rt/lib/builtins/subvdi3.c
@@ -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)
diff --git a/compiler-rt/lib/builtins/subvsi3.c b/compiler-rt/lib/builtins/subvsi3.c
index ec4594c..e6c0fb6 100644
--- a/compiler-rt/lib/builtins/subvsi3.c
+++ b/compiler-rt/lib/builtins/subvsi3.c
@@ -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)
diff --git a/compiler-rt/lib/builtins/subvti3.c b/compiler-rt/lib/builtins/subvti3.c
index 8f11714..a6804d2 100644
--- a/compiler-rt/lib/builtins/subvti3.c
+++ b/compiler-rt/lib/builtins/subvti3.c
@@ -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)