This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug sanitizer/81148] UBSAN: two more false positives


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81148

--- Comment #10 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
It should've been

--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -874,9 +874,24 @@ split_tree (location_t loc, tree in, tree type, enum
tree_code code,
    }
       if (var)
    {
-     /* Convert to TYPE before negating.  */
-     var = fold_convert_loc (loc, type, var);
-     var = negate_expr (var);
+     if ((*litp == NULL_TREE
+          && *conp == NULL_TREE
+          && *minus_litp == NULL_TREE)
+         || !INTEGRAL_TYPE_P (type)
+         || TYPE_OVERFLOW_WRAPS (type))
+       {
+         /* Convert to TYPE before negating.  */
+         var = fold_convert_loc (loc, type, var);
+         var = negate_expr (var);
+       }
+     else
+       {
+         /* Go back to blank slate.  */
+         var = in;
+         *conp = NULL_TREE;
+         *litp = NULL_TREE;
+         *minus_litp = NULL_TREE;
+       }
    }
     }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]