-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[CIR] Update isSized with upstreamed types #143960
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CIR] Update isSized with upstreamed types #143960
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clangir Author: Amr Hesham (AmrDeveloper) ChangesUpdate Full diff: https://github.com/llvm/llvm-project/pull/143960.diff 3 Files Affected:
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuilder.h b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
index fb1a290c18fa2..0beb234168482 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuilder.h
+++ b/clang/lib/CIR/CodeGen/CIRGenBuilder.h
@@ -139,8 +139,8 @@ class CIRGenBuilderTy : public cir::CIRBaseBuilderTy {
}
bool isSized(mlir::Type ty) {
- if (mlir::isa<cir::PointerType, cir::ArrayType, cir::BoolType,
- cir::IntType>(ty))
+ if (mlir::isa<cir::PointerType, cir::ArrayType, cir::BoolType, cir::IntType,
+ cir::CIRFPTypeInterface, cir::ComplexType, cir::RecordType>(ty))
return true;
if (const auto vt = mlir::dyn_cast<cir::VectorType>(ty))
diff --git a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
index eaba3dfd1105e..bab47924dd719 100644
--- a/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenTypes.cpp
@@ -419,6 +419,15 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
case Type::ConstantArray: {
const ConstantArrayType *arrTy = cast<ConstantArrayType>(ty);
mlir::Type elemTy = convertTypeForMem(arrTy->getElementType());
+
+ // TODO(CIR): In LLVM, "lower arrays of undefined struct type to arrays of
+ // i8 just to have a concrete type"
+ if (!builder.isSized(elemTy)) {
+ cgm.errorNYI(SourceLocation(), "arrays of undefined struct type", type);
+ resultType = cgm.UInt32Ty;
+ break;
+ }
+
resultType = cir::ArrayType::get(elemTy, arrTy->getSize().getZExtValue());
break;
}
@@ -432,8 +441,8 @@ mlir::Type CIRGenTypes::convertType(QualType type) {
}
case Type::Enum: {
- const EnumDecl *ED = cast<EnumType>(ty)->getDecl();
- if (auto integerType = ED->getIntegerType(); !integerType.isNull())
+ const EnumDecl *ed = cast<EnumType>(ty)->getDecl();
+ if (auto integerType = ed->getIntegerType(); !integerType.isNull())
return convertType(integerType);
// Return a placeholder 'i32' type. This can be changed later when the
// type is defined (see UpdateCompletedType), but is likely to be the
diff --git a/clang/test/CIR/CodeGen/array.cpp b/clang/test/CIR/CodeGen/array.cpp
index 7b90c1682ec45..26e172a006451 100644
--- a/clang/test/CIR/CodeGen/array.cpp
+++ b/clang/test/CIR/CodeGen/array.cpp
@@ -473,3 +473,26 @@ void func10(int *a) {
// OGCG: %[[ELE:.*]] = getelementptr inbounds i32, ptr %[[TMP_1]], i64 5
// OGCG: %[[TMP_2:.*]] = load i32, ptr %[[ELE]], align 4
// OGCG: store i32 %[[TMP_2]], ptr %[[INIT]], align 4
+
+void func11() { int _Complex a[4]; }
+
+// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!cir.complex<!s32i> x 4>, !cir.ptr<!cir.array<!cir.complex<!s32i> x 4>>, ["a"]
+
+// LLVM: %[[ARR:.*]] = alloca [4 x { i32, i32 }], i64 1, align 16
+
+// OGCG: %[[ARR:.*]] = alloca [4 x { i32, i32 }], align 16
+
+void func12() {
+ struct Point {
+ int x;
+ int y;
+ };
+
+ Point a[4];
+}
+
+// CIR: %[[ARR:.*]] = cir.alloca !cir.array<!rec_Point x 4>, !cir.ptr<!cir.array<!rec_Point x 4>>, ["a"]
+
+// LLVM: %[[ARR:.*]] = alloca [4 x %struct.Point], i64 1, align 16
+
+// OGCG: %[[ARR:.*]] = alloca [4 x %struct.Point], align 16
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
60b5efc
to
e726acb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Update `isSized` function with the upstreamed types
if (mlir::isa<cir::PointerType, cir::ArrayType, cir::BoolType, | ||
cir::IntType>(ty)) | ||
if (mlir::isa<cir::PointerType, cir::ArrayType, cir::BoolType, cir::IntType, | ||
cir::CIRFPTypeInterface, cir::ComplexType, cir::RecordType>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we figured out a way to make patches that add new types 'check' here. a switch
on the TypeID
is typically what we'd suggest in the FE, but of course that doesn't work here for a number of reasons. Would be nice if someone thought of a way to make sure we didn't forget this again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about creating IsSized
type trait that is attached to type definition, so one does not need to track uses like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a lovely idea!
Update `isSized` function with the upstreamed types
Update
isSized
function with the upstreamed types