summaryrefslogtreecommitdiff
path: root/gcc/c/c-convert.c
diff options
context:
space:
mode:
authorGary Funck <gfunck@gcc.gnu.org>2014-12-22 23:50:11 +0000
committerGary Funck <gfunck@gcc.gnu.org>2014-12-22 23:50:11 +0000
commit22ef28e6899cf24cd092fd9a257072e21c92f83c (patch)
tree8ec10a7bee308d810a2214290df50f03fe6bd54c /gcc/c/c-convert.c
parent981a930d371ec2fbb916d1e9520d5d9250beffb1 (diff)
parent9a1e784ae82f0ebff6d018631d3fe3730359f3c1 (diff)
downloadgcc-22ef28e6899cf24cd092fd9a257072e21c92f83c.tar.gz
Merge trunk version 219006 into gupc branch.
From-SVN: r219038
Diffstat (limited to 'gcc/c/c-convert.c')
-rw-r--r--gcc/c/c-convert.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/gcc/c/c-convert.c b/gcc/c/c-convert.c
index fcc15b11488..93aef853c5e 100644
--- a/gcc/c/c-convert.c
+++ b/gcc/c/c-convert.c
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
#include "c-tree.h"
#include "langhooks.h"
#include "target.h"
+#include "ubsan.h"
/* Change of width--truncation and extension of integers or reals--
is represented with NOP_EXPR. Proper functioning of many things
@@ -117,6 +118,20 @@ convert (tree type, tree expr)
case INTEGER_TYPE:
case ENUMERAL_TYPE:
+ if (flag_sanitize & SANITIZE_FLOAT_CAST
+ && TREE_CODE (TREE_TYPE (expr)) == REAL_TYPE
+ && COMPLETE_TYPE_P (type)
+ && current_function_decl != NULL_TREE
+ && !lookup_attribute ("no_sanitize_undefined",
+ DECL_ATTRIBUTES (current_function_decl)))
+ {
+ expr = c_save_expr (expr);
+ tree check = ubsan_instrument_float_cast (loc, type, expr);
+ expr = fold_build1 (FIX_TRUNC_EXPR, type, expr);
+ if (check == NULL)
+ return expr;
+ return fold_build2 (COMPOUND_EXPR, TREE_TYPE (expr), check, expr);
+ }
ret = convert_to_integer (type, e);
goto maybe_fold;