https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91890
--- Comment #7 from Jeffrey A. Law <law at redhat dot com> --- Another tidbit. It looks like the sprintf warning will at times ignore the passed in location. I'm not suggesting this is necessarily the right fix, but if we make gimple-ssa-warn-restrict honor the passed in location per this change, then the pragmas work perfectly in this case. diff --git a/gcc/gimple-ssa-warn-restrict.c b/gcc/gimple-ssa-warn-restrict.c index 2c582a670eb..1449492798a 100644 --- a/gcc/gimple-ssa-warn-restrict.c +++ b/gcc/gimple-ssa-warn-restrict.c @@ -1754,7 +1754,7 @@ maybe_diag_access_bounds (location_t loc, gimple *call, tree func, int strict, || (ref.ref && TREE_NO_WARNING (ref.ref))) return false; - if (EXPR_HAS_LOCATION (ref.ptr)) + if (loc == UNKNOWN_LOCATION && EXPR_HAS_LOCATION (ref.ptr)) loc = EXPR_LOCATION (ref.ptr); loc = expansion_point_location_if_in_system_header (loc); Martin, do you recall the rationale behind extracting the location out of ref.ptr when we were already passed in a location?