Skip to content

Commit ed1db71

Browse files
committed
Remove manual parsing of @PointerBounds macro
Also hack around EnumElementDecl not being handled in getTypeOfReference, for now.
1 parent 2dce1f5 commit ed1db71

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

lib/ClangImporter/ImportDecl.cpp

+6-22
Original file line numberDiff line numberDiff line change
@@ -8583,28 +8583,12 @@ void ClangImporter::Implementation::importBoundsAttributes(
85838583
auto &sourceFile = getClangSwiftAttrSourceFile(
85848584
*MappedDecl->getDeclContext()->getParentModule(), MacroString);
85858585

8586-
// Spin up a parser.
8587-
swift::Parser parser(sourceFile.getBufferID(), sourceFile,
8588-
&SwiftContext.Diags, nullptr, nullptr);
8589-
// Prime the lexer.
8590-
parser.consumeTokenWithoutFeedingReceiver();
8591-
8592-
bool hadError = false;
8593-
assert(parser.Tok.is(tok::at_sign));
8594-
SourceLoc atEndLoc = parser.Tok.getRange().getEnd();
8595-
SourceLoc atLoc = parser.consumeToken(tok::at_sign);
8596-
DeclContext *DC = MappedDecl->getParent();
8597-
auto initContext = PatternBindingInitializer::create(DC);
8598-
hadError = parser
8599-
.parseDeclAttribute(MappedDecl->getAttrs(), atLoc, atEndLoc,
8600-
initContext,
8601-
/*isFromClangAttribute=*/true)
8602-
.isError();
8603-
if (hadError) {
8604-
HeaderLoc attrLoc(ClangDecl->getLocation());
8605-
diagnose(attrLoc, diag::clang_pointer_bounds_unhandled,
8606-
MappedDecl->getName(), MacroString);
8607-
return;
8586+
// Collect the attributes from the synthesized top-level declaration in
8587+
// the source file.
8588+
auto topLevelDecls = sourceFile.getTopLevelDecls();
8589+
for (auto decl : topLevelDecls) {
8590+
for (auto attr : decl->getAttrs())
8591+
MappedDecl->getAttrs().add(attr->clone(SwiftContext));
86088592
}
86098593
}
86108594

lib/Sema/TypeOfReference.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,12 @@ ConstraintSystem::getTypeOfReference(ValueDecl *value,
977977
return { openedType, openedType, openedType, openedType, Type() };
978978
}
979979

980+
// FIXME: implement this properly
981+
if (auto enumElem = dyn_cast<EnumElementDecl>(value)) {
982+
Type interfaceType = enumElem->getInterfaceType();
983+
return {interfaceType, interfaceType, interfaceType, interfaceType, Type()};
984+
}
985+
980986
// Only remaining case: unqualified reference to a property.
981987
auto *varDecl = cast<VarDecl>(value);
982988

0 commit comments

Comments
 (0)