[clang] [CIR] Make vtable entries a layout-independent type (PR #248772)

Henrich Lauko via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 4 07:48:44 PST 2026


================
@@ -891,6 +891,22 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstPtrAttr ptrAttr) {
       rewriter, parentLoc, converter->convertType(ptrAttr.getType()), ptrVal);
 }
 
+/// VTableOffsetAttr visitor. The initializer of a relative layout vtable is
+/// built by lowerRelativeVTableInit, so the entry is a pointer here.
+mlir::Value CIRAttrToValue::visitCirAttr(cir::VTableOffsetAttr offsetAttr) {
+  assert(!usesRelativeVTables(parentModule) &&
+         "relative layout vtable entry lowered as an attribute");
+  mlir::Type llvmTy = converter->convertType(offsetAttr.getType());
+  if (!offsetAttr.getValue())
+    return mlir::LLVM::ZeroOp::create(rewriter, parentLoc, llvmTy);
+  mlir::DataLayout layout(parentModule);
+  mlir::Value ptrVal = mlir::LLVM::ConstantOp::create(
+      rewriter, parentLoc,
+      rewriter.getIntegerType(layout.getTypeSizeInBits(llvmTy)),
----------------
xlauko wrote:

nit: The `ConstPtrAttr` visitor above takes the integer width from the CIR type. Could this do the same with `offsetAttr.getType()`?

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


More information about the cfe-commits mailing list