Re: Getting bounds information (thus, attributes) within diagnose_mismatched_decls()

Alejandro Colomar via Gcc-help <[email protected]> Thu, 18 Dec 2025 00:56:07 +0100
Newsgroups gmane.comp.gcc.help
Message-ID <peyej7olbcu6ajcqjzomflgatotrpg3kbbhqnajug4v5pgnxp5@jsdlzdpuc7vn>
Hi Martin,

On Sun, Dec 14, 2025 at 07:09:34PM +0100, Martin Uecker wrote:
> > Is there a way to get that information here somehow?
> 
> See init_attr_rdwr_indices in attribs.cc
> 
> 
> So the overall story is this: 
> 
> For arguments declared as arrays we add an (internal)
> "arg spec" attribute (build_arg_spec_attribute) in
> grokdeclarator in c/c-decl.cc.  
> 
> In c-family/c-attribs.cc build_attr_access_from_parms then
> creates an "access" attribute with some string parameter
> that encodes the information.  It is called later from
> finish_decl (c-decl.cc).  Explicit access attributes are
> also transformed into this internal representation
> (handle_access_attribute ...).
> 
> The warning code in c-family/c-warn.cc  and also some
> middle-end warning code uses this information to emit warning.
> For this it uses init_attr_rdwr_indices (attribs.cc)
> to reconstruct a per-parameter access specification 
> (attr_spec) and this gives some information.
> 
> So basically instead of using types properly, we create
> internal attributes, transform them in complicated ways
> to attach them to the function decl, and then recompute per
> parameter information when needed.  
> 
> I fixed various bugs in this code and changed the
> arg spec attribute to simply preserve the original type,

Thanks a lot!

> but I think this needs to be refactored more.

Hmmmm, and certainly someone with more experience in GCC internals
than me.  :)

> > Maybe warn_parm_array_mismatch() could be split into yet another helper
> > which doesn't get the parameter position and the rdwr_map*'s and instead
> > gets the attributes in a form that I can produce within
> > diagnose_mismatched_decls(), to be able to share that code.  (But I'd
> > still need to know how to get a form that can be shared with the other
> > code.)
> 
> My recommendation is to rewrite the FE warning code to not
> rely on init_attr_rdwr_indices at all but make use of the
> types directly (the original type is now in the "arg spec"
> for each parameter). This should be much clearer.  So if you
> add new warnings, I would do this directly in this way.

If you refactor any existing diagnostic to do this, please let me know,
and I'll try to imitate that.  I don't think I can do that myself at the
moment.


Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmlDQxEACgkQ64mZXMKQ
wql5SxAAhgrkM2KDMFpg+3DQ5W+ZsmhU5ufgYbK6Y+hSneJL+Q95bjERZtqEqu3D
+oKfbJBEBWlc0Nv2gMTYeGmM8+/U/3NOXRc4cbpvAFDeNXYrfTuOSzlAdMQM55uJ
7WuLrS/I8/+cHNPJZKK+/qWx3kt+GYQlbWCiAswEXixE+Wk3KQtUzdr3IYjCNUQy
lO8C8oynE+r8pwp5rxf9qdiuvGTN1dwLpInGoj6V/Z4tcxijiKHK/Nd2i2r2CRdx
Mwsgb1uBY9qu8amzfUO4qIsgk0jvGGN9EtwlvA09pT3NvidEaDYatI88Rl480vOz
kQn/RFF+XBz525SXZpmfi6AhvFJfUJizRFPOzWu3PrucKT3rf34/V/5w4+B4d2gW
8BIkVAdodHfWDwAXbAWVJX2nsKrXPMv1rg94KVpAQB6Bdd+iOokPcyQOADJxL3xP
NnLCxWkpX2b/5vaZ57/fHpyg4d2KCtMRPrUu7kMxxqp3QZ/KHcuG+uP6T3Wa1xfG
QbeNT7agkMAuemFyIj2rbl4302kHs0Lg+xvEjfHWVuF/8Bua+wfJpmrQZnlXBu4K
hKr+Mlu6U2AuNE5WMfQ2Z8qGOndQQu+Tj7jIjrPXwocSm7Iy7DG8WP0lbNk1kSo2
YWU5a+3y+Rp7ouQrd/vh77zfag+kZq0qB99F2EBM2+erQ2AZRLc=
=TZLL
-----END PGP SIGNATURE-----