[clang] [CIR] Upstream DynamicCastOp (PR #161734)
Henrich Lauko via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 5 04:04:34 PDT 2025
================
@@ -601,6 +601,60 @@ def CIR_VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
}];
}
+//===----------------------------------------------------------------------===//
+// DynamicCastInfoAttr
+//===----------------------------------------------------------------------===//
+
+def CIR_DynamicCastInfoAttr : CIR_Attr<"DynamicCastInfo", "dyn_cast_info"> {
+ let summary = "ABI specific information about a dynamic cast";
+ let description = [{
+ Provide ABI specific information about a dynamic cast operation.
+
+ The `srcRtti` and the `destRtti` parameters give the RTTI of the source
+ record type and the destination record type, respectively.
+
+ The `runtimeFunc` parameter gives the `__dynamic_cast` function which is
+ provided by the runtime. The `badCastFunc` parameter gives the
+ `__cxa_bad_cast` function which is also provided by the runtime.
+
+ The `offsetHint` parameter gives the hint value that should be passed to the
+ `__dynamic_cast` runtime function.
+ }];
+
+ let parameters = (ins
+ CIR_GlobalViewAttr:$srcRtti,
+ CIR_GlobalViewAttr:$destRtti,
+ "mlir::FlatSymbolRefAttr":$runtimeFunc,
+ "mlir::FlatSymbolRefAttr":$badCastFunc,
+ CIR_IntAttr:$offsetHint
+ );
+
+ let builders = [
+ AttrBuilderWithInferredContext<(ins "GlobalViewAttr":$srcRtti,
+ "GlobalViewAttr":$destRtti,
+ "mlir::FlatSymbolRefAttr":$runtimeFunc,
+ "mlir::FlatSymbolRefAttr":$badCastFunc,
+ "IntAttr":$offsetHint), [{
+ return $_get(srcRtti.getContext(), srcRtti, destRtti, runtimeFunc,
+ badCastFunc, offsetHint);
+ }]>,
+ ];
+
+ let genVerifyDecl = 1;
+ let assemblyFormat = [{
+ `<`
+ `srcRtti` `=` qualified($srcRtti) `,` `destRtti` `=` qualified($destRtti)
+ `,` `runtimeFunc` `=` $runtimeFunc `,` `badCastFunc` `=` $badCastFunc `,`
+ `offsetHint` `=` qualified($offsetHint)
+ `>`
----------------
xlauko wrote:
Maybe `struct(qualified($srcRtti), qualified($destRtti), $runtimeFunc, $badCastFunc, qualified($offsetHint))` will work to preserve the names, but I have not found any example of this in upstream.
https://github.com/llvm/llvm-project/pull/161734
More information about the cfe-commits
mailing list