Skip to content

Commit 8104d5f

Browse files
authored
Merge pull request #34956 from zoecarver/cxx/cache-nullptr
[gardening] Remove uses of "importDeclCached" and cleanup "VisitEnumConstantDecl".
2 parents 509f905 + 3ac7dbf commit 8104d5f

File tree

1 file changed

+11
-49
lines changed

1 file changed

+11
-49
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3612,8 +3612,10 @@ namespace {
36123612
if (name.empty())
36133613
return nullptr;
36143614

3615-
switch (Impl.getEnumKind(clangEnum)) {
3616-
case EnumKind::Constants: {
3615+
auto enumKind = Impl.getEnumKind(clangEnum);
3616+
switch (enumKind) {
3617+
case EnumKind::Constants:
3618+
case EnumKind::Unknown: {
36173619
// The enumeration was simply mapped to an integral type. Create a
36183620
// constant with that integral type.
36193621

@@ -3630,54 +3632,14 @@ namespace {
36303632
isInSystemModule(dc), Bridgeability::None);
36313633
if (!type)
36323634
return nullptr;
3633-
// FIXME: Importing the type will recursively revisit this same
3634-
// EnumConstantDecl. Short-circuit out if we already emitted the import
3635-
// for this decl.
3636-
if (auto Known = Impl.importDeclCached(decl, getVersion()))
3637-
return Known;
36383635

36393636
// Create the global constant.
3640-
auto result = Impl.createConstant(name, dc, type,
3641-
clang::APValue(decl->getInitVal()),
3642-
ConstantConvertKind::None,
3643-
/*static*/dc->isTypeContext(), decl);
3644-
Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = result;
3645-
3646-
// If this is a compatibility stub, mark it as such.
3647-
if (correctSwiftName)
3648-
markAsVariant(result, *correctSwiftName);
3649-
3650-
return result;
3651-
}
3652-
3653-
case EnumKind::Unknown: {
3654-
// The enumeration was mapped to a struct containing the integral
3655-
// type. Create a constant with that struct type.
3656-
3657-
// The context where the constant will be introduced.
3658-
auto dc =
3659-
Impl.importDeclContextOf(decl, importedName.getEffectiveContext());
3660-
if (!dc)
3661-
return nullptr;
3662-
3663-
// Import the enumeration type.
3664-
auto enumType = Impl.importTypeIgnoreIUO(
3665-
Impl.getClangASTContext().getTagDeclType(clangEnum),
3666-
ImportTypeKind::Value, isInSystemModule(dc), Bridgeability::None);
3667-
if (!enumType)
3668-
return nullptr;
3669-
3670-
// FIXME: Importing the type will can recursively revisit this same
3671-
// EnumConstantDecl. Short-circuit out if we already emitted the import
3672-
// for this decl.
3673-
if (auto Known = Impl.importDeclCached(decl, getVersion()))
3674-
return Known;
3675-
3676-
// Create the global constant.
3677-
auto result = Impl.createConstant(name, dc, enumType,
3678-
clang::APValue(decl->getInitVal()),
3679-
ConstantConvertKind::Construction,
3680-
/*static*/ false, decl);
3637+
bool isStatic = enumKind != EnumKind::Unknown && dc->isTypeContext();
3638+
auto result = Impl.createConstant(
3639+
name, dc, type, clang::APValue(decl->getInitVal()),
3640+
enumKind == EnumKind::Unknown ? ConstantConvertKind::Construction
3641+
: ConstantConvertKind::None,
3642+
isStatic, decl);
36813643
Impl.ImportedDecls[{decl->getCanonicalDecl(), getVersion()}] = result;
36823644

36833645
// If this is a compatibility stub, mark it as such.
@@ -3699,7 +3661,7 @@ namespace {
36993661
return nullptr;
37003662
}
37013663
}
3702-
3664+
37033665
llvm_unreachable("Invalid EnumKind.");
37043666
}
37053667

0 commit comments

Comments
 (0)