[clang] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of different types (PR #228700)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-aarch64-sve-vla-2stage` running on `linaro-g3-01` while building `clang` at step 19 "test-suite". Full details are available at: https://lab.llvm.org/buildbot/#/builders/41/builds/13280 Here is the relevant piece of the build log for the reference ``` Step 19 (test-suite) failure: test (failure) TEST 'test-suite :: Fortran/gfortran/regression/gomp/gfortran-regression-compile-regression__gomp__task-detach-1_f90.test' FAILED /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/tools/timeit-target --timeout 7200 --limit-core 0 --limit-cpu 7200 --limit-file-size 209715200 --limit-rss-size 838860800 --redirect-input /dev/null --summary /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/Output/gfortran-regression-compile-regression__gomp__task-detach-1_f90.test.time /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/../..//dummy /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/tools/not /usr/bin/diff /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/../..//gfortran-compile-empty.reference.out /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/gfortran-regression-compile-regression__gomp__task-detach-1_f90.out + /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/tools/not /usr/bin/diff /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/../..//gfortran-compile-empty.reference.out /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/gfortran-regression-compile-regression__gomp__task-detach-1_f90.out ``` https://github.com/llvm/llvm-project/pull/228700 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of different types (PR #228700)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-aarch64-sve-vla-2stage` running on `linaro-g3-01` while building `clang` at step 19 "test-suite". Full details are available at: https://lab.llvm.org/buildbot/#/builders/41/builds/13280 Here is the relevant piece of the build log for the reference ``` Step 19 (test-suite) failure: test (failure) TEST 'test-suite :: Fortran/gfortran/regression/gomp/gfortran-regression-compile-regression__gomp__task-detach-1_f90.test' FAILED /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/tools/timeit-target --timeout 7200 --limit-core 0 --limit-cpu 7200 --limit-file-size 209715200 --limit-rss-size 838860800 --redirect-input /dev/null --summary /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/Output/gfortran-regression-compile-regression__gomp__task-detach-1_f90.test.time /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/../..//dummy /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/tools/not /usr/bin/diff /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/../..//gfortran-compile-empty.reference.out /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/gfortran-regression-compile-regression__gomp__task-detach-1_f90.out + /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/tools/not /usr/bin/diff /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/../..//gfortran-compile-empty.reference.out /home/tcwg-buildbot/worker/clang-aarch64-sve-vla-2stage/test/sandbox/build/Fortran/gfortran/regression/gomp/gfortran-regression-compile-regression__gomp__task-detach-1_f90.out ``` https://github.com/llvm/llvm-project/pull/228700 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of different types (PR #228700)
llvm-ci wrote:
LLVM Buildbot has detected a new failure on builder `sanitizer-aarch64-linux`
running on `sanitizer-buildbot7` while building `clang` at step 2 "annotate".
Full details are available at:
https://lab.llvm.org/buildbot/#/builders/51/builds/45124
Here is the relevant piece of the build log for the reference
```
Step 2 (annotate) failure: 'python
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
(failure)
...
[204/208] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.aarch64-with-call.o
[205/208] Generating Msan-aarch64-with-call-Test
[206/208] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.aarch64.o
[207/208] Generating Msan-aarch64-Test
[207/208] Running compiler_rt regression tests
llvm-lit:
/home/b/sanitizer-aarch64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:273:
warning: input
'/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/interception/Unit'
contained no tests
llvm-lit:
/home/b/sanitizer-aarch64-linux/build/llvm-project/llvm/utils/lit/lit/discovery.py:273:
warning: input
'/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/sanitizer_common/Unit'
contained no tests
{'host=None', 'glibc-2.33', 'zlib', 'aarch64-target-arch', 'Clang',
'glibc-2.34', 'target=aarch64-unknown-linux-gnu', 'gwp_asan', 'glibc-2.30',
'glibc-2.19', 'libunwind-available', 'glibc-2.38', 'system-linux',
'aarch64-linux', 'host-byteorder-little-endian', 'glibc-2.27',
'host-arch-compatible', 'asserts', 'shadow-scale-3', 'compiler-rt-optimized',
'linux', 'target-aarch64', 'page-size-4096', 'lld-available', 'shared_unwind',
'glibc', 'memprof-shadow-scale-3', 'non-root-user', 'target-is-aarch64',
'has_sancovcc', 'aarch64-sme-available', 'cxxabi', 'shared_cxxabi',
'can-symbolize', 'symlinks', 'host-jit-triple=aarch64-unknown-linux-gnu',
'glibc-2.37', 'glibc-2.40'}
-- Testing: 6573 tests, 72 workers --
Testing: 0.. 10.. 20.. 30.. 40.. 50.. 60..
FAIL: LeakSanitizer-HWAddressSanitizer-aarch64 ::
TestCases/create_thread_leak.cpp (4667 of 6573)
TEST 'LeakSanitizer-HWAddressSanitizer-aarch64 ::
TestCases/create_thread_leak.cpp' FAILED
Exit Code: 2
Command Output (stdout):
--
# RUN: at line 3
/home/b/sanitizer-aarch64-linux/build/build_default/./bin/clang
--driver-mode=g++ -O0 -Wthread-safety -Wthread-safety-reference
-Wthread-safety-beta -gline-tables-only -fsanitize=hwaddress -fuse-ld=lld
-I/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lsan/../
-pthread
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lsan/TestCases/create_thread_leak.cpp
-o
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/lsan/AARCH64HWAsanConfig/TestCases/Output/create_thread_leak.cpp.tmp
# executed command:
/home/b/sanitizer-aarch64-linux/build/build_default/./bin/clang
--driver-mode=g++ -O0 -Wthread-safety -Wthread-safety-reference
-Wthread-safety-beta -gline-tables-only -fsanitize=hwaddress -fuse-ld=lld
-I/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lsan/../
-pthread
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lsan/TestCases/create_thread_leak.cpp
-o
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/lsan/AARCH64HWAsanConfig/TestCases/Output/create_thread_leak.cpp.tmp
# note: command had no output on stdout or stderr
# RUN: at line 4
not
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/lsan/AARCH64HWAsanConfig/TestCases/Output/create_thread_leak.cpp.tmp
10 1 0 0 2>&1 | FileCheck
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lsan/TestCases/create_thread_leak.cpp
--check-prefixes=LEAK,LEAK123
# executed command: not
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/lsan/AARCH64HWAsanConfig/TestCases/Output/create_thread_leak.cpp.tmp
10 1 0 0
# note: command had no output on stdout or stderr
# executed command: FileCheck
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lsan/TestCases/create_thread_leak.cpp
--check-prefixes=LEAK,LEAK123
# note: command had no output on stdout or stderr
# RUN: at line 5
not
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/lsan/AARCH64HWAsanConfig/TestCases/Output/create_thread_leak.cpp.tmp
10 0 1 0 2>&1 | FileCheck
/home/b/sanitizer-aarch64-linux/build/llvm-project/compiler-rt/test/lsan/TestCases/create_thread_leak.cpp
--check-prefixes=LEAK,LEAK234
# executed command: not
/home/b/sanitizer-aarch64-linux/build/build_default/runtimes/runtimes-bins/compiler-rt/test/lsan/AARCH64HWAsanConfig/TestCases/Output/create_thread_leak.cpp.tmp
10 0 1 0
# note: command had no output on stdout or stderr
# executed command: FileCheck
[clang] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of different types (PR #228700)
https://github.com/akash-manna-sky closed https://github.com/llvm/llvm-project/pull/228700 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of different types (PR #228700)
https://github.com/akash-manna-sky auto_merge_enabled https://github.com/llvm/llvm-project/pull/228700 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of different types (PR #228700)
https://github.com/akash-manna-sky updated
https://github.com/llvm/llvm-project/pull/228700
>From e1b54881c1640311f76c97bfa4013a8f091e2052 Mon Sep 17 00:00:00 2001
From: Akash Manna
Date: Sat, 3 Oct 2026 17:26:16 +0530
Subject: [PATCH] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of
different types
When a simd directive has both clauses, Sema checks that simdlen is not
greater than safelen. The values were compared with APSInt's operator>,
which requires operands of the same bit width and signedness, but each
clause keeps its argument in the type it was written with. A pair such
as safelen(111) simdlen(1) asserted, and a build without
assertions rejected it as if simdlen were the larger value.
Compare the values with APSInt::compareValues instead, which handles
operands of different widths and signedness.
Fixes #108367
---
clang/docs/ReleaseNotes.md | 2 ++
clang/lib/Sema/SemaOpenMP.cpp | 2 +-
clang/test/OpenMP/simd_misc_messages.c | 32 ++
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 6afaa6675be7cd..7538f3e1825fc7 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1071,6 +1071,8 @@ The `alpha.cplusplus.UseAfterLifetimeEnd` checker was
renamed to `alpha.core.Use
- Mapping of expressions with base-pointers through a user-defined mapper (e.g.
`map(s.p[0:n])`) now conforms to OpenMP's conditional pointer-attachment,
matching the behavior of such maps outside a mapper.
+- Fixed a crash when the `safelen` and `simdlen` clauses of an OpenMP directive
+ have arguments of different integer types. (#GH108367)
- The `holds` clause on the `assume` directive now lowers side-effect-free
conditions to `llvm.assume`, enabling downstream optimizations. Previously
the clause was parsed but its condition was discarded without effect.
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6ef86b8391f40c..315f869e0b72e7 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -11371,7 +11371,7 @@ static bool checkSimdlenSafelenSpecified(Sema &S,
// If both simdlen and safelen clauses are specified, the value of the
// simdlen parameter must be less than or equal to the value of the safelen
// parameter.
-if (SimdlenRes > SafelenRes) {
+if (llvm::APSInt::compareValues(SimdlenRes, SafelenRes) > 0) {
S.Diag(SimdlenLength->getExprLoc(),
diag::err_omp_wrong_simdlen_safelen_values)
<< SimdlenLength->getSourceRange() <<
SafelenLength->getSourceRange();
diff --git a/clang/test/OpenMP/simd_misc_messages.c
b/clang/test/OpenMP/simd_misc_messages.c
index 818bd9056edbc3..c3e2bcbe2ccde5 100644
--- a/clang/test/OpenMP/simd_misc_messages.c
+++ b/clang/test/OpenMP/simd_misc_messages.c
@@ -274,6 +274,38 @@ void test_safelen_simdlen(void) {
#pragma omp simd safelen(5) simdlen(6)
for (i = 0; i < 16; ++i)
;
+#pragma omp simd safelen(8) simdlen(4)
+ for (i = 0; i < 16; ++i)
+;
+// expected-error@+1 {{the value of 'simdlen' parameter must be less than or
equal to the value of the 'safelen' parameter}}
+#pragma omp simd safelen(4) simdlen(8)
+ for (i = 0; i < 16; ++i)
+;
+}
+
+// GH108367
+void test_safelen_simdlen_types(void) {
+#pragma omp simd safelen(111) simdlen(1)
+ for (int i = 0; i < 10; i++)
+;
+// expected-error@+1 {{the value of 'simdlen' parameter must be less than or
equal to the value of the 'safelen' parameter}}
+#pragma omp simd simdlen(111) safelen(1)
+ for (int i = 0; i < 10; i++)
+;
+// expected-error@+1 {{the value of 'simdlen' parameter must be less than or
equal to the value of the 'safelen' parameter}}
+#pragma omp simd safelen(111) simdlen(222)
+ for (int i = 0; i < 10; i++)
+;
+#pragma omp simd safelen(222) simdlen(111)
+ for (int i = 0; i < 10; i++)
+;
+#pragma omp simd safelen(8u) simdlen(4)
+ for (int i = 0; i < 10; i++)
+;
+// expected-error@+1 {{the value of 'simdlen' parameter must be less than or
equal to the value of the 'safelen' parameter}}
+#pragma omp simd safelen(4u) simdlen(8)
+ for (int i = 0; i < 10; i++)
+;
}
void test_collapse(void) {
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of different types (PR #228700)
https://github.com/alexey-bataev approved this pull request. https://github.com/llvm/llvm-project/pull/228700 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of different types (PR #228700)
https://github.com/akash-manna-sky ready_for_review https://github.com/llvm/llvm-project/pull/228700 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of different types (PR #228700)
llvmorg-github-actions[bot] wrote:
@llvm/pr-subscribers-clang
Author: Akash Manna (akash-manna-sky)
Changes
Fixes #108367
When a `simd` directive has both `safelen` and `simdlen`, Sema checks that
`simdlen` is not greater than `safelen`. It compared the two values with
`APSInt`'s `operator>`, which needs both operands to have the same bit width
and signedness. But each clause keeps its argument in the type it was written
with, so in `safelen(111) simdlen(1)` one value is 64 bits wide and the
other 32, and the comparison asserted. Mixed signedness, as in `safelen(8u)
simdlen(4)`, hit a second assertion on the same line. A build without
assertions rejected the valid code instead, as if `simdlen` were the larger
value.
The check now uses `APSInt::compareValues`, which extends the operands to a
common width and handles mixed signedness, so the values themselves are
compared. The error is still emitted whenever `simdlen` is larger than
`safelen`.
---
Full diff: https://github.com/llvm/llvm-project/pull/228700.diff
3 Files Affected:
- (modified) clang/docs/ReleaseNotes.md (+2)
- (modified) clang/lib/Sema/SemaOpenMP.cpp (+1-1)
- (modified) clang/test/OpenMP/simd_misc_messages.c (+32)
``diff
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 6afaa6675be7c..7538f3e1825fc 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1071,6 +1071,8 @@ The `alpha.cplusplus.UseAfterLifetimeEnd` checker was
renamed to `alpha.core.Use
- Mapping of expressions with base-pointers through a user-defined mapper (e.g.
`map(s.p[0:n])`) now conforms to OpenMP's conditional pointer-attachment,
matching the behavior of such maps outside a mapper.
+- Fixed a crash when the `safelen` and `simdlen` clauses of an OpenMP directive
+ have arguments of different integer types. (#GH108367)
- The `holds` clause on the `assume` directive now lowers side-effect-free
conditions to `llvm.assume`, enabling downstream optimizations. Previously
the clause was parsed but its condition was discarded without effect.
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6ef86b8391f40..315f869e0b72e 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -11371,7 +11371,7 @@ static bool checkSimdlenSafelenSpecified(Sema &S,
// If both simdlen and safelen clauses are specified, the value of the
// simdlen parameter must be less than or equal to the value of the safelen
// parameter.
-if (SimdlenRes > SafelenRes) {
+if (llvm::APSInt::compareValues(SimdlenRes, SafelenRes) > 0) {
S.Diag(SimdlenLength->getExprLoc(),
diag::err_omp_wrong_simdlen_safelen_values)
<< SimdlenLength->getSourceRange() <<
SafelenLength->getSourceRange();
diff --git a/clang/test/OpenMP/simd_misc_messages.c
b/clang/test/OpenMP/simd_misc_messages.c
index 818bd9056edbc..c3e2bcbe2ccde 100644
--- a/clang/test/OpenMP/simd_misc_messages.c
+++ b/clang/test/OpenMP/simd_misc_messages.c
@@ -274,6 +274,38 @@ void test_safelen_simdlen(void) {
#pragma omp simd safelen(5) simdlen(6)
for (i = 0; i < 16; ++i)
;
+#pragma omp simd safelen(8) simdlen(4)
+ for (i = 0; i < 16; ++i)
+;
+// expected-error@+1 {{the value of 'simdlen' parameter must be less than or
equal to the value of the 'safelen' parameter}}
+#pragma omp simd safelen(4) simdlen(8)
+ for (i = 0; i < 16; ++i)
+;
+}
+
+// GH108367
+void test_safelen_simdlen_types(void) {
+#pragma omp simd safelen(111) simdlen(1)
+ for (int i = 0; i < 10; i++)
+;
+// expected-error@+1 {{the value of 'simdlen' parameter must be less than or
equal to the value of the 'safelen' parameter}}
+#pragma omp simd simdlen(111) safelen(1)
+ for (int i = 0; i < 10; i++)
+;
+// expected-error@+1 {{the value of 'simdlen' parameter must be less than or
equal to the value of the 'safelen' parameter}}
+#pragma omp simd safelen(111) simdlen(222)
+ for (int i = 0; i < 10; i++)
+;
+#pragma omp simd safelen(222) simdlen(111)
+ for (int i = 0; i < 10; i++)
+;
+#pragma omp simd safelen(8u) simdlen(4)
+ for (int i = 0; i < 10; i++)
+;
+// expected-error@+1 {{the value of 'simdlen' parameter must be less than or
equal to the value of the 'safelen' parameter}}
+#pragma omp simd safelen(4u) simdlen(8)
+ for (int i = 0; i < 10; i++)
+;
}
void test_collapse(void) {
``
https://github.com/llvm/llvm-project/pull/228700
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of different types (PR #228700)
https://github.com/akash-manna-sky created
https://github.com/llvm/llvm-project/pull/228700
Fixes #108367
When a `simd` directive has both `safelen` and `simdlen`, Sema checks that
`simdlen` is not greater than `safelen`. It compared the two values with
`APSInt`'s `operator>`, which needs both operands to have the same bit width
and signedness. But each clause keeps its argument in the type it was written
with, so in `safelen(111) simdlen(1)` one value is 64 bits wide and the
other 32, and the comparison asserted. Mixed signedness, as in `safelen(8u)
simdlen(4)`, hit a second assertion on the same line. A build without
assertions rejected the valid code instead, as if `simdlen` were the larger
value.
The check now uses `APSInt::compareValues`, which extends the operands to a
common width and handles mixed signedness, so the values themselves are
compared. The error is still emitted whenever `simdlen` is larger than
`safelen`.
>From e1b54881c1640311f76c97bfa4013a8f091e2052 Mon Sep 17 00:00:00 2001
From: Akash Manna
Date: Sat, 3 Oct 2026 17:26:16 +0530
Subject: [PATCH] [Clang][OpenMP] Fix crash on `safelen` and `simdlen` of
different types
When a simd directive has both clauses, Sema checks that simdlen is not
greater than safelen. The values were compared with APSInt's operator>,
which requires operands of the same bit width and signedness, but each
clause keeps its argument in the type it was written with. A pair such
as safelen(111) simdlen(1) asserted, and a build without
assertions rejected it as if simdlen were the larger value.
Compare the values with APSInt::compareValues instead, which handles
operands of different widths and signedness.
Fixes #108367
---
clang/docs/ReleaseNotes.md | 2 ++
clang/lib/Sema/SemaOpenMP.cpp | 2 +-
clang/test/OpenMP/simd_misc_messages.c | 32 ++
3 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 6afaa6675be7cd..7538f3e1825fc7 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -1071,6 +1071,8 @@ The `alpha.cplusplus.UseAfterLifetimeEnd` checker was
renamed to `alpha.core.Use
- Mapping of expressions with base-pointers through a user-defined mapper (e.g.
`map(s.p[0:n])`) now conforms to OpenMP's conditional pointer-attachment,
matching the behavior of such maps outside a mapper.
+- Fixed a crash when the `safelen` and `simdlen` clauses of an OpenMP directive
+ have arguments of different integer types. (#GH108367)
- The `holds` clause on the `assume` directive now lowers side-effect-free
conditions to `llvm.assume`, enabling downstream optimizations. Previously
the clause was parsed but its condition was discarded without effect.
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 6ef86b8391f40c..315f869e0b72e7 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -11371,7 +11371,7 @@ static bool checkSimdlenSafelenSpecified(Sema &S,
// If both simdlen and safelen clauses are specified, the value of the
// simdlen parameter must be less than or equal to the value of the safelen
// parameter.
-if (SimdlenRes > SafelenRes) {
+if (llvm::APSInt::compareValues(SimdlenRes, SafelenRes) > 0) {
S.Diag(SimdlenLength->getExprLoc(),
diag::err_omp_wrong_simdlen_safelen_values)
<< SimdlenLength->getSourceRange() <<
SafelenLength->getSourceRange();
diff --git a/clang/test/OpenMP/simd_misc_messages.c
b/clang/test/OpenMP/simd_misc_messages.c
index 818bd9056edbc3..c3e2bcbe2ccde5 100644
--- a/clang/test/OpenMP/simd_misc_messages.c
+++ b/clang/test/OpenMP/simd_misc_messages.c
@@ -274,6 +274,38 @@ void test_safelen_simdlen(void) {
#pragma omp simd safelen(5) simdlen(6)
for (i = 0; i < 16; ++i)
;
+#pragma omp simd safelen(8) simdlen(4)
+ for (i = 0; i < 16; ++i)
+;
+// expected-error@+1 {{the value of 'simdlen' parameter must be less than or
equal to the value of the 'safelen' parameter}}
+#pragma omp simd safelen(4) simdlen(8)
+ for (i = 0; i < 16; ++i)
+;
+}
+
+// GH108367
+void test_safelen_simdlen_types(void) {
+#pragma omp simd safelen(111) simdlen(1)
+ for (int i = 0; i < 10; i++)
+;
+// expected-error@+1 {{the value of 'simdlen' parameter must be less than or
equal to the value of the 'safelen' parameter}}
+#pragma omp simd simdlen(111) safelen(1)
+ for (int i = 0; i < 10; i++)
+;
+// expected-error@+1 {{the value of 'simdlen' parameter must be less than or
equal to the value of the 'safelen' parameter}}
+#pragma omp simd safelen(111) simdlen(222)
+ for (int i = 0; i < 10; i++)
+;
+#pragma omp simd safelen(222) simdlen(111)
+ for (int i = 0; i < 10; i++)
+;
+#pragma omp simd safelen(8u) simdlen(4)
+ for (int i = 0; i < 10; i++)
+;
+// expected-error@+1 {{the value of 'simdlen'
