From 0e81719703bf681533220f3629cc4f1a24110778 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 2 Dec 2016 00:15:57 +0100 Subject: [PATCH] re PR tree-optimization/78586 (Wrong code caused by printf-return-value) PR tree-optimization/78586 * gimple-ssa-sprintf.c (format_integer): Don't handle NOP_EXPR, CONVERT_EXPR or COMPONENT_REF here. Formatting fix. For SSA_NAME_DEF_STMT with NOP_EXPR only change argtype if the rhs1's type is INTEGER_TYPE or POINTER_TYPE. From-SVN: r243145 --- gcc/ChangeLog | 8 ++++++++ gcc/gimple-ssa-sprintf.c | 30 ++++++++++++------------------ 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7f9dd0e..c3170c0 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2016-12-02 Jakub Jelinek + + PR tree-optimization/78586 + * gimple-ssa-sprintf.c (format_integer): Don't handle NOP_EXPR, + CONVERT_EXPR or COMPONENT_REF here. Formatting fix. For + SSA_NAME_DEF_STMT with NOP_EXPR only change argtype if the rhs1's + type is INTEGER_TYPE or POINTER_TYPE. + 2016-12-01 Kelvin Nilsen PR target/78577 diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c index 99a635a..e86c4dc 100644 --- a/gcc/gimple-ssa-sprintf.c +++ b/gcc/gimple-ssa-sprintf.c @@ -968,24 +968,13 @@ format_integer (const conversion_spec &spec, tree arg) } else if (TREE_CODE (TREE_TYPE (arg)) == INTEGER_TYPE || TREE_CODE (TREE_TYPE (arg)) == POINTER_TYPE) - { - /* Determine the type of the provided non-constant argument. */ - if (TREE_CODE (arg) == NOP_EXPR) - arg = TREE_OPERAND (arg, 0); - else if (TREE_CODE (arg) == CONVERT_EXPR) - arg = TREE_OPERAND (arg, 0); - if (TREE_CODE (arg) == COMPONENT_REF) - arg = TREE_OPERAND (arg, 1); - - argtype = TREE_TYPE (arg); - } + /* Determine the type of the provided non-constant argument. */ + argtype = TREE_TYPE (arg); else - { - /* Don't bother with invalid arguments since they likely would - have already been diagnosed, and disable any further checking - of the format string by returning [-1, -1]. */ - return fmtresult (); - } + /* Don't bother with invalid arguments since they likely would + have already been diagnosed, and disable any further checking + of the format string by returning [-1, -1]. */ + return fmtresult (); fmtresult res; @@ -1059,7 +1048,12 @@ format_integer (const conversion_spec &spec, tree arg) } if (code == NOP_EXPR) - argtype = TREE_TYPE (gimple_assign_rhs1 (def)); + { + tree type = TREE_TYPE (gimple_assign_rhs1 (def)); + if (TREE_CODE (type) == INTEGER_TYPE + || TREE_CODE (type) == POINTER_TYPE) + argtype = type; + } } } } -- 2.7.4