public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Martin Uecker <uecker@tugraz.at>
Cc: "Joseph S. Myers" <joseph@codesourcery.com>,
	Marek Polacek <polacek@redhat.com>,
	Jason Merrill <jason@redhat.com>,
	Richard Biener <rguenther@suse.de>,
	gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c: Split -Wcalloc-transposed-args warning from -Walloc-size, -Walloc-size fixes
Date: Tue, 19 Dec 2023 09:47:06 +0100	[thread overview]
Message-ID: <ZYFYiltexdf6gU4m@tucnak> (raw)
In-Reply-To: <b26d9cd28e955749683e11ee2003ff8a845dadf3.camel@tugraz.at>

On Tue, Dec 19, 2023 at 08:11:11AM +0100, Martin Uecker wrote:
> Am Montag, dem 18.12.2023 um 20:14 +0100 schrieb Jakub Jelinek:
> > Hi!
> > 
> > The following patch changes -Walloc-size warning to no longer warn
> > about int *p = calloc (1, sizeof (int));, because as discussed earlier,
> > the size is IMNSHO sufficient in that case, for alloc_size with 2
> > arguments warns if the product of the 2 arguments is insufficiently small.
> > 
> > Also, it warns also for explicit casts of malloc/calloc etc. calls
> > rather than just implicit, so not just
> >   int *p = malloc (1);
> > but also
> >   int *p = (int *) malloc (1);
> > 
> > It also fixes some ICEs where the code didn't verify the alloc_size
> > arguments properly (Walloc-size-5.c testcase ICEs with vanilla trunk).
> > 
> > And lastly, it introduces a coding style warning, -Wcalloc-transposed-args
> > to warn for calloc (sizeof (struct S), 1) and similar calls (regardless
> > of what they are cast to, warning whenever first argument is sizeof and
> > the second is not).
> 
> I would generally see function arguments that are swapped relative
> to the documented ABI as more than a coding style issue even in 
> cases where it can be expected to make no difference.

If you have suggestions how to reword the documentation, would that be
sufficient for you?  I still don't see why given correct alignment one can't
store struct S into sizeof (struct S) sized heap char array, but if the
documentation explain reasons why should one write it one way and not the
other except for coding style, sure.

> > Ok for trunk if this passes bootstrap/regtest?
> 
> I wonder whether we could turn on -Walloc-size for -Wall with this change?

I think that is a possibility, yes.

BTW, the patch passed bootstrap/regtest on x86_64-linux and i686-linux.

	Jakub


  reply	other threads:[~2023-12-19  8:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-18 19:14 Jakub Jelinek
2023-12-19  7:11 ` Martin Uecker
2023-12-19  8:47   ` Jakub Jelinek [this message]
2023-12-19 10:34     ` Martin Uecker
2023-12-19 17:20     ` Jason Merrill
2023-12-19 17:45       ` Martin Uecker
2023-12-19 19:32 ` Joseph Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZYFYiltexdf6gU4m@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=polacek@redhat.com \
    --cc=rguenther@suse.de \
    --cc=uecker@tugraz.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).