Author: Amr Hesham
Date: 2025-12-12T18:19:42+01:00
New Revision: 44aec0e768d986aa026e352188baccb0cd529a50

URL: 
https://github.com/llvm/llvm-project/commit/44aec0e768d986aa026e352188baccb0cd529a50
DIFF: 
https://github.com/llvm/llvm-project/commit/44aec0e768d986aa026e352188baccb0cd529a50.diff

LOG: [CIR] Add support for TypeTraitExpr with bool result (#171687)

Add support for the TypeTraitExpr with a boolean result

Added: 
    

Modified: 
    clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
    clang/test/CIR/CodeGen/cxx-traits.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
index d223772b1d9a4..d8c95389396a8 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp
@@ -840,7 +840,11 @@ class ScalarExprEmitter : public 
StmtVisitor<ScalarExprEmitter, mlir::Value> {
     return {};
   }
   mlir::Value VisitTypeTraitExpr(const TypeTraitExpr *e) {
-    cgf.cgm.errorNYI(e->getSourceRange(), "ScalarExprEmitter: type trait");
+    mlir::Location loc = cgf.getLoc(e->getExprLoc());
+    if (e->isStoredAsBoolean())
+      return builder.getBool(e->getBoolValue(), loc);
+    cgf.cgm.errorNYI(e->getSourceRange(),
+                     "ScalarExprEmitter: TypeTraitExpr stored as int");
     return {};
   }
   mlir::Value

diff  --git a/clang/test/CIR/CodeGen/cxx-traits.cpp 
b/clang/test/CIR/CodeGen/cxx-traits.cpp
index cf44f775d0842..ddbdfaeccae2c 100644
--- a/clang/test/CIR/CodeGen/cxx-traits.cpp
+++ b/clang/test/CIR/CodeGen/cxx-traits.cpp
@@ -18,3 +18,42 @@ void expression_trait_expr() {
 
 // OGCG: %[[A_ADDR:.*]] = alloca i8, align 1
 // OGCG: store i8 0, ptr %[[A_ADDR]], align 1
+
+void type_trait_expr() {
+  enum E {};
+  bool a = __is_enum(E);
+  bool b = __is_same(int, float);
+  bool c = __is_constructible(int, int, int, int);
+  bool d = __is_array(int);
+}
+
+// CIR: %[[A_ADDR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["a", init]
+// CIR: %[[B_ADDR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["b", init]
+// CIR: %[[C_ADDR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["c", init]
+// CIR: %[[D_ADDR:.*]] = cir.alloca !cir.bool, !cir.ptr<!cir.bool>, ["d", init]
+// CIR: %[[CONST_TRUE:.*]] = cir.const #true
+// CIR: cir.store {{.*}} %[[CONST_TRUE]], %[[A_ADDR]] : !cir.bool, 
!cir.ptr<!cir.bool>
+// CIR: %[[CONST_FALSE:.*]] = cir.const #false
+// CIR: cir.store {{.*}} %[[CONST_FALSE]], %[[B_ADDR]] : !cir.bool, 
!cir.ptr<!cir.bool>
+// CIR: %[[CONST_FALSE:.*]] = cir.const #false
+// CIR: cir.store {{.*}} %[[CONST_FALSE]], %[[C_ADDR]] : !cir.bool, 
!cir.ptr<!cir.bool>
+// CIR: %[[CONST_FALSE:.*]] = cir.const #false
+// CIR: cir.store {{.*}} %[[CONST_FALSE]], %[[D_ADDR]] : !cir.bool, 
!cir.ptr<!cir.bool>
+
+// LLVM: %[[A_ADDR:.*]] = alloca i8, i64 1, align 1
+// LLVM: %[[B_ADDR:.*]] = alloca i8, i64 1, align 1
+// LLVM: %[[C_ADDR:.*]] = alloca i8, i64 1, align 1
+// LLVM: %[[D_ADDR:.*]] = alloca i8, i64 1, align 1
+// LLVM: store i8 1, ptr %[[A_ADDR]], align 1
+// LLVM: store i8 0, ptr %[[B_ADDR]], align 1
+// LLVM: store i8 0, ptr %[[C_ADDR]], align 1
+// LLVM: store i8 0, ptr %[[D_ADDR]], align 1
+
+// OGCG: %[[A_ADDR:.*]] = alloca i8, align 1
+// OGCG: %[[B_ADDR:.*]] = alloca i8, align 1
+// OGCG: %[[C_ADDR:.*]] = alloca i8, align 1
+// OGCG: %[[D_ADDR:.*]] = alloca i8, align 1
+// OGCG: store i8 1, ptr %[[A_ADDR]], align 1
+// OGCG: store i8 0, ptr %[[B_ADDR]], align 1
+// OGCG: store i8 0, ptr %[[C_ADDR]], align 1
+// OGCG: store i8 0, ptr %[[D_ADDR]], align 1


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

Reply via email to