diff mbox series

[13/14] c-format.c: handle location wrappers

Message ID 1510350329-48956-14-git-send-email-dmalcolm@redhat.com
State New
Headers show
Series Preserving locations for variable-uses and constants (PR 43486) | expand

Commit Message

David Malcolm Nov. 10, 2017, 9:45 p.m. UTC
gcc/c-family/ChangeLog:
	* c-format.c (check_format_arg): Strip any location wrapper around
	format_tree.
---
 gcc/c-family/c-format.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Jason Merrill Dec. 11, 2017, 11:45 p.m. UTC | #1
On 11/10/2017 04:45 PM, David Malcolm wrote:
> gcc/c-family/ChangeLog:
> 	* c-format.c (check_format_arg): Strip any location wrapper around
> 	format_tree.
> ---
>   gcc/c-family/c-format.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
> index 164d035..6b436ec 100644
> --- a/gcc/c-family/c-format.c
> +++ b/gcc/c-family/c-format.c
> @@ -1536,6 +1536,8 @@ check_format_arg (void *ctx, tree format_tree,
>   
>     location_t fmt_param_loc = EXPR_LOC_OR_LOC (format_tree, input_location);
>   
> +  STRIP_ANY_LOCATION_WRAPPER (format_tree);
> +
>     if (VAR_P (format_tree))
>       {
>         /* Pull out a constant value if the front end didn't.  */

It seems like we want fold_for_warn here instead of the special variable 
handling.  That probably makes sense for the other places you change in 
this patch, too.

Jason
diff mbox series

Patch

diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index 164d035..6b436ec 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -1536,6 +1536,8 @@  check_format_arg (void *ctx, tree format_tree,
 
   location_t fmt_param_loc = EXPR_LOC_OR_LOC (format_tree, input_location);
 
+  STRIP_ANY_LOCATION_WRAPPER (format_tree);
+
   if (VAR_P (format_tree))
     {
       /* Pull out a constant value if the front end didn't.  */
@@ -1598,6 +1600,7 @@  check_format_arg (void *ctx, tree format_tree,
     }
   res->format_string_loc = EXPR_LOC_OR_LOC (format_tree, input_location);
   format_tree = TREE_OPERAND (format_tree, 0);
+  STRIP_ANY_LOCATION_WRAPPER (format_tree);
   if (format_types[info->format_type].flags 
       & (int) FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL)
     {
@@ -1634,7 +1637,10 @@  check_format_arg (void *ctx, tree format_tree,
   if (TREE_CODE (format_tree) == ARRAY_REF
       && tree_fits_shwi_p (TREE_OPERAND (format_tree, 1))
       && (offset += tree_to_shwi (TREE_OPERAND (format_tree, 1))) >= 0)
-    format_tree = TREE_OPERAND (format_tree, 0);
+    {
+      format_tree = TREE_OPERAND (format_tree, 0);
+      STRIP_ANY_LOCATION_WRAPPER (format_tree);
+    }
   if (offset < 0)
     {
       res->number_non_literal++;
@@ -1650,6 +1656,7 @@  check_format_arg (void *ctx, tree format_tree,
 	 const char a[3] = "foo";).  */
       array_size = DECL_SIZE_UNIT (format_tree);
       format_tree = array_init;
+      STRIP_ANY_LOCATION_WRAPPER (format_tree);
     }
   if (TREE_CODE (format_tree) != STRING_CST)
     {