KeDeng has uploaded this change for review. ( 
http://gerrit.cloudera.org:8080/23055


Change subject: [util] eliminate compiler warnings in RLE encoding debug checks
......................................................................

[util] eliminate compiler warnings in RLE encoding debug checks

This patch resolves two categories of compiler warnings in RLE encoding
that were discovered during Rocky Linux compilation and also exist in CentOS:

1. Boolean comparison warnings (-Wbool-compare):
   For T=bool and BIT_WIDTH=1, the debug check "value < (1LL << BIT_WIDTH)"
   (which evaluates to "value < 2") is always true for boolean values (0 or 1),
   triggering warnings like:
`
/data/code/kudu/src/kudu/util/rle-encoding.h:388:37:
warning: comparison of constant '2' with boolean expression is always true
[-Wbool-compare]
DCHECK(value < (1LL << BIT_WIDTH));
~~~~~^~~~~~~~~~~~~~~~~~~~
`
2. Shift overflow warnings (-Wshift-count-overflow):
For BIT_WIDTH=64, the expression (1LL << 64) causes undefined behavior
by shifting beyond long long's bit width, triggering warnings like:
`
/data/code/kudu/src/kudu/util/rle-encoding.h:388:44:
warning: left shift count >= width of type [-Wshift-count-overflow]
DCHECK(value < (1LL << BIT_WIDTH));
~~~~^~~~~~~~~~~~~
`

Implemented solution:
- Added template specialization for validation:
* For boolean types: Strictly validates values are 0 or 1
* For other types: Maintains original range check while avoiding
 unsafe 64-bit shifts
- Created helper template struct ValueCheck with:
* Boolean specialization: Uses DCHECK(value == 0 || value == 1)
* Non-boolean specialization: Uses DCHECK(value < (1LL << BW))
 with guard for BW < 64
- Preserved all original safety checks while eliminating warnings

The changes:
- Completely separate code paths for boolean/non-boolean types
- Prevent generation of problematic comparisons for booleans
- Avoid undefined shift behavior for 64-bit widths
- Maintain identical safety guarantees

Change-Id: I230fb92acb18aeda29766f2f131beac9eca8dab9
---
M src/kudu/util/rle-encoding.h
1 file changed, 25 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.cloudera.org:29418/kudu refs/changes/55/23055/1
--
To view, visit http://gerrit.cloudera.org:8080/23055
To unsubscribe, visit http://gerrit.cloudera.org:8080/settings

Gerrit-Project: kudu
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I230fb92acb18aeda29766f2f131beac9eca8dab9
Gerrit-Change-Number: 23055
Gerrit-PatchSet: 1
Gerrit-Owner: KeDeng <[email protected]>

Reply via email to