From: Jakub Jelinek Date: Tue, 11 Dec 2018 13:51:44 +0000 (+0100) Subject: re PR sanitizer/88426 (Compiler crash if use special code with command line switch... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6d9391732bc8816627ff40103a6261d233c722bf;p=gcc.git re PR sanitizer/88426 (Compiler crash if use special code with command line switch -fsanitize=float-cast-overflow) 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 --- diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 9bbfe76040b..294442cd41b 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2018-12-11 Jakub Jelinek + + PR sanitizer/88426 + * c-convert.c (convert): Call c_fully_fold before calling + ubsan_instrument_float_cast. + 2018-12-08 Segher Boessenkool * c-parser (c_parser_asm_statement) [RID_INLINE]: Delete stray line diff --git a/gcc/c/c-convert.c b/gcc/c/c-convert.c index b57bb8ea936..6165e145c0b 100644 --- a/gcc/c/c-convert.c +++ b/gcc/c/c-convert.c @@ -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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b718fed5f17..52804b4b8b6 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-12-11 Jakub Jelinek + + PR sanitizer/88426 + * c-c++-common/ubsan/float-cast-overflow-11.c: New test. + 2018-12-11 Yannick Moy * 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 index 00000000000..b96c218aa1a --- /dev/null +++ b/gcc/testsuite/c-c++-common/ubsan/float-cast-overflow-11.c @@ -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); +}