substring_loc fmt_loc (fmt_string_loc, string_type, char_idx, char_idx,
char_idx);
- bool warned = format_warning_va (fmt_loc, NULL, NULL, opt, gmsgid, &ap);
+ bool warned = format_warning_va (fmt_loc, UNKNOWN_LOCATION, NULL, opt,
+ gmsgid, &ap);
va_end (ap);
return warned;
char conversion_char,
vec<location_t> *arglocs);
static void format_type_warning (const substring_loc &fmt_loc,
- source_range *param_range,
+ location_t param_loc,
format_wanted_type *, tree,
tree,
const format_kind_info *fki,
cur_param = types->param;
if (!cur_param)
{
- format_type_warning (fmt_loc, NULL, types, wanted_type, NULL, fki,
- offset_to_type_start, conversion_char);
+ format_type_warning (fmt_loc, UNKNOWN_LOCATION, types, wanted_type,
+ NULL, fki, offset_to_type_start,
+ conversion_char);
continue;
}
orig_cur_type = cur_type;
char_type_flag = 0;
- source_range param_range;
- source_range *param_range_ptr;
+ location_t param_loc = UNKNOWN_LOCATION;
if (EXPR_HAS_LOCATION (cur_param))
- {
- param_range = EXPR_LOCATION_RANGE (cur_param);
- param_range_ptr = ¶m_range;
- }
+ param_loc = EXPR_LOCATION (cur_param);
else if (arglocs)
{
/* arg_num is 1-based. */
gcc_assert (types->arg_num > 0);
- location_t param_loc = (*arglocs)[types->arg_num - 1];
- param_range = get_range_from_loc (line_table, param_loc);
- param_range_ptr = ¶m_range;
+ param_loc = (*arglocs)[types->arg_num - 1];
}
- else
- param_range_ptr = NULL;
STRIP_NOPS (cur_param);
}
else
{
- format_type_warning (fmt_loc, param_range_ptr,
+ format_type_warning (fmt_loc, param_loc,
types, wanted_type, orig_cur_type, fki,
offset_to_type_start, conversion_char);
break;
&& TYPE_PRECISION (cur_type) == TYPE_PRECISION (wanted_type))
continue;
/* Now we have a type mismatch. */
- format_type_warning (fmt_loc, param_range_ptr, types,
+ format_type_warning (fmt_loc, param_loc, types,
wanted_type, orig_cur_type, fki,
offset_to_type_start, conversion_char);
}
/* Give a warning about a format argument of different type from that expected.
The range of the diagnostic is taken from WHOLE_FMT_LOC; the caret location
is based on the location of the char at TYPE->offset_loc.
- If non-NULL, PARAM_RANGE is the source range of the
- relevant argument. WANTED_TYPE is the type the argument should have,
+ PARAM_LOC is the location of the relevant argument, or UNKNOWN_LOCATION
+ if this is unavailable.
+ WANTED_TYPE is the type the argument should have,
possibly stripped of pointer dereferences. The description (such as "field
precision"), the placement in the format string, a possibly more
friendly name of WANTED_TYPE, and the number of pointer dereferences
V~~~~~~~~ : range of WHOLE_FMT_LOC, from cols 23-31
sprintf (d, "before %-+*.*lld after", int_expr, int_expr, long_expr);
^ ^ ^~~~~~~~~
- | ` CONVERSION_CHAR: 'd' *PARAM_RANGE
+ | ` CONVERSION_CHAR: 'd' PARAM_LOC
type starts here
OFFSET_TO_TYPE_START is 13, the offset to the "lld" within the
static void
format_type_warning (const substring_loc &whole_fmt_loc,
- source_range *param_range,
+ location_t param_loc,
format_wanted_type *type,
tree wanted_type, tree arg_type,
const format_kind_info *fki,
{
if (arg_type)
format_warning_at_substring
- (fmt_loc, param_range,
+ (fmt_loc, param_loc,
corrected_substring, OPT_Wformat_,
"%s %<%s%.*s%> expects argument of type %<%s%s%>, "
"but argument %d has type %qT",
wanted_type_name, p, arg_num, arg_type);
else
format_warning_at_substring
- (fmt_loc, param_range,
+ (fmt_loc, param_loc,
corrected_substring, OPT_Wformat_,
"%s %<%s%.*s%> expects a matching %<%s%s%> argument",
gettext (kind_descriptions[kind]),
{
if (arg_type)
format_warning_at_substring
- (fmt_loc, param_range,
+ (fmt_loc, param_loc,
corrected_substring, OPT_Wformat_,
"%s %<%s%.*s%> expects argument of type %<%T%s%>, "
"but argument %d has type %qT",
wanted_type, p, arg_num, arg_type);
else
format_warning_at_substring
- (fmt_loc, param_range,
+ (fmt_loc, param_loc,
corrected_substring, OPT_Wformat_,
"%s %<%s%.*s%> expects a matching %<%T%s%> argument",
gettext (kind_descriptions[kind]),
/* For convenience and brevity. */
static bool
- (* const fmtwarn) (const substring_loc &, const source_range *,
+ (* const fmtwarn) (const substring_loc &, location_t,
const char *, int, const char *, ...)
= format_warning_at_substring;
Return true if a warning has been issued. */
static bool
-maybe_warn (substring_loc &dirloc, source_range *pargrange,
+maybe_warn (substring_loc &dirloc, location_t argloc,
const pass_sprintf_length::call_info &info,
const result_range &avail_range, const result_range &res,
const directive &dir)
: G_("%qE writing a terminating nul past the end "
"of the destination")));
- return fmtwarn (dirloc, NULL, NULL, info.warnopt (), fmtstr,
- info.func);
+ return fmtwarn (dirloc, UNKNOWN_LOCATION, NULL, info.warnopt (),
+ fmtstr, info.func);
}
if (res.min == res.max)
"%wu bytes into a region of size %wu"))
: G_("%<%.*s%> directive writing %wu bytes "
"into a region of size %wu")));
- return fmtwarn (dirloc, pargrange, NULL,
+ return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.min, navail);
"up to %wu bytes into a region of size %wu"))
: G_("%<%.*s%> directive writing up to %wu bytes "
"into a region of size %wu"));
- return fmtwarn (dirloc, pargrange, NULL,
+ return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.max, navail);
"likely %wu or more bytes into a region of size %wu"))
: G_("%<%.*s%> directive writing likely %wu or more bytes "
"into a region of size %wu"));
- return fmtwarn (dirloc, pargrange, NULL,
+ return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.likely, navail);
"between %wu and %wu bytes into a region of size %wu"))
: G_("%<%.*s%> directive writing between %wu and "
"%wu bytes into a region of size %wu"));
- return fmtwarn (dirloc, pargrange, NULL,
+ return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.min, res.max, navail);
"%wu or more bytes into a region of size %wu"))
: G_("%<%.*s%> directive writing %wu or more bytes "
"into a region of size %wu"));
- return fmtwarn (dirloc, pargrange, NULL,
+ return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.min, navail);
: G_("%qE writing a terminating nul past the end "
"of the destination")));
- return fmtwarn (dirloc, NULL, NULL, info.warnopt (), fmtstr,
+ return fmtwarn (dirloc, UNKNOWN_LOCATION, NULL, info.warnopt (), fmtstr,
info.func);
}
: G_("%<%.*s%> directive writing %wu bytes "
"into a region of size between %wu and %wu")));
- return fmtwarn (dirloc, pargrange, NULL,
+ return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.min, avail_range.min, avail_range.max);
"%wu and %wu"))
: G_("%<%.*s%> directive writing up to %wu bytes "
"into a region of size between %wu and %wu"));
- return fmtwarn (dirloc, pargrange, NULL,
+ return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.max, avail_range.min, avail_range.max);
"%wu and %wu"))
: G_("%<%.*s%> directive writing likely %wu or more bytes "
"into a region of size between %wu and %wu"));
- return fmtwarn (dirloc, pargrange, NULL,
+ return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.likely, avail_range.min, avail_range.max);
"between %wu and %wu"))
: G_("%<%.*s%> directive writing between %wu and "
"%wu bytes into a region of size between %wu and %wu"));
- return fmtwarn (dirloc, pargrange, NULL,
+ return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.min, res.max, avail_range.min, avail_range.max);
"%wu and %wu"))
: G_("%<%.*s%> directive writing %wu or more bytes "
"into a region of size between %wu and %wu"));
- return fmtwarn (dirloc, pargrange, NULL,
+ return fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dir.len,
target_to_host (hostdir, sizeof hostdir, dir.beg),
res.min, avail_range.min, avail_range.max);
substring_loc dirloc (info.fmtloc, TREE_TYPE (info.format),
offset, start, length);
- /* Also create a location range for the argument if possible.
+ /* Also get the location of the argument if possible.
This doesn't work for integer literals or function calls. */
- source_range argrange;
- source_range *pargrange;
- if (dir.arg && CAN_HAVE_LOCATION_P (dir.arg))
- {
- argrange = EXPR_LOCATION_RANGE (dir.arg);
- pargrange = &argrange;
- }
- else
- pargrange = NULL;
+ location_t argloc = UNKNOWN_LOCATION;
+ if (dir.arg)
+ argloc = EXPR_LOCATION (dir.arg);
/* Bail when there is no function to compute the output length,
or when minimum length checking has been disabled. */
if (fmtres.nullp)
{
- fmtwarn (dirloc, pargrange, NULL, info.warnopt (),
+ fmtwarn (dirloc, argloc, NULL, info.warnopt (),
"%<%.*s%> directive argument is null",
dirlen, target_to_host (hostdir, sizeof hostdir, dir.beg));
bool warned = res->warned;
if (!warned)
- warned = maybe_warn (dirloc, pargrange, info, avail_range,
+ warned = maybe_warn (dirloc, argloc, info, avail_range,
fmtres.range, dir);
/* Bump up the total maximum if it isn't too big. */
(like Glibc does under some conditions). */
if (fmtres.range.min == fmtres.range.max)
- warned = fmtwarn (dirloc, pargrange, NULL,
+ warned = fmtwarn (dirloc, argloc, NULL,
info.warnopt (),
"%<%.*s%> directive output of %wu bytes exceeds "
"minimum required size of 4095",
: G_("%<%.*s%> directive output between %wu and %wu "
"bytes exceeds minimum required size of 4095"));
- warned = fmtwarn (dirloc, pargrange, NULL,
+ warned = fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dirlen,
target_to_host (hostdir, sizeof hostdir, dir.beg),
fmtres.range.min, fmtres.range.max);
to exceed INT_MAX bytes. */
if (fmtres.range.min == fmtres.range.max)
- warned = fmtwarn (dirloc, pargrange, NULL, info.warnopt (),
+ warned = fmtwarn (dirloc, argloc, NULL, info.warnopt (),
"%<%.*s%> directive output of %wu bytes causes "
"result to exceed %<INT_MAX%>",
dirlen,
"bytes causes result to exceed %<INT_MAX%>")
: G_ ("%<%.*s%> directive output between %wu and %wu "
"bytes may cause result to exceed %<INT_MAX%>"));
- warned = fmtwarn (dirloc, pargrange, NULL,
+ warned = fmtwarn (dirloc, argloc, NULL,
info.warnopt (), fmtstr, dirlen,
target_to_host (hostdir, sizeof hostdir, dir.beg),
fmtres.range.min, fmtres.range.max);
substring_loc dirloc (info.fmtloc, TREE_TYPE (info.format),
caret, begin, end);
- fmtwarn (dirloc, NULL, NULL,
+ fmtwarn (dirloc, UNKNOWN_LOCATION, NULL,
info.warnopt (), "%<%.*s%> directive width out of range",
dir.len, target_to_host (hostdir, sizeof hostdir, dir.beg));
}
substring_loc dirloc (info.fmtloc, TREE_TYPE (info.format),
caret, begin, end);
- fmtwarn (dirloc, NULL, NULL,
+ fmtwarn (dirloc, UNKNOWN_LOCATION, NULL,
info.warnopt (), "%<%.*s%> directive precision out of range",
dir.len, target_to_host (hostdir, sizeof hostdir, dir.beg));
}