Skip to content

Commit 72b8d22

Browse files
authored
Merge pull request #77457 from fahadnayyar/frt-ref-semantic-check-refactor
[cxx-interop] Refactoring reference semantic check for c++ records
2 parents 11781a5 + f4a0dd6 commit 72b8d22

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

include/swift/ClangImporter/ClangImporterRequests.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ SourceLoc extractNearestSourceLoc(CxxRecordSemanticsDescriptor desc);
353353
///
354354
/// Do not evaluate this request before importing has started. For example, it
355355
/// is OK to invoke this request when importing a decl, but it is not OK to
356-
/// import this request when importing names. This is because when importing
356+
/// evaluate this request when importing names. This is because when importing
357357
/// names, Clang sema has not yet defined implicit special members, so the
358358
/// results will be flakey/incorrect.
359359
class CxxRecordSemantics

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,10 @@ bool ClangImporter::Implementation::recordHasReferenceSemantics(
157157
if (!isa<clang::CXXRecordDecl>(decl) && !ctx.LangOpts.CForeignReferenceTypes)
158158
return false;
159159

160-
return decl->hasAttrs() && llvm::any_of(decl->getAttrs(), [](auto *attr) {
161-
if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr))
162-
return swiftAttr->getAttribute() == "import_reference" ||
163-
// TODO: Remove this once libSwift hosttools no longer
164-
// requires it.
165-
swiftAttr->getAttribute() == "import_as_ref";
166-
return false;
167-
});
160+
auto semanticsKind =
161+
evaluateOrDefault(ctx.evaluator,
162+
CxxRecordSemantics({decl, ctx}), {});
163+
return semanticsKind == CxxRecordSemanticsKind::Reference;
168164
}
169165

170166
#ifndef NDEBUG

0 commit comments

Comments
 (0)