================
@@ -1889,6 +1889,25 @@ mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr 
*ce) {
     }
     return v;
   }
+  case CK_IntegralToPointer: {
+    mlir:Type destCIRTy = cgf.convertType(destTy);
+    mlir::Value src = Visit(const_cast<Expr *>(subExpr));
+
+    // Properly resize by casting to an int of the same size as the pointer.
+    // Clang's IntegralToPointer includes 'bool' as the source, but in CIR
+    // 'bool' is not an integral type.  So check the source type to get the
+    // correct CIR conversion.
+    mlirType middleTy = cgf.cgm.getDataLayout().getIntPtrType(destCIRTy);
+    cir::CastOp middleVal = 
builder.createCast(subExpr->getType()->isBooleanType()
+                                            ? cir::CastKind::bool_to_int
+                                            : cir::CastKind::integral,
+                                        Src, MiddleTy);
+
+    if (cgf.cgm.getCodeGenOpts().StrictVTablePointers)
+      cgf.cgm.errorNYI(subExpr->getSourceRange(), "IntegralToPointer: strict 
vtable pointers");
+
----------------
AmrDeveloper wrote:

In case of NYI you can early return with a default or recovery value to not hit 
any assets from the code below

```suggestion
    if (cgf.cgm.getCodeGenOpts().StrictVTablePointers) {
      cgf.cgm.errorNYI(subExpr->getSourceRange(), "IntegralToPointer: strict 
vtable pointers");
      return {};
    }

```

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

Reply via email to