Skip to content

Commit 25ce6fa

Browse files
committed
[Type checker] Fail more usefully if something synthesizes a bogus attribute.
No part of the compiler, including the Clang importer, should synthesize an attribute that would fail early attribute validation. When it happens, it would emit diagnostics with no location information, which is really annoyingly hard to debug. Instead, assert that this doesn't happen, i.e., both that the Clang importer doesn't synthesize bogus attributes (as in the previous commit) and that nothing synthesizes such attributes with empty source location informations. In non-asserting builds, just suppress the diagnostic.
1 parent facf199 commit 25ce6fa

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/Sema/TypeCheckAttr.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,19 @@ class AttributeEarlyChecker : public AttributeVisitor<AttributeEarlyChecker> {
4242
/// This emits a diagnostic with a fixit to remove the attribute.
4343
template<typename ...ArgTypes>
4444
void diagnoseAndRemoveAttr(DeclAttribute *attr, ArgTypes &&...Args) {
45-
TC.diagnose(attr->getLocation(), std::forward<ArgTypes>(Args)...)
46-
.fixItRemove(attr->getRangeWithAt());
45+
assert(!D->hasClangNode() && "Clang imported propagated a bogus attribute");
46+
if (!D->hasClangNode()) {
47+
SourceLoc loc = attr->getLocation();
48+
assert(loc.isValid() && "Diagnosing attribute with invalid location");
49+
if (loc.isInvalid()) {
50+
loc = D->getLoc();
51+
}
52+
if (loc.isValid()) {
53+
TC.diagnose(loc, std::forward<ArgTypes>(Args)...)
54+
.fixItRemove(attr->getRangeWithAt());
55+
}
56+
}
57+
4758
attr->setInvalid();
4859
}
4960

0 commit comments

Comments
 (0)