Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-27968

GCC 12 -Og -Wmaybe-uninitialized in udf_handler::fix_fields()

    XMLWordPrintable

    Details

      Description

      The following compiler is issuing a warning that I cannot determine whether it is bogus or not:

      gcc-12 (Debian 12-20220222-1) 12.0.1 20220222 (experimental) [master r12-7325-g2f59f067610]
      

      10.2 ed691eca99da36f3c20558edd08786224539a7ab

      /mariadb/10.2o/sql/item_func.cc: In member function ‘bool udf_handler::fix_fields(THD*, Item_func_or_sum*, uint, Item**)’:
      /mariadb/10.2o/sql/item_func.cc:3507:39: error: ‘<anonymous>’ may be used uninitialized [-Werror=maybe-uninitialized]
       3507 |     if (!(buffers=new String[arg_count]) ||
            |                                       ^
      /mariadb/10.2o/sql/item_func.cc:3507:39: note: ‘<anonymous>’ was declared here
       3507 |     if (!(buffers=new String[arg_count]) ||
            |                                       ^
      cc1plus: all warnings being treated as errors
      

      The 10.6 version of the same looks a little different:

      10.6 fd5a6d0f75f1435e6b15409516ccba54b8fee145

      /mariadb/10.6/sql/item_func.cc: In member function ‘bool udf_handler::fix_fields(THD*, Item_func_or_sum*, uint, Item**)’:
      /mariadb/10.6/sql/item_func.cc:3513:55: error: ‘<anonymous>’ may be used uninitialized [-Werror=maybe-uninitialized]
       3513 |     if (!(buffers=new (thd->mem_root) String[arg_count]) ||
            |                                                       ^
      /mariadb/10.6/sql/item_func.cc:3513:55: note: ‘<anonymous>’ was declared here
       3513 |     if (!(buffers=new (thd->mem_root) String[arg_count]) ||
            |                                                       ^
      

      The following patch (below, it is for 10.6) would work around it:

      diff --git a/sql/item_func.cc b/sql/item_func.cc
      index 92f6255d958..c5f14dcd64f 100644
      --- a/sql/item_func.cc
      +++ b/sql/item_func.cc
      @@ -3448,6 +3448,10 @@ void udf_handler::cleanup()
         }
       }
       
      +#if defined __GNUC__ && __GNUC__ == 12
      +#pragma GCC diagnostic push
      +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
      +#endif
       
       bool
       udf_handler::fix_fields(THD *thd, Item_func_or_sum *func,
      @@ -3612,6 +3616,9 @@ udf_handler::fix_fields(THD *thd, Item_func_or_sum *func,
         }
         DBUG_RETURN(FALSE);
       }
      +#if defined __GNUC__ && __GNUC__ == 12
      +#pragma GCC diagnostic pop
      +#endif
       
       
       bool udf_handler::get_arguments()
      

      If I replace the -Og with -O2 or -O3 or omit it altogether, no warning will be issued.
      Here is a slightly truncated compiler invocation that will issue this warning but also some others:

      g++-12 -DHAVE_CONFIG_H -DMYSQL_SERVER -I/mariadb/10.6/wsrep-lib/include -I/mariadb/10.6/wsrep-lib/wsrep-API/v26 -I/dev/shm/10.6/include -I/mariadb/10.6/include -I/mariadb/10.6/sql -Og -Wall -Wno-unused-parameter -std=gnu++11 -MD -MT sql/CMakeFiles/sql.dir/item_func.cc.o -MF sql/CMakeFiles/sql.dir/item_func.cc.o.d -o sql/CMakeFiles/sql.dir/item_func.cc.o -c /mariadb/10.6/sql/item_func.cc
      

        Attachments

          Activity

            People

            Assignee:
            marko Marko Mäkelä
            Reporter:
            marko Marko Mäkelä
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.