Skip to content

Commit 0a6734b

Browse files
andykaylorlanza
authored andcommitted
[CIR] Avoid unnecessary type cache clearing with Enum type completion (llvm#1673)
When we process a completed Enum type, we were checking to see if the completed type was in the type cache and clearing the cache if the completed and converted underlying type for the enum doesn't pass an `isInteger(32)` check. Unfortunately, this checks to see if the type is the MLIR builtin 32-bit integer type, whereas it will always be a CIR integer type, so the check always fails. 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 de60fd4 commit 0a6734b

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

0 commit comments

Comments
 (0)