Skip to content

Commit 955d33f

Browse files
authored
[CIR] Backport TypeInfo record element type constraints (#1911)
Backport using ArrayOf constraints from the upstream and the test file for invalid type info
1 parent 9fc2a91 commit 955d33f

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,29 @@ def CIR_AnyIntOrFloatAttr : AnyAttrOf<[CIR_AnyIntAttr, CIR_AnyFPAttr],
3838
string cppType = "::mlir::TypedAttr";
3939
}
4040

41+
//===----------------------------------------------------------------------===//
42+
// GlobalViewAttr constraints
43+
//===----------------------------------------------------------------------===//
44+
45+
def CIR_AnyGlobalViewAttr : CIR_AttrConstraint<"::cir::GlobalViewAttr", "GlobalView attribute">;
46+
47+
def CIR_AnyIntOrGlobalViewAttr : AnyAttrOf<[CIR_AnyIntAttr, CIR_AnyGlobalViewAttr],
48+
"integer or global view attribute"> {
49+
string cppType = "::mlir::TypedAttr";
50+
}
51+
4152
//===----------------------------------------------------------------------===//
4253
// ArrayAttr constraints
4354
//===----------------------------------------------------------------------===//
4455

4556
def CIR_IntArrayAttr : TypedArrayAttrBase<CIR_AnyIntAttr,
4657
"integer array attribute">;
4758

59+
def CIR_IntOrGlobalViewArrayAttr : TypedArrayAttrBase<CIR_AnyIntOrGlobalViewAttr,
60+
"integer or global view array attribute">{
61+
string cppType = "::mlir::ArrayAttr";
62+
}
63+
4864
//===----------------------------------------------------------------------===//
4965
// TBAAAttr constraints
5066
//===----------------------------------------------------------------------===//

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -849,8 +849,10 @@ def CIR_TypeInfoAttr : CIR_Attr<"TypeInfo", "typeinfo", [TypedAttrInterface]> {
849849
```
850850
}];
851851

852-
let parameters = (ins AttributeSelfTypeParameter<"">:$type,
853-
"mlir::ArrayAttr":$data);
852+
let parameters = (ins
853+
AttributeSelfTypeParameter<"">:$type,
854+
CIR_IntOrGlobalViewArrayAttr:$data
855+
);
854856

855857
let builders = [
856858
AttrBuilderWithInferredContext<(ins "mlir::Type":$type,

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3728,11 +3728,6 @@ LogicalResult cir::TypeInfoAttr::verify(
37283728
if (cir::ConstRecordAttr::verify(emitError, type, typeinfoData).failed())
37293729
return failure();
37303730

3731-
for (auto &member : typeinfoData) {
3732-
if (llvm::isa<GlobalViewAttr, IntAttr>(member))
3733-
continue;
3734-
return emitError() << "expected GlobalViewAttr or IntAttr attribute";
3735-
}
37363731
return success();
37373732
}
37383733

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: cir-opt %s -verify-diagnostics -split-input-file
2+
3+
!u8i = !cir.int<u, 8>
4+
5+
!rec_anon_struct = !cir.record<struct {!cir.ptr<!u8i>, !cir.ptr<!u8i>, !cir.ptr<!u8i>}>
6+
7+
// expected-error @below {{expected !cir.record type}}
8+
cir.global constant external @type_info = #cir.typeinfo<{#cir.global_view<@_ZTVN10__cxxabiv120__si_class_type_infoE, [2 : i32]> : !cir.ptr<!u8i>, #cir.global_view<@_ZTS1B> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI1A> : !cir.ptr<!u8i>}> : !u8i
9+
10+
// -----
11+
12+
!u8i = !cir.int<u, 8>
13+
14+
!rec_anon_struct = !cir.record<struct {!u8i, !u8i, !u8i}>
15+
16+
// expected-error @below {{integer or global view array attribute}}
17+
cir.global constant external @type_info = #cir.typeinfo<{ #cir.undef : !u8i, #cir.int<1> : !u8i, #cir.int<1> : !u8i}> : !rec_anon_struct

0 commit comments

Comments
 (0)