[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.
This commit is contained in:
Doug Gregor
2017-04-22 21:44:51 -07:00
parent facf1996b1
commit 25ce6fa28c

View File

@@ -42,8 +42,19 @@ public:
/// This emits a diagnostic with a fixit to remove the attribute.
template<typename ...ArgTypes>
void diagnoseAndRemoveAttr(DeclAttribute *attr, ArgTypes &&...Args) {
TC.diagnose(attr->getLocation(), std::forward<ArgTypes>(Args)...)
.fixItRemove(attr->getRangeWithAt());
assert(!D->hasClangNode() && "Clang imported propagated a bogus attribute");
if (!D->hasClangNode()) {
SourceLoc loc = attr->getLocation();
assert(loc.isValid() && "Diagnosing attribute with invalid location");
if (loc.isInvalid()) {
loc = D->getLoc();
}
if (loc.isValid()) {
TC.diagnose(loc, std::forward<ArgTypes>(Args)...)
.fixItRemove(attr->getRangeWithAt());
}
}
attr->setInvalid();
}