Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8300113

C2: Single-bit fields with signed type in TypePtr after JDK-8297933

XMLWordPrintable

    • b06

      JDK-8297933 added new fields to `TypePtr`:

      ```
          int _hash_computed:1;
          int _exact_klass_computed:1;
          int _is_loaded_computed:1;
      ```

      SonarCloud reports a warning for them:
        Single-bit named bit fields should not be of a signed type cpp:S2216

      With 1 bit field, there is only a place for sign, not the value. Storing "1" into that field might effectively converts it to "-1" on the compilers I have tried. These fields are currently used as "booleans" by boolean-converting non-zeros to true, so there is no bug yet for those compilers. But, I can see how a compiler can convert "1" to "0", only effectively storing the sign bit, introducing subtle bugs.

            shade Aleksey Shipilev
            shade Aleksey Shipilev
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: