Skip to content

Commit f4a0dd6

Browse files
committed
[cxx-interop] Refactoring reference semantic check for c++ records
1 parent e640ed6 commit f4a0dd6

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
@@ -156,14 +156,10 @@ bool ClangImporter::Implementation::recordHasReferenceSemantics(
156156
if (!isa<clang::CXXRecordDecl>(decl) && !ctx.LangOpts.CForeignReferenceTypes)
157157
return false;
158158

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

169165
#ifndef NDEBUG

0 commit comments

Comments
 (0)