Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge compiler warning fixes from jdk17u-dev #96

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion make/modules/java.desktop/lib/Awt2dLibraries.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ else

HARFBUZZ_DISABLED_WARNINGS_gcc := type-limits missing-field-initializers strict-aliasing
HARFBUZZ_DISABLED_WARNINGS_CXX_gcc := reorder delete-non-virtual-dtor strict-overflow \
maybe-uninitialized class-memaccess unused-result extra
maybe-uninitialized class-memaccess unused-result extra use-after-free
HARFBUZZ_DISABLED_WARNINGS_clang := unused-value incompatible-pointer-types \
tautological-constant-out-of-range-compare int-to-pointer-cast \
undef missing-field-initializers range-loop-analysis \
Expand Down
8 changes: 2 additions & 6 deletions src/hotspot/share/classfile/verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void ErrorContext::stackmap_details(outputStream* ss, const Method* method) cons

ClassVerifier::ClassVerifier(JavaThread* current, InstanceKlass* klass)
: _thread(current), _previous_symbol(NULL), _symbols(NULL), _exception_type(NULL),
_message(NULL), _method_signatures_table(NULL), _klass(klass) {
_message(NULL), _klass(klass) {
_this_type = VerificationType::reference_type(klass->name());
}

Expand Down Expand Up @@ -625,16 +625,12 @@ void ClassVerifier::verify_class(TRAPS) {
// Either verifying both local and remote classes or just remote classes.
assert(BytecodeVerificationRemote, "Should not be here");

// Create hash table containing method signatures.
method_signatures_table_type method_signatures_table;
set_method_signatures_table(&method_signatures_table);

Array<Method*>* methods = _klass->methods();
int num_methods = methods->length();

for (int index = 0; index < num_methods; index++) {
// Check for recursive re-verification before each method.
if (was_recursively_verified()) return;
if (was_recursively_verified()) return;

Method* m = methods->at(index);
if (m->is_native() || m->is_abstract() || m->is_overpass()) {
Expand Down
10 changes: 3 additions & 7 deletions src/hotspot/share/classfile/verifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ class ClassVerifier : public StackObj {
Symbol* _exception_type;
char* _message;

method_signatures_table_type* _method_signatures_table;
method_signatures_table_type _method_signatures_table;

ErrorContext _error_context; // contains information about an error

Expand Down Expand Up @@ -438,12 +438,8 @@ class ClassVerifier : public StackObj {

Klass* load_class(Symbol* name, TRAPS);

method_signatures_table_type* method_signatures_table() const {
return _method_signatures_table;
}

void set_method_signatures_table(method_signatures_table_type* method_signatures_table) {
_method_signatures_table = method_signatures_table;
method_signatures_table_type* method_signatures_table() {
return &_method_signatures_table;
}

int change_sig_to_verificationType(
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/z/zReferenceProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static const char* reference_type_name(ReferenceType type) {

default:
ShouldNotReachHere();
return NULL;
return "Unknown";
}
}

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

template <typename T>
Expand Down
24 changes: 17 additions & 7 deletions src/hotspot/share/oops/array.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -91,30 +91,40 @@ class Array: public MetaspaceObj {
Array(int length, T init) : _length(length) {
assert(length >= 0, "illegal length");
for (int i = 0; i < length; i++) {
_data[i] = init;
data()[i] = init;
}
}

public:

// standard operations
int length() const { return _length; }
T* data() { return _data; }

T* data() {
return reinterpret_cast<T*>(
reinterpret_cast<char*>(this) + base_offset_in_bytes());
}

const T* data() const {
return reinterpret_cast<const T*>(
reinterpret_cast<const char*>(this) + base_offset_in_bytes());
}

bool is_empty() const { return length() == 0; }

int index_of(const T& x) const {
int i = length();
while (i-- > 0 && _data[i] != x) ;
while (i-- > 0 && data()[i] != x) ;

return i;
}

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

T at(int i) const { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return _data[i]; }
void at_put(const int i, const T& x) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); _data[i] = x; }
T* adr_at(const int i) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return &_data[i]; }
T at(int i) const { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return data()[i]; }
void at_put(const int i, const T& x) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); data()[i] = x; }
T* adr_at(const int i) { assert(i >= 0 && i< _length, "oob: 0 <= %d < %d", i, _length); return &data()[i]; }
int find(const T& x) { return index_of(x); }

T at_acquire(const int i) { return Atomic::load_acquire(adr_at(i)); }
Expand Down
8 changes: 6 additions & 2 deletions src/hotspot/share/utilities/globalDefinitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,14 @@ inline bool is_floating_point_type(BasicType t) {
extern char type2char_tab[T_CONFLICT+1]; // Map a BasicType to a jchar
inline char type2char(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2char_tab[t] : 0; }
extern int type2size[T_CONFLICT+1]; // Map BasicType to result stack elements
extern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a jchar
inline const char* type2name(BasicType t) { return (uint)t < T_CONFLICT+1 ? type2name_tab[t] : NULL; }
extern const char* type2name_tab[T_CONFLICT+1]; // Map a BasicType to a char*
extern BasicType name2type(const char* name);

inline const char* type2name(BasicType t) {
assert((uint)t < T_CONFLICT + 1, "invalid type");
return type2name_tab[t];
}

inline jlong max_signed_integer(BasicType bt) {
if (bt == T_INT) {
return max_jint;
Expand Down
7 changes: 5 additions & 2 deletions src/java.base/share/native/libjli/java.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -51,6 +51,8 @@
*/


#include <assert.h>

#include "java.h"
#include "jni.h"

Expand Down Expand Up @@ -1708,7 +1710,8 @@ TranslateApplicationArgs(int jargc, const char **jargv, int *pargc, char ***parg
for (i = 0; i < jargc; i++) {
const char *arg = jargv[i];
if (arg[0] == '-' && arg[1] == 'J') {
*nargv++ = ((arg + 2) == NULL) ? NULL : JLI_StringDup(arg + 2);
assert(arg[2] != '\0' && "Invalid JAVA_ARGS or EXTRA_JAVA_ARGS defined by build");
*nargv++ = JLI_StringDup(arg + 2);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/java.base/share/native/libjli/parse_manifest.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -288,8 +288,8 @@ find_positions(int fd, Byte *eb, jlong* base_offset, jlong* censtart)
for (cp = &buffer[bytes - ENDHDR]; cp >= &buffer[0]; cp--)
if (ENDSIG_AT(cp) && (cp + ENDHDR + ENDCOM(cp) == endpos)) {
(void) memcpy(eb, cp, ENDHDR);
free(buffer);
pos = flen - (endpos - cp);
free(buffer);
return find_positions64(fd, eb, pos, base_offset, censtart);
}
free(buffer);
Expand Down
11 changes: 7 additions & 4 deletions src/java.base/unix/native/libjli/java_md_common.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -119,10 +119,13 @@ ProgramExists(char *name)
static char *
Resolve(char *indir, char *cmd)
{
char name[PATH_MAX + 2], *real;
char name[PATH_MAX + 1], *real;
int snprintf_result;

if ((JLI_StrLen(indir) + JLI_StrLen(cmd) + 1) > PATH_MAX) return 0;
JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd);
snprintf_result = JLI_Snprintf(name, sizeof(name), "%s%c%s", indir, FILE_SEPARATOR, cmd);
if ((snprintf_result < 0) || (snprintf_result >= (int)sizeof(name))) {
return NULL;
}
if (!ProgramExists(name)) return 0;
real = JLI_MemAlloc(PATH_MAX + 2);
if (!realpath(name, real))
Expand Down
7 changes: 5 additions & 2 deletions src/jdk.jpackage/linux/native/applauncher/LinuxPackage.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand All @@ -25,6 +25,7 @@

#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <errno.h>
#include <linux/limits.h>
Expand Down Expand Up @@ -123,6 +124,7 @@ static int popenCommand(const char* cmdlineFormat, const char* arg,
int callbackMode = POPEN_CALLBACK_USE;
int exitCode = -1;
int c;
ptrdiff_t char_offset;

cmdline = malloc(cmdlineLenth + 1 /* \0 */);
if (!cmdline) {
Expand Down Expand Up @@ -171,13 +173,14 @@ static int popenCommand(const char* cmdlineFormat, const char* arg,
if (strBufNextChar == strBufEnd) {
/* Double buffer size */
strBufCapacity = strBufCapacity * 2 + 1;
char_offset = strBufNextChar - strBufBegin;
strNewBufBegin = realloc(strBufBegin, strBufCapacity);
if (!strNewBufBegin) {
JP_LOG_ERRNO;
goto cleanup;
}

strBufNextChar = strNewBufBegin + (strBufNextChar - strBufBegin);
strBufNextChar = strNewBufBegin + char_offset;
strBufEnd = strNewBufBegin + strBufCapacity;
strBufBegin = strNewBufBegin;
}
Expand Down