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

GCC 12 reports some compiler warnings

XMLWordPrintable

    • b25

        I saw some compiler warnings when I tried to build OpenJDK with GCC 12.0.1 on Fedora 36.

        * -Wstringop-overflow
            * src/hotspot/share/oops/array.hpp
            * src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdBits.inline.hpp
        ```
        In member function 'void Array<T>::at_put(int, const T&) [with T = unsigned char]',
            inlined from 'void ConstantPool::tag_at_put(int, jbyte)' at /home/ysuenaga/github-forked/jdk/src/hotspot/share/oops/constantPool.hpp:126:64,
            inlined from 'void ConstantPool::method_at_put(int, int, int)' at /home/ysuenaga/github-forked/jdk/src/hotspot/share/oops/constantPool.hpp:380:15,
            inlined from 'ConstantPool* BytecodeConstantPool::create_constant_pool(JavaThread*) const' at /home/ysuenaga/github-forked/jdk/src/hotspot/share/classfile/bytecodeAssembler.cpp:85:26:
        /home/ysuenaga/github-forked/jdk/src/hotspot/share/oops/array.hpp:119:114: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
          119 | void at_put(const int i, const T& x) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); _data[i] = x; }
              | ~~~~~~~~~^~~

        In file included from /home/ysuenaga/github-forked/jdk/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdLoadBarrier.inline.hpp:33,
                         from /home/ysuenaga/github-forked/jdk/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp:30,
                         from /home/ysuenaga/github-forked/jdk/src/hotspot/share/jfr/support/jfrJdkJfrEvent.cpp:30:
        In function 'void set_form(jbyte, jbyte*) [with jbyte (* op)(jbyte, jbyte) = traceid_or]',
            inlined from 'void set(jbyte, jbyte*)' at /home/ysuenaga/github-forked/jdk/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdBits.inline.hpp:129:23,
            inlined from 'static void JfrTraceIdBits::store(jbyte, const T*) [with T = Klass]' at /home/ysuenaga/github-forked/jdk/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdBits.inline.hpp:135:6,
            inlined from 'static void JfrTraceId::tag_as_jdk_jfr_event(const Klass*)' at /home/ysuenaga/github-forked/jdk/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceId.inline.hpp:106:3,
            inlined from 'static void JdkJfrEvent::tag_as(const Klass*)' at /home/ysuenaga/github-forked/jdk/src/hotspot/share/jfr/support/jfrJdkJfrEvent.cpp:176:35:
        /home/ysuenaga/github-forked/jdk/src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdBits.inline.hpp:99:9: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
           99 | *dest = op(bits, *dest);
              | ~~~~~~^~~~~~~~~~~~~~~~~
        ```

        * -Wformat-overflow
            * src/hotspot/share/opto/memnode.cpp
        ```
        /home/ysuenaga/github-forked/jdk/src/hotspot/share/opto/memnode.cpp: In member function 'Node* LoadNode::eliminate_autobox(PhaseIterGVN*)':
        /home/ysuenaga/github-forked/jdk/src/hotspot/share/opto/memnode.cpp:1409:53: error: '%s' directive argument is null [-Werror=format-overflow=]
         1409 | bt == T_INT || bt == T_LONG, "wrong type = %s", type2name(bt));
              | ^~~~~~~~~~~~~~~~~
        ```

        * -Wformat-truncation
            * src/java.base/unix/native/libjli/java_md_common.c
        ```
        /home/ysuenaga/github-forked/jdk/src/java.base/unix/native/libjli/java_md_common.c: In function 'Resolve':
        /home/ysuenaga/github-forked/jdk/src/java.base/unix/native/libjli/java_md_common.c:132:43: error: '%s' directive output may be truncated writing up to 4095 bytes into a region of size between 2 and 4097 [-Werror=format-truncation=]
          132 | JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd);
              | ^~
        ```

        * -Waddress
            * src/java.base/share/native/libjli/java.c
        ```
        /home/ysuenaga/github-forked/jdk/src/java.base/share/native/libjli/java.c:1629:35: error: the comparison will always evaluate as 'false' for the pointer operand in 'arg + 2' must not be NULL [-Werror=address]
         1629 | *nargv++ = ((arg + 2) == NULL) ? NULL : JLI_StringDup(arg + 2);
              |
        ```

        * -Wuse-after-free
            * src/java.base/share/native/libjli/parse_manifest.c
            * src/jdk.jpackage/linux/native/applauncher/LinuxPackage.c
            * src/java.desktop/share/native/libharfbuzz/hb-font.cc
        ```
        /home/ysuenaga/github-forked/jdk/src/java.base/share/native/libjli/parse_manifest.c:292:34: error: pointer 'endpos' used after 'free' [-Werror=use-after-free]
          292 | pos = flen - (endpos - cp);
              | ~~~~~~~~^~~~~

        /home/ysuenaga/github-forked/jdk/src/jdk.jpackage/linux/native/applauncher/LinuxPackage.c:180:63: error: pointer 'strBufBegin' may be used after 'realloc' [-Werror=use-after-free]
          180 | strBufNextChar = strNewBufBegin + (strBufNextChar - strBufBegin);
              | ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~

        /home/ysuenaga/github-forked/jdk/src/java.desktop/share/native/libharfbuzz/hb-font.cc:2286:12: error: pointer 'trampoline' used after 'void free(void*)' [-Werror=use-after-free]
         2286 | closure->ref_count++;
              | ~~~~~~~~~^~~~~~~~~
        ```

        Most of warnings can be ignored, however warnings for libjli seem to be bugs.

              ysuenaga Yasumasa Suenaga
              ysuenaga Yasumasa Suenaga
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

                Created:
                Updated:
                Resolved: