Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions clang/include/clang/CIR/Dialect/IR/CIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ def CIR_DynamicCastOp : CIR_Op<"dyn_cast"> {
The `relative_layout` argument specifies whether the Itanium C++ ABI vtable
uses relative layout. It is only meaningful when the operation models a
cast-to-complete operation.

Example:

```mlir
%res = cir.dyn_cast ptr %ptr: !cir.ptr<!rec_Base> -> !cir.ptr<!rec_Derived>
%res = cir.dyn_cast ptr relative_layout %ptr: !cir.ptr<!rec_Base> -> !cir.ptr<!rec_Derived>
```
}];

let arguments = (ins
Expand All @@ -301,12 +308,9 @@ def CIR_DynamicCastOp : CIR_Op<"dyn_cast"> {
);

let assemblyFormat = [{
`(`
$kind `,` $src `:` qualified(type($src))
(`,` qualified($info)^)?
(`relative_layout` $relative_layout^)?
`)`
`->` qualified(type($result)) attr-dict
$kind (`relative_layout` $relative_layout^)? $src
`:` qualified(type($src)) `->` qualified(type($result))
(qualified($info)^)? attr-dict
}];

let extraClassDeclaration = [{
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void *ptr_cast_to_complete(Base *ptr) {
}

// BEFORE: cir.func dso_local @_Z20ptr_cast_to_completeP4Base
// BEFORE: %{{.+}} = cir.dyn_cast(ptr, %{{.+}} : !cir.ptr<!rec_Base> relative_layout) -> !cir.ptr<!void>
// BEFORE: %{{.+}} = cir.dyn_cast ptr relative_layout %{{.+}} : !cir.ptr<!rec_Base> -> !cir.ptr<!void>
// BEFORE: }

// AFTER: cir.func dso_local @_Z20ptr_cast_to_completeP4Base
Expand Down
6 changes: 3 additions & 3 deletions clang/test/CIR/CodeGen/dynamic-cast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Derived *ptr_cast(Base *b) {
}

// BEFORE: cir.func dso_local @_Z8ptr_castP4Base
// BEFORE: %{{.+}} = cir.dyn_cast(ptr, %{{.+}} : !cir.ptr<!rec_Base>, #dyn_cast_info__ZTI4Base__ZTI7Derived) -> !cir.ptr<!rec_Derived>
// BEFORE: %{{.+}} = cir.dyn_cast ptr %{{.+}} : !cir.ptr<!rec_Base> -> !cir.ptr<!rec_Derived> #dyn_cast_info__ZTI4Base__ZTI7Derived
// BEFORE: }

// AFTER: cir.func dso_local @_Z8ptr_castP4Base
Expand All @@ -43,7 +43,7 @@ Derived &ref_cast(Base &b) {
}

// BEFORE: cir.func dso_local @_Z8ref_castR4Base
// BEFORE: %{{.+}} = cir.dyn_cast(ref, %{{.+}} : !cir.ptr<!rec_Base>, #dyn_cast_info__ZTI4Base__ZTI7Derived) -> !cir.ptr<!rec_Derived>
// BEFORE: %{{.+}} = cir.dyn_cast ref %{{.+}} : !cir.ptr<!rec_Base> -> !cir.ptr<!rec_Derived> #dyn_cast_info__ZTI4Base__ZTI7Derived
// BEFORE: }

// AFTER: cir.func dso_local @_Z8ref_castR4Base
Expand All @@ -66,7 +66,7 @@ void *ptr_cast_to_complete(Base *ptr) {
}

// BEFORE: cir.func dso_local @_Z20ptr_cast_to_completeP4Base
// BEFORE: %{{.+}} = cir.dyn_cast(ptr, %{{.+}} : !cir.ptr<!rec_Base>) -> !cir.ptr<!void>
// BEFORE: %{{.+}} = cir.dyn_cast ptr %{{.+}} : !cir.ptr<!rec_Base> -> !cir.ptr<!void>
// BEFORE: }

// AFTER: cir.func dso_local @_Z20ptr_cast_to_completeP4Base
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/IR/invalid.cir
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ module {
cir.func private @__cxa_bad_cast()
cir.func @test(%arg0 : !cir.ptr<!Base>) {
// expected-error@+1 {{srcRtti must be an RTTI pointer}}
%0 = cir.dyn_cast(ptr, %arg0 : !cir.ptr<!Base>, #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr<!u32i>, #cir.global_view<@_ZTI7Derived> : !cir.ptr<!u8i>, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>) -> !cir.ptr<!Derived>
%0 = cir.dyn_cast ptr %arg0 : !cir.ptr<!Base> -> !cir.ptr<!Derived> #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr<!u32i>, #cir.global_view<@_ZTI7Derived> : !cir.ptr<!u8i>, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>
}
}

Expand All @@ -1214,7 +1214,7 @@ module {
cir.func private @__cxa_bad_cast()
cir.func @test(%arg0 : !cir.ptr<!Base>) {
// expected-error@+1 {{destRtti must be an RTTI pointer}}
%0 = cir.dyn_cast(ptr, %arg0 : !cir.ptr<!Base>, #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI7Derived> : !cir.ptr<!u32i>, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>) -> !cir.ptr<!Derived>
%0 = cir.dyn_cast ptr %arg0 : !cir.ptr<!Base> -> !cir.ptr<!Derived> #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI7Derived> : !cir.ptr<!u32i>, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>
}
}

Expand Down
Loading