[clang] [CIR] Upstream zero init for global variables (PR #133100)

Andy Kaylor via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 26 16:43:32 PDT 2025


================
@@ -67,6 +67,40 @@ class CIRBaseBuilderTy : public mlir::OpBuilder {
     return create<cir::ConstantOp>(loc, attr.getType(), attr);
   }
 
+  mlir::TypedAttr getConstNullPtrAttr(mlir::Type t) {
+    assert(mlir::isa<cir::PointerType>(t) && "expected cir.ptr");
+    return getConstPtrAttr(t, 0);
+  }
+
+  mlir::TypedAttr getZeroAttr(mlir::Type t) {
+    return cir::ZeroAttr::get(getContext(), t);
+  }
+
+  mlir::TypedAttr getZeroInitAttr(mlir::Type ty) {
+    if (mlir::isa<cir::IntType>(ty))
+      return cir::IntAttr::get(ty, 0);
+    if (auto fltType = mlir::dyn_cast<cir::SingleType>(ty))
----------------
andykaylor wrote:

I think this will work:

```
if (cir::isAnyFloatingPointType(ty))
  return cir::FPAttr::getZero(ty);
```

https://github.com/llvm/llvm-project/pull/133100


More information about the cfe-commits mailing list