onnxruntime
c7c939ff - Fix -Warray-bounds build error in MLAS on clang 17+ (#27499)

Commit
1 day ago
Fix -Warray-bounds build error in MLAS on clang 17+ (#27499) ### Description The `-Warray-bounds` suppression pragma in `sqnbitgemm_kernel_avx2_int8_blklen32.h` was gated on `defined(HAS_ARRAY_BOUNDS)`, which is set in `onnxruntime_config.h`. MLAS never includes that header, so the guard was dead code and the pragma never fired. Changed the guard to `#ifdef __clang__`: ```cpp // Before: HAS_ARRAY_BOUNDS never defined in MLAS TU #if defined(__clang__) && defined(HAS_ARRAY_BOUNDS) // After #ifdef __clang__ ``` Note: `__has_warning("-Warray-bounds")` was considered but the C preprocessor does not short-circuit `&&`, so GCC fails to parse it even behind `defined(__clang__)`. ### Motivation and Context Build fails on Intel Mac with Apple Clang 17.0.0 (`-Werror,-Warray-bounds`). Clang raises a false-positive array-bounds warning on `acc[4..7]` inside an `if constexpr (NCols4 == 8)` branch that is dead when `NCols4 == 4`. <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>[Build] error: array index 4 is past the end of the array (that has type '__m256[4]') [-Werror,-Warray-bounds]</issue_title> > <issue_description>### Describe the issue > > Unable to build from main branch (0768f42400748427f1d2c39880af5aec97c8821a as of time writing this issue) on Intel Mac > > ``` > /usr/bin/c++ --version > Apple clang version 17.0.0 (clang-1700.0.13.5) > Target: x86_64-apple-darwin24.5.0 > Thread model: posix > InstalledDir: /Library/Developer/CommandLineTools/usr/bin > ``` > > > ### Urgency > > _No response_ > > ### Target platform > > MacOS > > ### Build script > > ./build.sh --config RelWithDebInfo --build_shared_lib --parallel --cmake_extra_defines CMAKE_OSX_ARCHITECTURES=x86_64 > > ### Error / output > > [ 18%] Building CXX object CMakeFiles/onnxruntime_mlas.dir/onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_avx2.cpp.o > In file included from /onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_avx2.cpp:26: > /onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_avx2_int8_blklen32.h:1677:49: error: array index 4 is past the end of the array (that has type '__m256[4]') [-Werror,-Warray-bounds] > 1677 | __m128 acc_1 = FoldAccumulators(acc[4], acc[5], acc[6], acc[7]); > | ^ ~ > /onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_avx2_int8_blklen32.h:1531:13: note: array 'acc' declared here > 1531 | __m256 acc[NCols4]; > | ^ > /onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_avx2_int8_blklen32.h:1677:57: error: array index 5 is past the end of the array (that has type '__m256[4]') [-Werror,-Warray-bounds] > 1677 | __m128 acc_1 = FoldAccumulators(acc[4], acc[5], acc[6], acc[7]); > | ^ ~ > /onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_avx2_int8_blklen32.h:1531:13: note: array 'acc' declared here > 1531 | __m256 acc[NCols4]; > | ^ > /onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_avx2_int8_blklen32.h:1677:65: error: array index 6 is past the end of the array (that has type '__m256[4]') [-Werror,-Warray-bounds] > 1677 | __m128 acc_1 = FoldAccumulators(acc[4], acc[5], acc[6], acc[7]); > | ^ ~ > /onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_avx2_int8_blklen32.h:1531:13: note: array 'acc' declared here > 1531 | __m256 acc[NCols4]; > | ^ > /onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_avx2_int8_blklen32.h:1677:73: error: array index 7 is past the end of the array (that has type '__m256[4]') [-Werror,-Warray-bounds] > 1677 | __m128 acc_1 = FoldAccumulators(acc[4], acc[5], acc[6], acc[7]); > | ^ ~ > /onnxruntime/onnxruntime/core/mlas/lib/sqnbitgemm_kernel_avx2_int8_blklen32.h:1531:13: note: array 'acc' declared here > 1531 | __m256 acc[NCols4]; > | ^ > 4 errors generated. > > ### Visual Studio Version > > _No response_ > > ### GCC / Compiler Version > > Apple clang version 17.0.0 (clang-1700.0.13.5)</issue_description> > > <agent_instructions>Please investigate the build error. If code need fix, create a pull requests. Otherwise, suggest ways to avoid the build errors.</agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes microsoft/onnxruntime#27497 <!-- START COPILOT CODING AGENT TIPS --> --- 🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. [Learn more about Advanced Security.](https://gh.io/cca-advanced-security) --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: tianleiwu <30328909+tianleiwu@users.noreply.github.com>
Author
Parents
Loading