From 889a3a30d0aea481e3452b0f2e25d0c4657b2f21 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Fri, 23 Mar 2018 13:45:49 +0000 Subject: [PATCH] re PR c++/85045 (ICE+SIGILL on valid C++ code: cxx_pretty_printer::postfix_expression(tree_node*) (), at cp/cxx-pretty-print.c:482) PR c++/85045 * c-pretty-print.c (c_pretty_printer::multiplicative_expression) : Tweak condition. * cxx-pretty-print.c (cxx_pretty_printer::multiplicative_expression): Handle EXACT_DIV_EXPR and RDIV_EXPR. Tweak condition. (cxx_pretty_printer::expression): Handle EXACT_DIV_EXPR and RDIV_EXPR. * g++.dg/cpp0x/Wnarrowing5.C: New test. * gcc.dg/pr85045.c: New test. From-SVN: r258804 --- gcc/c-family/ChangeLog | 6 ++++++ gcc/c-family/c-pretty-print.c | 2 +- gcc/cp/ChangeLog | 7 +++++++ gcc/cp/cxx-pretty-print.c | 6 +++++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C | 11 +++++++++++ gcc/testsuite/gcc.dg/pr85045.c | 9 +++++++++ 7 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C create mode 100644 gcc/testsuite/gcc.dg/pr85045.c diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 25ed91f2089..f728311310a 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2018-03-23 Marek Polacek + + PR c++/85045 + * c-pretty-print.c (c_pretty_printer::multiplicative_expression) + : Tweak condition. + 2018-03-20 Eric Botcazou * c-ada-spec.c (pp_ada_tree_identifier): Deal specifically with _Bool. diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c index c9dd8aefff9..dc76c9957d3 100644 --- a/gcc/c-family/c-pretty-print.c +++ b/gcc/c-family/c-pretty-print.c @@ -1841,7 +1841,7 @@ c_pretty_printer::multiplicative_expression (tree e) pp_c_whitespace (this); if (code == MULT_EXPR) pp_c_star (this); - else if (code == TRUNC_DIV_EXPR) + else if (code != TRUNC_MOD_EXPR) pp_slash (this); else pp_modulo (this); diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index e04eae18a44..ddda091b5fd 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2018-03-23 Marek Polacek + + PR c++/85045 + * cxx-pretty-print.c (cxx_pretty_printer::multiplicative_expression): + Handle EXACT_DIV_EXPR and RDIV_EXPR. Tweak condition. + (cxx_pretty_printer::expression): Handle EXACT_DIV_EXPR and RDIV_EXPR. + 2018-03-23 Ville Voutilainen Implement P0962 diff --git a/gcc/cp/cxx-pretty-print.c b/gcc/cp/cxx-pretty-print.c index ca99997f5e1..9a5545cb5cc 100644 --- a/gcc/cp/cxx-pretty-print.c +++ b/gcc/cp/cxx-pretty-print.c @@ -899,11 +899,13 @@ cxx_pretty_printer::multiplicative_expression (tree e) case MULT_EXPR: case TRUNC_DIV_EXPR: case TRUNC_MOD_EXPR: + case EXACT_DIV_EXPR: + case RDIV_EXPR: multiplicative_expression (TREE_OPERAND (e, 0)); pp_space (this); if (code == MULT_EXPR) pp_star (this); - else if (code == TRUNC_DIV_EXPR) + else if (code != TRUNC_MOD_EXPR) pp_slash (this); else pp_modulo (this); @@ -1113,6 +1115,8 @@ cxx_pretty_printer::expression (tree t) case MULT_EXPR: case TRUNC_DIV_EXPR: case TRUNC_MOD_EXPR: + case EXACT_DIV_EXPR: + case RDIV_EXPR: multiplicative_expression (t); break; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 88abac8faeb..fe12bbe38ce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,10 @@ PR c++/85033 * g++.dg/ext/builtin-offsetof2.C: New test. + PR c++/85045 + * g++.dg/cpp0x/Wnarrowing5.C: New test. + * gcc.dg/pr85045.c: New test. + 2018-03-23 Eric Botcazou PR debug/85020 diff --git a/gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C new file mode 100644 index 00000000000..d2abf03313e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/Wnarrowing5.C @@ -0,0 +1,11 @@ +// PR c++/85045 +// { dg-do compile { target c++11 } } + +typedef struct tt { + unsigned short h; +} tt; + +void mainScreen(float a) +{ + tt numlrect = {int(100/a)}; // { dg-error "narrowing conversion" } +} diff --git a/gcc/testsuite/gcc.dg/pr85045.c b/gcc/testsuite/gcc.dg/pr85045.c new file mode 100644 index 00000000000..8c4a7aa36a4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr85045.c @@ -0,0 +1,9 @@ +/* PR c/85045 */ +/* { dg-do compile } */ +/* { dg-options "-fno-diagnostics-show-caret" } */ + +void +f (double a, double b) +{ + (a / b) (); /* { dg-error "called object .a / b. is not a function or function pointer" } */ +} -- 2.30.2