[Openmp-commits] [openmp] [OpenMP][NFC] Fix -Wsign-compare warning in kmp_collapse.cpp (PR #137487)
Wang Qiang via Openmp-commits
openmp-commits at lists.llvm.org
Sat Apr 26 19:57:09 PDT 2025
https://github.com/ReVe1uv created https://github.com/llvm/llvm-project/pull/137487
Fix a signed/unsigned comparison warning in `kmp_collapse.cpp`.
`inner_ub0_u64` is of type `kmp_uint64`, but was being compared against `-1`, a signed integer literal, triggering a `-Wsign-compare` warning.
This patch explicitly casts `-1` to `(kmp_uint64)-1` to avoid the warning and ensure correct comparison behavior.
```
llvm-project/openmp/runtime/src/kmp_collapse.cpp:1317:44: warning: comparison of integer expressions of different signedness: ‘kmp_uint64’ {aka ‘long long unsigned int’} and ‘int’ [-Wsign-compare]
1317 | (inner_ub0_u64 == 0 || inner_ub0_u64 == -1) && inner_ub1_u64 == 1) {
```
>From 6b159cc46dabadbabe6930a39f41fea0553e2efc Mon Sep 17 00:00:00 2001
From: Wang Qiang <wangqiang1 at kylinos.cn>
Date: Sun, 27 Apr 2025 10:40:07 +0800
Subject: [PATCH] [OpenMP][NFC] Fix -Wsign-compare warning in kmp_collapse.cpp
Fix a signed/unsigned comparison warning in `kmp_collapse.cpp`.
`inner_ub0_u64` is of type `kmp_uint64`, but was being compared against `-1`,
a signed integer literal, triggering a `-Wsign-compare` warning.
This patch explicitly casts `-1` to `(kmp_uint64)-1` to avoid the warning
and ensure correct comparison behavior.
---
openmp/runtime/src/kmp_collapse.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/openmp/runtime/src/kmp_collapse.cpp b/openmp/runtime/src/kmp_collapse.cpp
index f1bf04901dc7b..ed4b521d96876 100644
--- a/openmp/runtime/src/kmp_collapse.cpp
+++ b/openmp/runtime/src/kmp_collapse.cpp
@@ -1314,7 +1314,7 @@ kmp_identify_nested_loop_structure(/*in*/ bounds_info_t *original_bounds_nest,
original_bounds_nest[1].ub1_u64);
// lower triangle loop inner bounds need to be {0,0}:{0/-1,1}
if (inner_lb0_u64 == 0 && inner_lb1_u64 == 0 &&
- (inner_ub0_u64 == 0 || inner_ub0_u64 == -1) && inner_ub1_u64 == 1) {
+ (inner_ub0_u64 == 0 || inner_ub0_u64 == (kmp_uint64)-1) && inner_ub1_u64 == 1) {
return nested_loop_type_lower_triangular_matrix;
}
// upper triangle loop inner bounds need to be {0,1}:{N,0}
More information about the Openmp-commits
mailing list