re PR sanitizer/88426 (Compiler crash if use special code with command line switch...
authorJakub Jelinek <jakub@redhat.com>
Tue, 11 Dec 2018 13:51:44 +0000 (14:51 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 11 Dec 2018 13:51:44 +0000 (14:51 +0100)
PR sanitizer/88426
* c-convert.c (convert): Call c_fully_fold before calling
ubsan_instrument_float_cast.

* c-c++-common/ubsan/float-cast-overflow-11.c: New test.

From-SVN: r267022

gcc/c/ChangeLog
gcc/c/c-convert.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/float-cast-overflow-11.c [new file with mode: 0644]

index 9bbfe76040b6b5e955f4e756642e3e73919b7a15..294442cd41ba6b8de5b863eb69da5b3c189253df 100644 (file)
@@ -1,3 +1,9 @@
+2018-12-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/88426
+       * c-convert.c (convert): Call c_fully_fold before calling
+       ubsan_instrument_float_cast.
+
 2018-12-08  Segher Boessenkool  <segher@kernel.crashing.org>
 
        * c-parser (c_parser_asm_statement) [RID_INLINE]: Delete stray line
index b57bb8ea93614b9a4cdd296f17357fdf68cb6118..6165e145c0be23ee0b346fe89decfebc226ec219 100644 (file)
@@ -115,6 +115,7 @@ convert (tree type, tree expr)
          && COMPLETE_TYPE_P (type))
        {
          expr = save_expr (expr);
+         expr = c_fully_fold (expr, false, NULL);
          tree check = ubsan_instrument_float_cast (loc, type, expr);
          expr = fold_build1 (FIX_TRUNC_EXPR, type, expr);
          if (check == NULL_TREE)
index b718fed5f17e3656841a316e36be1ab0fc8d7027..52804b4b8b6d3a810b61fb7e84ac30f5edf0320a 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/88426
+       * c-c++-common/ubsan/float-cast-overflow-11.c: New test.
+
 2018-12-11  Yannick Moy  <moy@adacore.com>
 
        * gnat.dg/ghost4.adb: New testcase.
diff --git a/gcc/testsuite/c-c++-common/ubsan/float-cast-overflow-11.c b/gcc/testsuite/c-c++-common/ubsan/float-cast-overflow-11.c
new file mode 100644 (file)
index 0000000..b96c218
--- /dev/null
@@ -0,0 +1,10 @@
+/* PR sanitizer/88426 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=float-cast-overflow" } */
+
+int
+foo (void)
+{
+  const float v = 0.0f;
+  return (int) (v < 0.0f ? v : 0.0f);
+}