Skip to content

Commit 46c1434

Browse files
YaSuenagPaul Hohensee
authored andcommitted
8286562: GCC 12 reports some compiler warnings
Backport-of: 410a25d59a11b6a627bbb0a2c405c2c2be19f464
1 parent 0720b24 commit 46c1434

File tree

5 files changed

+40
-15
lines changed

5 files changed

+40
-15
lines changed

make/modules/java.desktop/lib/Awt2dLibraries.gmk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ else
460460

461461
HARFBUZZ_DISABLED_WARNINGS_gcc := type-limits missing-field-initializers strict-aliasing
462462
HARFBUZZ_DISABLED_WARNINGS_CXX_gcc := reorder delete-non-virtual-dtor strict-overflow \
463-
maybe-uninitialized class-memaccess unused-result extra
463+
maybe-uninitialized class-memaccess unused-result extra use-after-free
464464
HARFBUZZ_DISABLED_WARNINGS_clang := unused-value incompatible-pointer-types \
465465
tautological-constant-out-of-range-compare int-to-pointer-cast \
466466
undef missing-field-initializers range-loop-analysis \

src/hotspot/share/jfr/recorder/checkpoint/types/traceid/jfrTraceIdBits.inline.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -132,7 +132,15 @@ inline void set(jbyte bits, jbyte* dest) {
132132
template <typename T>
133133
inline void JfrTraceIdBits::store(jbyte bits, const T* ptr) {
134134
assert(ptr != NULL, "invariant");
135+
// gcc12 warns "writing 1 byte into a region of size 0" when T == Klass.
136+
// The warning seems to be a false positive. And there is no warning for
137+
// other types that use the same mechanisms. The warning also sometimes
138+
// goes away with minor code perturbations, such as replacing function calls
139+
// with equivalent code directly inlined.
140+
PRAGMA_DIAG_PUSH
141+
PRAGMA_DISABLE_GCC_WARNING("-Wstringop-overflow")
135142
set(bits, traceid_tag_byte(ptr));
143+
PRAGMA_DIAG_POP
136144
}
137145

138146
template <typename T>

src/hotspot/share/oops/array.hpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -91,30 +91,40 @@ class Array: public MetaspaceObj {
9191
Array(int length, T init) : _length(length) {
9292
assert(length >= 0, "illegal length");
9393
for (int i = 0; i < length; i++) {
94-
_data[i] = init;
94+
data()[i] = init;
9595
}
9696
}
9797

9898
public:
9999

100100
// standard operations
101101
int length() const { return _length; }
102-
T* data() { return _data; }
102+
103+
T* data() {
104+
return reinterpret_cast<T*>(
105+
reinterpret_cast<char*>(this) + base_offset_in_bytes());
106+
}
107+
108+
const T* data() const {
109+
return reinterpret_cast<const T*>(
110+
reinterpret_cast<const char*>(this) + base_offset_in_bytes());
111+
}
112+
103113
bool is_empty() const { return length() == 0; }
104114

105115
int index_of(const T& x) const {
106116
int i = length();
107-
while (i-- > 0 && _data[i] != x) ;
117+
while (i-- > 0 && data()[i] != x) ;
108118

109119
return i;
110120
}
111121

112122
// sort the array.
113123
bool contains(const T& x) const { return index_of(x) >= 0; }
114124

115-
T at(int i) const { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return _data[i]; }
116-
void at_put(const int i, const T& x) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); _data[i] = x; }
117-
T* adr_at(const int i) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return &_data[i]; }
125+
T at(int i) const { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return data()[i]; }
126+
void at_put(const int i, const T& x) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); data()[i] = x; }
127+
T* adr_at(const int i) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return &data()[i]; }
118128
int find(const T& x) { return index_of(x); }
119129

120130
T at_acquire(const int i) { return Atomic::load_acquire(adr_at(i)); }

src/hotspot/share/utilities/globalDefinitions.hpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,14 @@ inline bool is_floating_point_type(BasicType t) {
718718
extern char type2char_tab[T_CONFLICT+1]; // Map a BasicType to a jchar
719719
inline char type2char(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2char_tab[t] : 0; }
720720
extern int type2size[T_CONFLICT+1]; // Map BasicType to result stack elements
721-
extern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a jchar
722-
inline const char* type2name(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2name_tab[t] : NULL; }
721+
extern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a char*
723722
extern BasicType name2type(const char* name);
724723

724+
inline const char* type2name(BasicType t) {
725+
assert((uint)t < T_CONFLICT + 1, "invalid type");
726+
return type2name_tab[t];
727+
}
728+
725729
inline jlong max_signed_integer(BasicType bt) {
726730
if (bt == T_INT) {
727731
return max_jint;

src/java.base/unix/native/libjli/java_md_common.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -119,10 +119,13 @@ ProgramExists(char *name)
119119
static char *
120120
Resolve(char *indir, char *cmd)
121121
{
122-
char name[PATH_MAX + 2], *real;
122+
char name[PATH_MAX + 1], *real;
123+
int snprintf_result;
123124

124-
if ((JLI_StrLen(indir) + JLI_StrLen(cmd) + 1) > PATH_MAX) return 0;
125-
JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd);
125+
snprintf_result = JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd);
126+
if ((snprintf_result < 0) || (snprintf_result >= (int)sizeof(name))) {
127+
return NULL;
128+
}
126129
if (!ProgramExists(name)) return 0;
127130
real = JLI_MemAlloc(PATH_MAX + 2);
128131
if (!realpath(name, real))

0 commit comments

Comments
 (0)