aboutsummaryrefslogtreecommitdiff
path: root/gcc/convert.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2017-09-05 15:55:04 +0000
committerMarek Polacek <mpolacek@gcc.gnu.org>2017-09-05 15:55:04 +0000
commitc253525edd51a027b7db30e077a6643a78544b0c (patch)
tree984ffdfa544660a19e390c366d332810a8203588 /gcc/convert.c
parentd49318d9bc3e63251aada27b322e7756eab19884 (diff)
downloadgcc-c253525edd51a027b7db30e077a6643a78544b0c.zip
gcc-c253525edd51a027b7db30e077a6643a78544b0c.tar.gz
gcc-c253525edd51a027b7db30e077a6643a78544b0c.tar.bz2
re PR sanitizer/82072 (sanitizer does not detect an overflow from LLONG_MIN)
PR sanitizer/82072 * convert.c (convert_to_integer_1) <case NEGATE_EXPR>: Move the ubsan check earlier. * c-c++-common/ubsan/pr82072-2.c: New test. From-SVN: r251717
Diffstat (limited to 'gcc/convert.c')
-rw-r--r--gcc/convert.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/gcc/convert.c b/gcc/convert.c
index 139d790..bfe18fb 100644
--- a/gcc/convert.c
+++ b/gcc/convert.c
@@ -886,6 +886,12 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
break;
case NEGATE_EXPR:
+ /* Using unsigned arithmetic for signed types may hide overflow
+ bugs. */
+ if (!TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (expr, 0)))
+ && sanitize_flags_p (SANITIZE_SI_OVERFLOW))
+ break;
+ /* Fall through. */
case BIT_NOT_EXPR:
/* This is not correct for ABS_EXPR,
since we must test the sign before truncation. */
@@ -902,12 +908,7 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
TYPE_UNSIGNED (typex));
if (!TYPE_UNSIGNED (typex))
- {
- /* Using unsigned arithmetic may hide overflow bugs. */
- if (sanitize_flags_p (SANITIZE_SI_OVERFLOW))
- break;
- typex = unsigned_type_for (typex);
- }
+ typex = unsigned_type_for (typex);
return convert (type,
fold_build1 (ex_form, typex,
convert (typex,