Skip to content

Fix Clang unroll warning in LEB128 helpers - #13

Merged
huangminghuang merged 3 commits into
masterfrom
fix/compiler-warnings
Jun 18, 2026
Merged

Fix Clang unroll warning in LEB128 helpers#13
huangminghuang merged 3 commits into
masterfrom
fix/compiler-warnings

Conversation

@huangminghuang

@huangminghuang huangminghuang commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Change Description

Replace Clang's forced #pragma unroll (full unroll) hint on the LEB128 helper loops with #pragma clang loop unroll_count(5). These loops can terminate early based on encoded byte contents, so a forced full unroll request has no fallback and Clang emits -Wpass-failed=transform-warning when it can't comply (seen in downstream Release builds, reproduced locally with Homebrew llvm@18 at -O2/-O3 -Wall).

unroll_count(5) requests a partial unroll by a fixed factor instead. Unlike a forced full unroll, it has a runtime-remainder-loop fallback, so it succeeds without warning — while still giving Clang an unroll hint (previously these loops would have had no hint at all under one earlier version of this fix). This also makes the Clang hint symmetric with GCC's existing #pragma GCC unroll 5, which was already count-based rather than forcing a full unroll.

#ifdef __clang__ / #elif defined(__GNUC__) guard style kept consistent with the rest of the file.

API Changes

  • API Changes

No API changes.

Documentation Additions

  • Documentation Additions

No documentation additions required.

Testing

  • cmake -S . -B build/release -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake -DVCPKG_OVERLAY_TRIPLETS=build/vcpkg-triplets -DVCPKG_TARGET_TRIPLET=arm64-osx-release -DENABLE_TESTS=ON -DENABLE_SPEC_TESTS=ON -DENABLE_CCACHE=ON
  • cmake --build build/release -j — clean build, no leb128.hpp warnings
  • ctest -j --output-on-failure — 5151/5151 tests passed
  • Verified directly with Homebrew llvm@18 (clang++ -std=c++17 -O2/-O3 -Wall) on the real header: -Wpass-failed=transform-warning reproduced with bare #pragma unroll, gone with #pragma clang loop unroll_count(5)

@huangminghuang
huangminghuang requested a review from heifner June 18, 2026 18:47
huangminghuang and others added 2 commits June 18, 2026 14:07
Bare #pragma unroll forces a full unroll, which fails on these
break-bounded loops and triggers -Wpass-failed=transform-warning.
unroll_count(5) requests a partial unroll with a runtime remainder
fallback, avoiding the warning while keeping an unroll hint for
Clang (symmetric with GCC's #pragma GCC unroll 5).

Verified with Homebrew llvm@18 (-O2/-O3 -Wall): warning gone.
Full release build and ctest (5151/5151) pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@huangminghuang
huangminghuang merged commit 1589ff7 into master Jun 18, 2026
2 checks passed
@huangminghuang
huangminghuang deleted the fix/compiler-warnings branch June 19, 2026 18:16
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.

2 participants