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

core: address error=array-bounds in gcc14 #2639

Merged
merged 3 commits into from
Jan 10, 2025
Merged

core: address error=array-bounds in gcc14 #2639

merged 3 commits into from
Jan 10, 2025

Conversation

yperbasis
Copy link
Member

Address the following error when compling with gcc 14.2:

at /home/andrew/silkworm/silkworm/core/common/small_map.hpp:48:15,
    inlined from ‘static std::optional<silkworm::protocol::bor::Config> silkworm::protocol::bor::Config::from_json(const nlohmann::json_abi_v3_11_3::json&)’ at /home/andrew/silkworm/silkworm/core/protocol/bor/config.cpp:71:50:
/usr/include/c++/14/bits/stl_pair.h:607:48: error: array subscript [15, 576460752303423485] is outside array bounds of ‘const silkworm::SmallMap<long unsigned int, long unsigned int> [1]’ [-Werror=array-bounds=]
  607 |         second = std::forward<second_type>(__p.second);
      |                                            ~~~~^~~~~~
/home/andrew/silkworm/silkworm/core/protocol/bor/config.cpp: In static member function ‘static std::optional<silkworm::protocol::bor::Config> silkworm::protocol::bor::Config::from_json(const nlohmann::json_abi_v3_11_3::json&)’:
/home/andrew/silkworm/silkworm/core/protocol/bor/config.cpp:71:50: note: at offset [240, 9223372036854775760] into object ‘<anonymous>’ of size 136
   71 |     config.period = {period.begin(), period.end()};
      |                                                  ^

Copy link
Member

@chfast chfast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you think this is a false positive warning?

@yperbasis yperbasis marked this pull request as draft January 9, 2025 08:20
@yperbasis yperbasis marked this pull request as ready for review January 9, 2025 08:31
return std::nullopt;
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still needed given the if-check above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this still needed given the if-check above?

The error is still emitted unfortunately even with the check.

Copy link
Contributor

@battlmonstr battlmonstr Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you clarify the error? how does a big number like "576460752303423485" or "9223372036854775760" end up there despite the check? who is passing that number? could it be that if is faulty due to some signed-unsigned UB?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know where this number comes from (it's some internal details of the array-bounds check in gcc). The comparison is fine (both arguments are of type size_t).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This warning comes from optimized GCC builds. After some optimizations related to inlining and constant propagation compiler can convince itself that it knows the access index of an array and compare it with the array size.
Unfortunately, this analysis is known to have false-positives, see e.g.

If we want to be nice and you think it is worth the time I can reduce this example and report an issue. Or I can make a tutorial how to reduce failing compilations.

@yperbasis
Copy link
Member Author

So you think this is a false positive warning?

Yes, I think so

@yperbasis yperbasis enabled auto-merge (squash) January 9, 2025 08:34
@yperbasis yperbasis marked this pull request as draft January 9, 2025 08:46
auto-merge was automatically disabled January 9, 2025 08:46

Pull request was converted to draft

@yperbasis yperbasis marked this pull request as ready for review January 9, 2025 16:35
@yperbasis yperbasis enabled auto-merge (squash) January 9, 2025 16:38
@yperbasis yperbasis merged commit b00be69 into master Jan 10, 2025
5 checks passed
@yperbasis yperbasis deleted the gcc14 branch January 10, 2025 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants