public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111240] New: Incorrect warning from -Wmaybe-uninitialized
@ 2023-08-30 15:16 bruce at momjian dot us
  2023-08-30 15:25 ` [Bug tree-optimization/111240] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: bruce at momjian dot us @ 2023-08-30 15:16 UTC (permalink / raw)
  To: gcc-bugs

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);

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-03-07 23:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-30 15:16 [Bug c/111240] New: Incorrect warning from -Wmaybe-uninitialized bruce at momjian dot us
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

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).