Skip to content

[CIR] Avoid unnecessary type cache clearing with Enum type completion #1673

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

Merged
merged 1 commit into from
Jun 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,14 +810,14 @@ void CIRGenTypes::UpdateCompletedType(const TagDecl *TD) {
// from the cache. This allows function types and other things that may be
// derived from the enum to be recomputed.
if (const auto *ED = dyn_cast<EnumDecl>(TD)) {
// Only flush the cache if we've actually already converted this type.
if (TypeCache.count(ED->getTypeForDecl())) {
// Okay, we formed some types based on this. We speculated that the enum
// would be lowered to i32, so we only need to flush the cache if this
// didn't happen.
if (!convertType(ED->getIntegerType()).isInteger(32))
TypeCache.clear();
}
// Classic codegen clears the type cache if it contains an entry for this
// enum type that doesn't use i32 as the underlying type, but I can't find
// a test case that meets that condition. C++ doesn't allow forward
// declaration of enums, and C doesn't allow an incomplete forward
// declaration with a non-default type.
assert(
!TypeCache.count(ED->getTypeForDecl()) ||
(convertType(ED->getIntegerType()) == TypeCache[ED->getTypeForDecl()]));
// If necessary, provide the full definition of a type only used with a
// declaration so far.
assert(!cir::MissingFeatures::generateDebugInfo());
Expand Down
Loading