Skip to content

Commit 4060b35

Browse files
author
Kim Barrett
committed
8335298: Fix -Wzero-as-null-pointer-constant warning in G1CardSetContainers
Reviewed-by: iwalulya, ayang
1 parent 9046d7a commit 4060b35

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/hotspot/share/gc/g1/g1CardSetContainers.hpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2023, 2024, 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
@@ -86,12 +86,22 @@ class G1CardSetInlinePtr : public StackObj {
8686

8787
uint find(uint const card_idx, uint const bits_per_card, uint start_at, uint num_cards);
8888

89+
static ContainerPtr empty_card_set() {
90+
// Work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114573
91+
// gcc issues -Wzero-as-null-pointer-constant here, even though
92+
// ContainerInlinePtr is a *non-literal* constant 0. We cast a non-const
93+
// copy, and let the compiler's constant propagation optimize into
94+
// equivalent code.
95+
static_assert(G1CardSet::ContainerInlinePtr == 0, "unnecessary warning dodge");
96+
auto value = G1CardSet::ContainerInlinePtr;
97+
return reinterpret_cast<ContainerPtr>(value);
98+
}
99+
89100
public:
90-
G1CardSetInlinePtr() : _value_addr(nullptr), _value((ContainerPtr)G1CardSet::ContainerInlinePtr) { }
101+
G1CardSetInlinePtr() : G1CardSetInlinePtr(empty_card_set()) {}
91102

92-
G1CardSetInlinePtr(ContainerPtr value) : _value_addr(nullptr), _value(value) {
93-
assert(G1CardSet::container_type(_value) == G1CardSet::ContainerInlinePtr, "Value " PTR_FORMAT " is not a valid G1CardSetInlinePtr.", p2i(_value));
94-
}
103+
explicit G1CardSetInlinePtr(ContainerPtr value) :
104+
G1CardSetInlinePtr(nullptr, value) {}
95105

96106
G1CardSetInlinePtr(ContainerPtr volatile* value_addr, ContainerPtr value) : _value_addr(value_addr), _value(value) {
97107
assert(G1CardSet::container_type(_value) == G1CardSet::ContainerInlinePtr, "Value " PTR_FORMAT " is not a valid G1CardSetInlinePtr.", p2i(_value));

0 commit comments

Comments
 (0)