public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bruce at momjian dot us" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/111240] New: Incorrect warning from -Wmaybe-uninitialized
Date: Wed, 30 Aug 2023 15:16:15 +0000	[thread overview]
Message-ID: <bug-111240-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111240

            Bug ID: 111240
           Summary: Incorrect warning from -Wmaybe-uninitialized
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bruce at momjian dot us
  Target Milestone: ---

Compiling this file from the PostgreSQL master source tree generates a warning
when I don't think it should.  To reproduce, only -O1 produces the bug, not
-O0/-O2/-O3:

    gcc -Wmaybe-uninitialized -O1 -c clauses.i

Yields:

clauses.c: In function ‘recheck_cast_function_args’:
clauses.c:4293:19: warning: ‘actual_arg_types’ may be used uninitialized
[-Wmaybe-uninitialized]
 4293 |         rettype = enforce_generic_type_consistency(actual_arg_types,
In file included from clauses.c:45:
../../../../src/include/parser/parse_coerce.h:82:17: note: by argument 1 of
type ‘const Oid *’ {aka ‘const unsigned int *’} to
‘enforce_generic_type_consistency’ declared here
   82 | extern Oid      enforce_generic_type_consistency(const Oid
*actual_arg_types,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clauses.c:4279:24: note: ‘actual_arg_types’ declared here
 4279 |         Oid                     actual_arg_types[FUNC_MAX_ARGS];
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is the C code.  nargs prevents uninitialized values from being used when
calling enforce_generic_type_consistency().

-------------------------------------

static void
recheck_cast_function_args(List *args, Oid result_type,
                           Oid *proargtypes, int pronargs,
                           HeapTuple func_tuple)
{
    Form_pg_proc funcform = (Form_pg_proc) GETSTRUCT(func_tuple);
    int         nargs;
    Oid         actual_arg_types[FUNC_MAX_ARGS];
    Oid         declared_arg_types[FUNC_MAX_ARGS];
    Oid         rettype;
    ListCell   *lc;

    if (list_length(args) > FUNC_MAX_ARGS)
        elog(ERROR, "too many function arguments");
    nargs = 0;
    foreach(lc, args)
    {
        actual_arg_types[nargs++] = exprType((Node *) lfirst(lc));
    }
    Assert(nargs == pronargs);
    memcpy(declared_arg_types, proargtypes, pronargs * sizeof(Oid));
    rettype = enforce_generic_type_consistency(actual_arg_types,
                                               declared_arg_types,
                                               nargs,
                                               funcform->prorettype,
                                               false);

             reply	other threads:[~2023-08-30 15:16 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30 15:16 bruce at momjian dot us [this message]
2023-08-30 15:25 ` [Bug tree-optimization/111240] " pinskia at gcc dot gnu.org
2023-08-30 15:27 ` pinskia at gcc dot gnu.org
2023-08-30 15:30 ` bruce at momjian dot us
2023-08-30 15:30 ` bruce at momjian dot us
2023-08-30 15:38 ` pinskia at gcc dot gnu.org
2023-08-31  9:46 ` [Bug tree-optimization/111240] [12/13/14 Regression] " rguenth at gcc dot gnu.org
2024-03-07 23:22 ` law at gcc dot gnu.org

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=bug-111240-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).