Skip to content

Commit d37efd2

Browse files
committed
Address review feedback
1 parent f5e0612 commit d37efd2

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

clang/include/clang/CIR/Dialect/IR/CIRAttrs.td

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -500,28 +500,54 @@ def CIR_GlobalViewAttr : CIR_Attr<"GlobalView", "global_view", [
500500
// VTableAttr
501501
//===----------------------------------------------------------------------===//
502502

503-
def VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
503+
def CIR_VTableAttr : CIR_Attr<"VTable", "vtable", [TypedAttrInterface]> {
504504
let summary = "Represents a C++ vtable";
505505
let description = [{
506-
Wraps a #cir.const_record containing vtable data.
506+
Wraps a #cir.const_record containing one or more vtable arrays.
507507

508-
Example:
508+
In most cases, the anonymous record type wrapped by this attribute will
509+
contain a single array corresponding to the vtable for one class. However,
510+
in the case of multiple inheritence, the anonymous structure may contain
511+
multiple arrays, each of which is a vtable.
512+
513+
Example 1 (single vtable):
514+
```mlir
515+
cir.global linkonce_odr @_ZTV6Mother =
516+
#cir.vtable<{
517+
#cir.const_array<[
518+
#cir.ptr<null> : !cir.ptr<!u8i>,
519+
#cir.global_view<@_ZTI6Mother> : !cir.ptr<!u8i>,
520+
#cir.global_view<@_ZN6Mother9MotherFooEv> : !cir.ptr<!u8i>,
521+
#cir.global_view<@_ZN6Mother10MotherFoo2Ev> : !cir.ptr<!u8i>
522+
]> : !cir.array<!cir.ptr<!u8i> x 4>
523+
}> : !rec_anon_struct1
509524
```
510-
cir.global linkonce_odr @_ZTV1B = #cir.vtable<<
511-
{#cir.const_array<[#cir.null : !cir.ptr<i8>,
512-
#cir.global_view<@_ZTI1B> : !cir.ptr<i8>,
513-
#cir.global_view<@_ZN1BD1Ev> : !cir.ptr<i8>,
514-
#cir.global_view<@_ZN1BD0Ev> : !cir.ptr<i8>,
515-
#cir.global_view<@_ZNK1A5quackEv> : !cir.ptr<i8>]>
516-
: !cir.array<!cir.ptr<i8> x 5>}>>
517-
: !cir.record<"", !cir.array<!cir.ptr<i8> x 5>>
525+
526+
Example 2 (multiple vtables):
527+
```mlir
528+
cir.global linkonce_odr @_ZTV5Child =
529+
#cir.vtable<{
530+
#cir.const_array<[
531+
#cir.ptr<null> : !cir.ptr<!u8i>,
532+
#cir.global_view<@_ZTI5Child> : !cir.ptr<!u8i>,
533+
#cir.global_view<@_ZN5Child9MotherFooEv> : !cir.ptr<!u8i>,
534+
#cir.global_view<@_ZN6Mother10MotherFoo2Ev> : !cir.ptr<!u8i>
535+
]> : !cir.array<!cir.ptr<!u8i> x 4>,
536+
#cir.const_array<[
537+
#cir.ptr<-8 : i64> : !cir.ptr<!u8i>,
538+
#cir.global_view<@_ZTI5Child> : !cir.ptr<!u8i>,
539+
#cir.global_view<@_ZN6Father9FatherFooEv> : !cir.ptr<!u8i>
540+
]> : !cir.array<!cir.ptr<!u8i> x 3>
541+
}> : !rec_anon_struct2
518542
```
519543
}];
520544

521545
// `vtable_data` is a const record with one element, containing an array of
522546
// vtable information.
523-
let parameters = (ins AttributeSelfTypeParameter<"">:$type,
524-
"mlir::ArrayAttr":$vtable_data);
547+
let parameters = (ins
548+
AttributeSelfTypeParameter<"">:$type,
549+
"mlir::ArrayAttr":$vtable_data
550+
);
525551

526552
let builders = [
527553
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,

clang/lib/CIR/Dialect/IR/CIRAttrs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,14 +448,14 @@ LogicalResult cir::VTableAttr::verify(
448448
LogicalResult eltTypeCheck = success();
449449
auto arrayElts = mlir::cast<ArrayAttr>(constArrayAttr.getElts());
450450
arrayElts.walkImmediateSubElements(
451-
[&](Attribute attr) {
451+
[&](mlir::Attribute attr) {
452452
if (mlir::isa<ConstPtrAttr, GlobalViewAttr>(attr))
453453
return;
454454

455455
eltTypeCheck = emitError()
456456
<< "expected GlobalViewAttr or ConstPtrAttr";
457457
},
458-
[&](Type type) {});
458+
[&](mlir::Type type) {});
459459
if (eltTypeCheck.failed())
460460
return eltTypeCheck;
461461
}

0 commit comments

Comments
 (0)