================
@@ -17342,10 +17313,37 @@ 
SemaOpenMP::ActOnOpenMPFlattenDirective(ArrayRef<OMPClause *> Clauses,
   }
 
   CaptureVars CopyTransformer(SemaRef);
-  auto MakeNumIterations = [&CopyTransformer,
-                            &LoopHelpers](unsigned I) -> Expr * {
-    return AssertSuccess(
-        CopyTransformer.TransformExpr(LoopHelpers[I].NumIterations));
+  // Convert a non-integer trip count. Width matches buildNumIterations.
+  // Signedness follows an integer loop variable so a float count stays signed.
+  auto MakeNumIterations = [&CopyTransformer, &LoopHelpers, &Context,
+                            &SemaRef =
+                                this->SemaRef](unsigned I) -> ExprResult {
+    ExprResult N = CopyTransformer.TransformExpr(LoopHelpers[I].NumIterations);
+    if (!N.isUsable())
+      return ExprError();
+    QualType Type = N.get()->getType();
+    if (Type->isIntegerType())
+      return N;
+    const auto *Counter = cast<DeclRefExpr>(LoopHelpers[I].Counters.front());
+    QualType VarType = Counter->getType().getNonReferenceType();
+    bool VarIsInt = VarType->hasIntegerRepresentation();
+    bool UseVarWidth =
+        VarIsInt && Context.getTypeSize(Type) > Context.getTypeSize(VarType);
+    unsigned NewSize =
+        UseVarWidth ? Context.getTypeSize(VarType) : Context.getTypeSize(Type);
----------------
alexey-bataev wrote:

```suggestion
    unsigned NewSize = Context.getTypeSize(VarIsInt ? VarType : Type);
```

https://github.com/llvm/llvm-project/pull/229458
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to