[PATCH] [compiler-rt] Avoid undefined behaviour in __floatsisf and __floatsidf
Matthew Fernandez via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 2 03:32:08 PST 2015
These two functions for soft floating point support negate their signed int argument if it is negative. In the case
where the argument is INT_MIN, this negation is undefined behaviour with respect to the C standard. This change performs
the negation on an unsigned value, avoiding the just-described situation. This change does not alter the intended
semantics of these functions.
Signed-off-by: Matthew Fernandez <matthew.fernandez at gmail.com>
Index: lib/builtins/floatsidf.c
===================================================================
--- lib/builtins/floatsidf.c (revision 251670)
+++ lib/builtins/floatsidf.c (working copy)
@@ -33,7 +33,7 @@
rep_t sign = 0;
if (a < 0) {
sign = signBit;
- a = -a;
+ a = -(unsigned int)a;
}
// Exponent of (fp_t)a is the width of abs(a).
Index: lib/builtins/floatsisf.c
===================================================================
--- lib/builtins/floatsisf.c (revision 251670)
+++ lib/builtins/floatsisf.c (working copy)
@@ -33,7 +33,7 @@
rep_t sign = 0;
if (a < 0) {
sign = signBit;
- a = -a;
+ a = -(unsigned int)a;
}
// Exponent of (fp_t)a is the width of abs(a).
More information about the llvm-commits
mailing list