diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td b/clang/include/clang/CIR/Dialect/IR/CIROps.td index 80b066f5163b..0313b83d927c 100644 --- a/clang/include/clang/CIR/Dialect/IR/CIROps.td +++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td @@ -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 -> !cir.ptr + %res = cir.dyn_cast ptr relative_layout %ptr: !cir.ptr -> !cir.ptr + ``` }]; let arguments = (ins @@ -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 = [{ diff --git a/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp b/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp index 20498f905f8d..d40dfdd2f741 100644 --- a/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp +++ b/clang/test/CIR/CodeGen/dynamic-cast-relative-layout.cpp @@ -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 relative_layout) -> !cir.ptr +// BEFORE: %{{.+}} = cir.dyn_cast ptr relative_layout %{{.+}} : !cir.ptr -> !cir.ptr // BEFORE: } // AFTER: cir.func dso_local @_Z20ptr_cast_to_completeP4Base diff --git a/clang/test/CIR/CodeGen/dynamic-cast.cpp b/clang/test/CIR/CodeGen/dynamic-cast.cpp index 37791de09a3d..0d2cae3317af 100644 --- a/clang/test/CIR/CodeGen/dynamic-cast.cpp +++ b/clang/test/CIR/CodeGen/dynamic-cast.cpp @@ -18,7 +18,7 @@ Derived *ptr_cast(Base *b) { } // BEFORE: cir.func dso_local @_Z8ptr_castP4Base -// BEFORE: %{{.+}} = cir.dyn_cast(ptr, %{{.+}} : !cir.ptr, #dyn_cast_info__ZTI4Base__ZTI7Derived) -> !cir.ptr +// BEFORE: %{{.+}} = cir.dyn_cast ptr %{{.+}} : !cir.ptr -> !cir.ptr #dyn_cast_info__ZTI4Base__ZTI7Derived // BEFORE: } // AFTER: cir.func dso_local @_Z8ptr_castP4Base @@ -43,7 +43,7 @@ Derived &ref_cast(Base &b) { } // BEFORE: cir.func dso_local @_Z8ref_castR4Base -// BEFORE: %{{.+}} = cir.dyn_cast(ref, %{{.+}} : !cir.ptr, #dyn_cast_info__ZTI4Base__ZTI7Derived) -> !cir.ptr +// BEFORE: %{{.+}} = cir.dyn_cast ref %{{.+}} : !cir.ptr -> !cir.ptr #dyn_cast_info__ZTI4Base__ZTI7Derived // BEFORE: } // AFTER: cir.func dso_local @_Z8ref_castR4Base @@ -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) -> !cir.ptr +// BEFORE: %{{.+}} = cir.dyn_cast ptr %{{.+}} : !cir.ptr -> !cir.ptr // BEFORE: } // AFTER: cir.func dso_local @_Z20ptr_cast_to_completeP4Base diff --git a/clang/test/CIR/IR/invalid.cir b/clang/test/CIR/IR/invalid.cir index 7edfbdf5933d..b1b42a9d7505 100644 --- a/clang/test/CIR/IR/invalid.cir +++ b/clang/test/CIR/IR/invalid.cir @@ -1192,7 +1192,7 @@ module { cir.func private @__cxa_bad_cast() cir.func @test(%arg0 : !cir.ptr) { // expected-error@+1 {{srcRtti must be an RTTI pointer}} - %0 = cir.dyn_cast(ptr, %arg0 : !cir.ptr, #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr, #cir.global_view<@_ZTI7Derived> : !cir.ptr, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>) -> !cir.ptr + %0 = cir.dyn_cast ptr %arg0 : !cir.ptr -> !cir.ptr #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr, #cir.global_view<@_ZTI7Derived> : !cir.ptr, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i> } } @@ -1214,7 +1214,7 @@ module { cir.func private @__cxa_bad_cast() cir.func @test(%arg0 : !cir.ptr) { // expected-error@+1 {{destRtti must be an RTTI pointer}} - %0 = cir.dyn_cast(ptr, %arg0 : !cir.ptr, #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr, #cir.global_view<@_ZTI7Derived> : !cir.ptr, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i>) -> !cir.ptr + %0 = cir.dyn_cast ptr %arg0 : !cir.ptr -> !cir.ptr #cir.dyn_cast_info<#cir.global_view<@_ZTI4Base> : !cir.ptr, #cir.global_view<@_ZTI7Derived> : !cir.ptr, @__dynamic_cast, @__cxa_bad_cast, #cir.int<0> : !s64i> } }