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

UNINIT_VAR emits code in non-debug builds

Details

    • Bug
    • Status: Closed (View Workflow)
    • Minor
    • Resolution: Fixed
    • 5.5.37, 10.0.11, 10.1.0
    • 10.1.1
    • None
    • None

    Description

      Leaving variables uninitialized in certain cases helps to achieve top-notch performance. Sometimes compiler thinks that variable may be used uninitialized (whereas it may not) and emits a warning.

      To silence these warnings there is UNINIT_VAR() macro:

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

      There are a few problems with this macro:
      1. It always emits "x= 0" for non-gcc
      2. It always emits "x= 0" for C++ code

      It means leaving variable uninitialized makes sense only in C code compiled by gcc.

      Regarding __cplusplus: there is a reference to gcc bug which was fixed 3 years ago. Probably it is time to remove it?

      Attachments

        Issue Links

          Activity

            svoj Sergey Vojtovich created issue -
            serg Sergei Golubchik made changes -
            Field Original Value New Value
            Fix Version/s 10.1.0 [ 12200 ]
            serg Sergei Golubchik made changes -
            Assignee Sergey Vojtovich [ svoj ]
            serg Sergei Golubchik made changes -
            Workflow defaullt [ 42200 ] MariaDB v2 [ 44277 ]

            Sergei, please review fix for this bug.

            Though I doubt it is a good idea to "Always enable -Wall for gnu C/C++" bypassing cmake maintainer mode (specifically FORCE_INIT_OF_VARS).
            Now we get more warnings from LINT_INIT(). And there is also LINT_INIT_STRUCT() which didn't work before.

            svoj Sergey Vojtovich added a comment - Sergei, please review fix for this bug. Though I doubt it is a good idea to "Always enable -Wall for gnu C/C++" bypassing cmake maintainer mode (specifically FORCE_INIT_OF_VARS). Now we get more warnings from LINT_INIT(). And there is also LINT_INIT_STRUCT() which didn't work before.
            svoj Sergey Vojtovich made changes -
            Assignee Sergey Vojtovich [ svoj ] Sergei Golubchik [ serg ]
            Status Open [ 1 ] In Review [ 10002 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 10.1 [ 16100 ]
            Fix Version/s 10.1.0 [ 12200 ]

            Ok to push.
            let's handle LINT_INIT/etc warnings separately

            serg Sergei Golubchik added a comment - Ok to push. let's handle LINT_INIT/etc warnings separately
            serg Sergei Golubchik made changes -
            Assignee Sergei Golubchik [ serg ] Sergey Vojtovich [ svoj ]
            Status In Review [ 10002 ] Stalled [ 10000 ]

            Fixed in 10.1.1:

            commit bb11eb82d5dce664e151519577df173acb31ee91
            Author: Sergey Vojtovich <svoj@mariadb.org>
            Date:   Tue Aug 26 14:57:09 2014 +0400
             
                MDEV-6305 - UNINIT_VAR emits code in non-debug builds
             
                Reverted workaround for gcc bug, which was fixed 3 years ago:
                http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34772

            svoj Sergey Vojtovich added a comment - Fixed in 10.1.1: commit bb11eb82d5dce664e151519577df173acb31ee91 Author: Sergey Vojtovich <svoj@mariadb.org> Date: Tue Aug 26 14:57:09 2014 +0400   MDEV-6305 - UNINIT_VAR emits code in non-debug builds   Reverted workaround for gcc bug, which was fixed 3 years ago: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34772
            svoj Sergey Vojtovich made changes -
            Fix Version/s 10.1.1 [ 16801 ]
            Fix Version/s 10.1 [ 16100 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            svoj Sergey Vojtovich made changes -
            ratzpo Rasmus Johansson (Inactive) made changes -
            Workflow MariaDB v2 [ 44277 ] MariaDB v3 [ 62164 ]
            serg Sergei Golubchik made changes -
            Workflow MariaDB v3 [ 62164 ] MariaDB v4 [ 147934 ]

            People

              svoj Sergey Vojtovich
              svoj Sergey Vojtovich
              Votes:
              0 Vote for this issue
              Watchers:
              2 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.