Skip to content

Commit f246e76

Browse files
committed
[CIR] Fix parsing of a generic TBAAAttr
1 parent 44eeec2 commit f246e76

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
#include "mlir/IR/Attributes.h"
1717
#include "mlir/IR/BuiltinAttributeInterfaces.h"
18+
#include "mlir/IR/OpImplementation.h"
1819

1920
#include "clang/CIR/Dialect/IR/CIROpsEnums.h"
2021

@@ -50,4 +51,24 @@ class VectorType;
5051
#define GET_ATTRDEF_CLASSES
5152
#include "clang/CIR/Dialect/IR/CIROpsAttributes.h.inc"
5253

54+
template <> struct ::mlir::FieldParser<cir::TBAAAttr, cir::TBAAAttr> {
55+
static mlir::FailureOr<cir::TBAAAttr> parse(mlir::AsmParser &parser) {
56+
mlir::Attribute attribute;
57+
if (parser.parseAttribute(attribute))
58+
return mlir::failure();
59+
if (auto omnipotentChar =
60+
mlir::dyn_cast<cir::TBAAOmnipotentCharAttr>(attribute))
61+
return omnipotentChar;
62+
if (auto vtablePtr = mlir::dyn_cast<cir::TBAAVTablePointerAttr>(attribute))
63+
return vtablePtr;
64+
if (auto scalar = mlir::dyn_cast<cir::TBAAScalarAttr>(attribute))
65+
return scalar;
66+
if (auto tag = mlir::dyn_cast<cir::TBAATagAttr>(attribute))
67+
return tag;
68+
if (auto structAttr = mlir::dyn_cast<cir::TBAAStructAttr>(attribute))
69+
return structAttr;
70+
return parser.emitError(parser.getCurrentLocation(), "Expected TBAAAttr");
71+
}
72+
};
73+
5374
#endif // CLANG_CIR_DIALECT_IR_CIRATTRS_H

clang/test/CIR/CodeGen/tbaa-parse.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir -o %t -O1
2+
// RUN: cir-opt %t
3+
4+
struct S {
5+
short i;
6+
};
7+
8+
struct S glob;
9+
int main(void) {
10+
glob.i = 0;
11+
return glob.i;
12+
}

0 commit comments

Comments
 (0)