Skip to content

Commit 6bfe37f

Browse files
committed
[CIR] Avoid unnecessary type cache clearing with Enum type completion
When we process a completed Enum type, we were checking to see if the type was in the type cache and clearing the cache if the mapped type for the enum didn't pass an isInteger(32) check. Unfortunately, this checks to see if the type is the MLIR builtin 32-bit integer type, whereas the type we actually use as a default for forward-declared enums is a CIR integer type, so the check always failed. I don't believe there can ever be a case where the forward declared type for the enum doesn't match the completed type, so we should never need to clear the cache. This change replaces the previous check with an assert that compares the actual completed type to the cached type.
1 parent 26b1332 commit 6bfe37f

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

clang/lib/CIR/CodeGen/CIRGenTypes.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -810,14 +810,14 @@ void CIRGenTypes::UpdateCompletedType(const TagDecl *TD) {
810810
// from the cache. This allows function types and other things that may be
811811
// derived from the enum to be recomputed.
812812
if (const auto *ED = dyn_cast<EnumDecl>(TD)) {
813-
// Only flush the cache if we've actually already converted this type.
814-
if (TypeCache.count(ED->getTypeForDecl())) {
815-
// Okay, we formed some types based on this. We speculated that the enum
816-
// would be lowered to i32, so we only need to flush the cache if this
817-
// didn't happen.
818-
if (!convertType(ED->getIntegerType()).isInteger(32))
819-
TypeCache.clear();
820-
}
813+
// Classic codegen clears the type cache if it contains an entry for this
814+
// enum type that doesn't use i32 as the underlying type, but I can't find
815+
// a test case that meets that condition. C++ doesn't allow forward
816+
// declaration of enums, and C doesn't allow an incomplete forward
817+
// declaration with a non-default type.
818+
assert(
819+
!TypeCache.count(ED->getTypeForDecl()) ||
820+
(convertType(ED->getIntegerType()) == TypeCache[ED->getTypeForDecl()]));
821821
// If necessary, provide the full definition of a type only used with a
822822
// declaration so far.
823823
assert(!cir::MissingFeatures::generateDebugInfo());

0 commit comments

Comments
 (0)