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

Augment DBUG_ASSERT with __builtin_assume

    XMLWordPrintable

Details

    Description

      An assertion is basically a test of an invariant, that should be true during the program run. Having it false makes a program run into an undefined behavior. This is also true for an optimized, code, where the assertion is not checked, but it has no benefit of this invariant.

      Let's add this benefit by instrumenting DBUG_ASSERT with a platform-dependent c++23 analog of [[assume(cond)]].

      For optimized builds, it'll bring an extra freedom for a compiler in the code optimization., for example it can reorganize while-do loops into do-while, if it knows that the loop will run at least once.

      For debug builds, it'll help data flow analysis tools, like clang-tidy, to make correct assumptions.

      Additionally, it will resolve a problem with all-around IF_DBUG use for avoiding unused variable warnings in release builds.

      Attachments

        Activity

          People

            nikitamalyavin Nikita Malyavin
            nikitamalyavin Nikita Malyavin
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

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