From 3a7ff371a2724b0d24d8fb804a1691e5241f311a Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Wed, 8 Nov 2017 14:37:15 -0500 Subject: [PATCH 21/25] {[13/14], NEEDS REVIEW} v3: c-format.c: handle location wrappers gcc/c-family/ChangeLog: * c-format.c (check_format_arg): Convert VAR_P check to a fold_for_warn. gcc/testsuite/ChangeLog: * g++.dg/warn/Wformat-1.C: Add tests of pointer arithmetic on format strings. --- gcc/c-family/c-format.c | 10 ++++------ gcc/testsuite/g++.dg/warn/Wformat-1.C | 2 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index 164d035..1fcac2f 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -1536,12 +1536,10 @@ check_format_arg (void *ctx, tree format_tree, location_t fmt_param_loc = EXPR_LOC_OR_LOC (format_tree, input_location); - if (VAR_P (format_tree)) - { - /* Pull out a constant value if the front end didn't. */ - format_tree = decl_constant_value (format_tree); - STRIP_NOPS (format_tree); - } + /* Pull out a constant value if the front end didn't, and handle location + wrappers. */ + format_tree = fold_for_warn (format_tree); + STRIP_NOPS (format_tree); if (integer_zerop (format_tree)) { diff --git a/gcc/testsuite/g++.dg/warn/Wformat-1.C b/gcc/testsuite/g++.dg/warn/Wformat-1.C index 6094a9c..f2e772a 100644 --- a/gcc/testsuite/g++.dg/warn/Wformat-1.C +++ b/gcc/testsuite/g++.dg/warn/Wformat-1.C @@ -7,4 +7,6 @@ foo (void) { const char *const msg = "abc"; bar (1, msg); + bar (1, msg + 1); + bar (1, 1 + msg); } -- 1.8.5.3