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

Remove some markers that variable is not going to be used uninitalized in clang

    XMLWordPrintable

Details

    • Sprint 7 (07.04.2025), Sprint 8 (21.04.2025), Sprint 9 (05.05.2025)

    Description

      There are a number of compiler defines that marks variables as 'will not be used uninitialized'.
      This is to around issues with compilers that wrongly conclude that a variable will be used uninitialized.
      The macros that makes this possible are LINT_INIT and UNINIT_VAR for example.

      With modern static analysers and the current usage, these are very shallow path to determine the initialisation did happen. They however still do mistakes.

      While we want to have optimal code, we still want to be able to catch uninitialised values usage in the code.

      The UNINIT_VAR(x) x= x construct was causing UBSAN issues like:

      sql/sql_view.cc:1299:8: runtime error: load of value 16, which is not a valid value for type 'bool'
      

      However vallgrind and other memory checkers does not have this issue.
      When compling with UBSAN we should use the -DWITH_UBSAN option, like we do in the BUILD scripts.

      The fix for this would be to change:

      #if defined(__GNUC__)
      /* GCC specific self-initialization which inhibits the warning. */
      #define UNINIT_VAR(x) x= x
      #elif defined(_lint) || defined(FORCE_INIT_OF_VARS)
      #define UNINIT_VAR(x) x= 0
      #else
      #define UNINIT_VAR(x) x
      #endif
       
      to
       
      #if defined(__GNUC__) && !defined(WITH_UBSAN)
      /* GCC specific self-initialization which inhibits the warning. */
      #define UNINIT_VAR(x) x= x
      #elif defined(FORCE_INIT_OF_VARS)
      #define UNINIT_VAR(x) x= 0
      #else
      #define UNINIT_VAR(x) x
      #endif
      

      (I removed _lint as this is not used anymore)

      Attachments

        Issue Links

          Activity

            People

              danblack Daniel Black
              danblack Daniel Black
              Votes:
              2 Vote for this issue
              Watchers:
              5 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.