From 0c3389f8f57788368c8af94eb4ca38bf28722057 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 16 Aug 2018 10:33:39 -0400 Subject: [PATCH 17/18] FIXME: gimple-ssa-sprintf.c: WIP experiment for labels etc --- gcc/gimple-ssa-sprintf.c | 54 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c index 90f028d..3fe950f 100644 --- a/gcc/gimple-ssa-sprintf.c +++ b/gcc/gimple-ssa-sprintf.c @@ -78,6 +78,7 @@ along with GCC; see the file COPYING3. If not see #include "input.h" #include "toplev.h" #include "substring-locations.h" +#include "gcc-rich-location.h" #include "diagnostic.h" #include "domwalk.h" #include "alloc-pool.h" @@ -476,12 +477,15 @@ fmtwarn (const substring_loc &fmt_loc, location_t param_loc, } static bool -ATTRIBUTE_GCC_DIAG (6, 8) ATTRIBUTE_GCC_DIAG (7, 8) -fmtwarn_n (const substring_loc &fmt_loc, location_t param_loc, +ATTRIBUTE_GCC_DIAG (8, 10) ATTRIBUTE_GCC_DIAG (9, 10) +fmtwarn_n (const substring_loc &fmt_loc, + const range_label *fmt_label, + location_t param_loc, + const range_label *param_label, const char *corrected_substring, int opt, unsigned HOST_WIDE_INT n, const char *singular_gmsgid, const char *plural_gmsgid, ...) { - format_string_diagnostic_t diag (fmt_loc, NULL, param_loc, NULL, + format_string_diagnostic_t diag (fmt_loc, fmt_label, param_loc, param_label, corrected_substring); va_list ap; va_start (ap, plural_gmsgid); @@ -2429,6 +2433,27 @@ should_warn_p (const sprintf_dom_walker::call_info &info, return true; } +/* FIXME. */ + +class buffer_range_label : public range_label +{ + public: + buffer_range_label (const result_range &range) + : m_range (range) + {} + + label_text get_text (unsigned) const FINAL OVERRIDE + { + pretty_printer pp; + // FIXME: various possibilities here: + pp_printf (&pp, "%wi", m_range.min); + return label_text (xstrdup (pp_formatted_text (&pp)), true); + } + + private: + const result_range &m_range; +}; + /* At format string location describe by DIRLOC in a call described by INFO, issue a warning for a directive DIR whose output may be in excess of the available space AVAIL_RANGE in the destination @@ -2502,23 +2527,29 @@ maybe_warn (substring_loc &dirloc, location_t argloc, if (res.min == res.max) { + // FIXME: should label the destination + text_range_label fmt_label ("FIXME: fmt_label"); + buffer_range_label param_label (res); const char *d = target_to_host (hostdir, sizeof hostdir, dir.beg); if (!info.bounded) - return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min, + return fmtwarn_n (dirloc, &fmt_label, argloc, ¶m_label, + NULL, info.warnopt (), res.min, "%<%.*s%> directive writing %wu byte into a " "region of size %wu", "%<%.*s%> directive writing %wu bytes into a " "region of size %wu", (int) dir.len, d, res.min, navail); else if (maybe) - return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min, + return fmtwarn_n (dirloc, &fmt_label, argloc, ¶m_label, + NULL, info.warnopt (), res.min, "%<%.*s%> directive output may be truncated " "writing %wu byte into a region of size %wu", "%<%.*s%> directive output may be truncated " "writing %wu bytes into a region of size %wu", (int) dir.len, d, res.min, navail); else - return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min, + return fmtwarn_n (dirloc, &fmt_label, argloc, ¶m_label, + NULL, info.warnopt (), res.min, "%<%.*s%> directive output truncated writing " "%wu byte into a region of size %wu", "%<%.*s%> directive output truncated writing " @@ -2621,16 +2652,20 @@ maybe_warn (substring_loc &dirloc, location_t argloc, if (res.min == res.max) { + text_range_label fmt_label ("FIXME: fmt_label"); + text_range_label param_label ("FIXME: param_label"); const char *d = target_to_host (hostdir, sizeof hostdir, dir.beg); if (!info.bounded) - return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min, + return fmtwarn_n (dirloc, &fmt_label, argloc, ¶m_label, + NULL, info.warnopt (), res.min, "%<%.*s%> directive writing %wu byte into a region " "of size between %wu and %wu", "%<%.*s%> directive writing %wu bytes into a region " "of size between %wu and %wu", (int) dir.len, d, res.min, avail_range.min, avail_range.max); else if (maybe) - return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min, + return fmtwarn_n (dirloc, &fmt_label, argloc, ¶m_label, + NULL, info.warnopt (), res.min, "%<%.*s%> directive output may be truncated writing " "%wu byte into a region of size between %wu and %wu", "%<%.*s%> directive output may be truncated writing " @@ -2638,7 +2673,8 @@ maybe_warn (substring_loc &dirloc, location_t argloc, "%wu", (int) dir.len, d, res.min, avail_range.min, avail_range.max); else - return fmtwarn_n (dirloc, argloc, NULL, info.warnopt (), res.min, + return fmtwarn_n (dirloc, &fmt_label, argloc, ¶m_label, + NULL, info.warnopt (), res.min, "%<%.*s%> directive output truncated writing %wu " "byte into a region of size between %wu and %wu", "%<%.*s%> directive output truncated writing %wu " -- 1.8.5.3