From: Jason Merrill Date: Wed, 21 Jan 2015 20:15:27 +0000 (-0500) Subject: re PR c++/64629 (-Wformat-security warns with const char *const vars) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6875457f349eebb3d13d780e909b131bfff87e16;p=gcc.git re PR c++/64629 (-Wformat-security warns with const char *const vars) PR c++/64629 * c-format.c (check_format_arg): Call decl_constant_value. From-SVN: r219964 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index df56b310992..3b9a3d4b5cb 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2015-01-21 Jason Merrill + + PR c++/64629 + * c-format.c (check_format_arg): Call decl_constant_value. + 2015-01-19 Martin Liska * c-common.c (handle_noicf_attribute): New function. diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c index e47c190ce53..faaca093070 100644 --- a/gcc/c-family/c-format.c +++ b/gcc/c-family/c-format.c @@ -1443,6 +1443,13 @@ check_format_arg (void *ctx, tree format_tree, tree array_init; alloc_pool fwt_pool; + if (TREE_CODE (format_tree) == VAR_DECL) + { + /* Pull out a constant value if the front end didn't. */ + format_tree = decl_constant_value (format_tree); + STRIP_NOPS (format_tree); + } + if (integer_zerop (format_tree)) { /* Skip to first argument to check, so we can see if this format diff --git a/gcc/testsuite/g++.dg/warn/Wformat-1.C b/gcc/testsuite/g++.dg/warn/Wformat-1.C new file mode 100644 index 00000000000..6094a9ca36b --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/Wformat-1.C @@ -0,0 +1,10 @@ +// PR c++/64629 +// { dg-options "-Wformat -Wformat-security" } + +extern void bar (int, const char *, ...) __attribute__((format (printf, 2, 3))); +void +foo (void) +{ + const char *const msg = "abc"; + bar (1, msg); +}