https://github.com/loopacino updated https://github.com/llvm/llvm-project/pull/226462
>From 71e52541e9a4567c6d92cba67245c6aac052cca5 Mon Sep 17 00:00:00 2001 From: amtiwari <[email protected]> Date: Fri, 25 Sep 2026 07:58:10 -0400 Subject: [PATCH 1/2] sign mismatch fix --- clang/lib/Sema/SemaOpenMP.cpp | 15 ++++-------- clang/test/OpenMP/flatten_codegen.cpp | 14 +++++++++++ .../test/transform/flatten/mixed-sign.c | 24 +++++++++++++++++++ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 openmp/runtime/test/transform/flatten/mixed-sign.c diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 3bd68a9ace981..1f858a35090bb 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -17420,21 +17420,16 @@ SemaOpenMP::ActOnOpenMPFlattenDirective(ArrayRef<OMPClause *> Clauses, auto MakeDivisorInIVTy = [&](unsigned I) -> Expr * { Expr *N = MakeNumIterationsInIVTy(I); Expr *NCmp = MakeNumIterationsInIVTy(I); - auto MakeOne = [&]() -> ExprResult { - return SemaRef.PerformImplicitConversion( - SemaRef.ActOnIntegerConstant(CondLoc, 1).get(), IVTy, - AssignmentAction::Converting, /*AllowExplicit=*/true); + auto MakeOne = [&]() -> Expr * { + return IntegerLiteral::Create(Context, llvm::APInt(IVWidth, 1), IVTy, + CondLoc); }; - ExprResult OneCmp = MakeOne(); - ExprResult OneVal = MakeOne(); - if (!OneCmp.isUsable() || !OneVal.isUsable()) - return N; ExprResult TooSmall = - SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, NCmp, OneCmp.get()); + SemaRef.BuildBinOp(CurScope, CondLoc, BO_LT, NCmp, MakeOne()); if (!TooSmall.isUsable()) return N; return AssertSuccess(SemaRef.ActOnConditionalOp( - CondLoc, CondLoc, TooSmall.get(), OneVal.get(), N)); + CondLoc, CondLoc, TooSmall.get(), MakeOne(), N)); }; // \code{.cpp} diff --git a/clang/test/OpenMP/flatten_codegen.cpp b/clang/test/OpenMP/flatten_codegen.cpp index fe2e4350672f3..c470bd962ef47 100644 --- a/clang/test/OpenMP/flatten_codegen.cpp +++ b/clang/test/OpenMP/flatten_codegen.cpp @@ -6,6 +6,8 @@ #ifndef HEADER #define HEADER +#include <stddef.h> + extern "C" void body(int, int); // CHECK-LABEL: define {{.*}}void @foo( @@ -100,4 +102,16 @@ extern "C" void both_neg() { body(i, j); } +// Mixed signed/unsigned trip counts: the flattened IV is unsigned, and the +// signed inner count is converted into that type for max(1, N). +// CHECK-LABEL: define {{.*}}void @mixed_sign( +// CHECK: %.flatten.iv = alloca i64 +// CHECK: icmp ult i64 +extern "C" void mixed_sign(int n) { +#pragma omp flatten depth(2) + for (size_t i = 0; i < (size_t)n; ++i) + for (int j = 0; j < n; ++j) + body((int)i, j); +} + #endif diff --git a/openmp/runtime/test/transform/flatten/mixed-sign.c b/openmp/runtime/test/transform/flatten/mixed-sign.c new file mode 100644 index 0000000000000..c354e332a15dc --- /dev/null +++ b/openmp/runtime/test/transform/flatten/mixed-sign.c @@ -0,0 +1,24 @@ +// RUN: %libomp-compile -fopenmp-version=61 && %libomp-run \ +// RUN: | FileCheck %s --match-full-lines + +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> + +int main(void) { + int n = 2; + printf("do\n"); +#pragma omp flatten depth(2) + for (size_t i = 0; i < (size_t)n; ++i) + for (int j = 0; j < n; ++j) + printf("i=%zu j=%d\n", i, j); + printf("done\n"); + return EXIT_SUCCESS; +} + +// CHECK: do +// CHECK-NEXT: i=0 j=0 +// CHECK-NEXT: i=0 j=1 +// CHECK-NEXT: i=1 j=0 +// CHECK-NEXT: i=1 j=1 +// CHECK-NEXT: done >From 59d5c8a45aef88e5254a784e365826de7cbc8341 Mon Sep 17 00:00:00 2001 From: amtiwari <[email protected]> Date: Sat, 26 Sep 2026 11:00:18 -0400 Subject: [PATCH 2/2] drop std include --- clang/test/OpenMP/flatten_codegen.cpp | 2 +- openmp/runtime/test/transform/flatten/mixed-sign.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/clang/test/OpenMP/flatten_codegen.cpp b/clang/test/OpenMP/flatten_codegen.cpp index c470bd962ef47..7c83c9824303b 100644 --- a/clang/test/OpenMP/flatten_codegen.cpp +++ b/clang/test/OpenMP/flatten_codegen.cpp @@ -6,7 +6,7 @@ #ifndef HEADER #define HEADER -#include <stddef.h> +typedef __SIZE_TYPE__ size_t; extern "C" void body(int, int); diff --git a/openmp/runtime/test/transform/flatten/mixed-sign.c b/openmp/runtime/test/transform/flatten/mixed-sign.c index c354e332a15dc..9295239f4ade5 100644 --- a/openmp/runtime/test/transform/flatten/mixed-sign.c +++ b/openmp/runtime/test/transform/flatten/mixed-sign.c @@ -1,10 +1,11 @@ // RUN: %libomp-compile -fopenmp-version=61 && %libomp-run \ // RUN: | FileCheck %s --match-full-lines -#include <stddef.h> #include <stdio.h> #include <stdlib.h> +typedef __SIZE_TYPE__ size_t; + int main(void) { int n = 2; printf("do\n"); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
