https://github.com/widberg updated 
https://github.com/llvm/llvm-project/pull/192569

>From ce5ffb842142abbf755d8fe9df43c8bc68c827c6 Mon Sep 17 00:00:00 2001
From: widberg <[email protected]>
Date: Thu, 29 Jan 2026 01:20:01 -0500
Subject: [PATCH 1/2] cir bool result

---
 clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp 
b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
index afa7e5b91251b..1e6043e22e761 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp
@@ -2160,7 +2160,11 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
 
     auto encompassingCIRTy = cir::IntType::get(
         &getMLIRContext(), encompassingInfo.width, encompassingInfo.isSigned);
-    auto resultCIRTy = mlir::cast<cir::IntType>(cgm.convertType(resultQTy));
+    auto resultCIRType = cgm.convertType(resultQTy);
+    bool resultIsBool = mlir::isa<cir::BoolType>(resultCIRType);
+    auto resultCIRTy = resultIsBool ? cir::IntType::get(&getMLIRContext(), 1,
+                                                        /*isSigned=*/false)
+                                    : mlir::cast<cir::IntType>(resultCIRType);
 
     mlir::Value x = emitScalarExpr(leftArg);
     mlir::Value y = emitScalarExpr(rightArg);
@@ -2213,7 +2217,11 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl 
&gd, unsigned builtinID,
     // Finally, store the result using the pointer.
     bool isVolatile =
         resultArg->getType()->getPointeeType().isVolatileQualified();
-    builder.createStore(loc, result, resultPtr, isVolatile);
+    mlir::Value storeVal = result;
+    if (resultIsBool)
+      storeVal = builder.createCast(loc, cir::CastKind::int_to_bool, storeVal,
+                                    cir::BoolType::get(&getMLIRContext()));
+    builder.createStore(loc, storeVal, resultPtr, isVolatile);
 
     return RValue::get(overflow);
   }

>From 40699328b14fb5faded37f112a9050103842cd10 Mon Sep 17 00:00:00 2001
From: widberg <[email protected]>
Date: Thu, 28 May 2026 00:12:13 +0000
Subject: [PATCH 2/2] cir tests

---
 .../CIR/CodeGenBuiltins/builtins-overflow.cpp   | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/clang/test/CIR/CodeGenBuiltins/builtins-overflow.cpp 
b/clang/test/CIR/CodeGenBuiltins/builtins-overflow.cpp
index 33dd4bb733059..62de9e41d7d67 100644
--- a/clang/test/CIR/CodeGenBuiltins/builtins-overflow.cpp
+++ b/clang/test/CIR/CodeGenBuiltins/builtins-overflow.cpp
@@ -388,3 +388,20 @@ bool test_bool_math_overflow(bool x, bool y, int *res) {
 // LLVM: call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %[[X_CAST]], i32 
%[[Y_CAST]])
 }
 
+bool f(int x, int y, bool *r) {
+  return __builtin_add_overflow(x, y, r);
+}
+
+//      CIR: cir.func {{.*}} @_Z1fiiPb
+//      CIR:   %[[#X:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i
+// CIR-NEXT:   %[[#Y:]] = cir.load{{.*}} %{{.+}} : !cir.ptr<!s32i>, !s32i
+// CIR-NEXT:   %[[#R_PTR:]] = cir.load{{.*}} %{{.+}} : 
!cir.ptr<!cir.ptr<!cir.bool>>, !cir.ptr<!cir.bool>
+// CIR-NEXT:   %[[RES:.+]], %{{.+}} = cir.add.overflow %[[#X]], %[[#Y]] : 
!s32i -> !cir.int<u, 1>
+// CIR-NEXT:   %[[RES_BOOL:.+]] = cir.cast int_to_bool %[[RES]] : !cir.int<u, 
1> -> !cir.bool
+// CIR-NEXT:   cir.store{{.*}} %[[RES_BOOL]], %[[#R_PTR]] : !cir.bool, 
!cir.ptr<!cir.bool>
+//      CIR: }
+
+// LLVM-LABEL: @_Z1fiiPb(
+// LLVM: call { i32, i1 } @llvm.sadd.with.overflow.i32(i32 %{{.+}}, i32 
%{{.+}})
+// LLVM: trunc i32 %{{.+}} to i1
+// LLVM: store i8 %{{.+}}, ptr %{{.+}}

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

Reply via email to