Skip to content

Fix BoolKeys test to use integer-to-bool cast - #25862

Closed
saisindhuri91 wants to merge 1 commit into
protocolbuffers:mainfrom
linux-on-ibm-z:v33.4-upb-hash-test-cast-bool
Closed

saisindhuri91 wants to merge 1 commit into
protocolbuffers:mainfrom
linux-on-ibm-z:v33.4-upb-hash-test-cast-bool

Conversation

@saisindhuri91

Copy link
Copy Markdown
Contributor

This PR has been raised to resolve the following test case failure //upb/hash:test occurred in s390x:
Error:

upb/hash/test.cc:349: Failure
Expected equality of these values:
 key_bool
  Which is: false
 true

[ FAILED ] IntTableTest.BoolKeys (0 ms)

Solution:

  • The use of memcpy() copied byte from an integer key into a bool, which fails on big endian systems.
  • Replacing it with an explicit static type cast conversion from integer to bool worked on both little and big endian systems
    key_bool = static_cast<bool>(key);

Comment thread upb/hash/test.cc
// First element.
EXPECT_TRUE(upb_inttable_next(&t, &key, &val, &iter));
bool key_bool;
memcpy(&key_bool, &key, sizeof(key_bool));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe this instead?

bool key_bool = upb_value_getbool(key)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi @esrauchg,
Thank you for reviewing the code..

  • I tried using upb_value_getbool(key), but it gives compilation error error: could not convert 'key' from 'uintptr_t' to 'upb_value'
  • The reason is that upb_value_getbool() expects an argument of type upb_value (which is a struct wrapper used for the values of type uint64_t)
  • And, upb_inttable_next arguments mentions the key explicitly as a raw uintptr_t, not as a upb_value
  • So, we cannot use upb_value_getbool on the key, instead we can cast the uintptr_t directly

@jiridanek

jiridanek commented Jul 20, 2026 •

Copy link
Copy Markdown

Thanks for this fix! The memcpy approach is indeed broken on big-endian — static_cast<bool>(key) is the correct, endian-agnostic way to do this.

Re the reviewer's suggestion to use upb_value_getbool(key): your explanation is right — key is a uintptr_t, not a upb_value, so that won't compile. The cast is the appropriate fix here.

We've been tracking protobuf s390x issues downstream (we pin protobuf in our builds) and even though this is just a test fix, it would be great to see this merged.

@saisindhuri91

Copy link
Copy Markdown
Contributor Author

Hi @esrauchg,
Could you please review the changes in this PR and let us know if any further updates are needed? Thank you...

@esrauchg esrauchg added the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Oct 1, 2026
@github-actions github-actions Bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Oct 1, 2026
@karenwuz

Copy link
Copy Markdown
Member

Hi @saisindhuri91, looks like there are tests failing. Please fix.

@saisindhuri91
saisindhuri91 force-pushed the v33.4-upb-hash-test-cast-bool branch from 02774a2 to 5ce0d04 Compare October 24, 2026 14:38
@saisindhuri91

saisindhuri91 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @saisindhuri91, looks like there are tests failing. Please fix.

Thanks @karenwuz. The earlier CI failures were due to the old commit in the branch. Now I have rebased onto the latest main. The diff is still the same in upb/hash/test.cc

@esrauchg could you please re-add the safe for tests label so CI can run again?

Thank you...

@rgoldfinger6 rgoldfinger6 added 🅰️ safe for tests Mark a commit as safe to run presubmits over and removed wait for user action labels Oct 26, 2026
@github-actions github-actions Bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Oct 26, 2026
@saisindhuri91
saisindhuri91 force-pushed the v33.4-upb-hash-test-cast-bool branch from 5ce0d04 to c3da332 Compare October 27, 2026 10:25
@saisindhuri91
saisindhuri91 force-pushed the v33.4-upb-hash-test-cast-bool branch from c3da332 to c9c5ca9 Compare October 28, 2026 05:53
@rgoldfinger6 rgoldfinger6 added the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Oct 28, 2026
@github-actions github-actions Bot removed the 🅰️ safe for tests Mark a commit as safe to run presubmits over label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants