This is an archive of the discontinued LLVM Phabricator instance.

Don't create builtin declaration when looking for typo corrections in C++
AbandonedPublic

Authored by agutowski on Oct 10 2016, 5:34 PM.

Details

Summary

Declarations for the builtins were created when suspected of being corrections for a typo. That could trigger some absurd warnings about missing headers.

Event Timeline

agutowski updated this revision to Diff 74190.Oct 10 2016, 5:34 PM
agutowski retitled this revision from to Don't create builtin declaration when looking for typo corrections in C++.
agutowski updated this object.
agutowski added reviewers: rnk, hans, majnemer, thakis.
agutowski added a subscriber: cfe-commits.
thakis edited edge metadata.

rtrieu: Is there some global "are we in typo correction?" bit somewhere already?

lib/CodeGen/CGBuiltin.cpp
800

Is this an unrelated change?

lib/Sema/SemaLookup.cpp
2013

Are you passing false anywhere? I can't find it (but I'm probably just blind) :-)

agutowski added inline comments.Oct 10 2016, 6:34 PM
lib/CodeGen/CGBuiltin.cpp
800

Yeah, mostly - I had to fix this for tests to work properly.

lib/Sema/SemaLookup.cpp
2013

Yes, it's not visible in the changelist - in line ~4305, in "LookupPotentialTypoResult":

SemaRef.LookupParsedName(Res, S, SS, /*AllowBuiltinCreation=*/false, EnteringContext);
rsmith added a subscriber: rsmith.Oct 10 2016, 6:41 PM

It sounds like this will hinder our ability to typo-correct to builtins. I think we only want to suppress implicitly declaring *library* builtins here (those that are expected to be provided by a header), not all builtins.

rnk edited edge metadata.Oct 11 2016, 3:26 PM

We shouldn't thread this kind of boolean all the way through name lookup. This is the kind of thing that callers should configure on the LookupResult object that they pass in.

rnk added a comment.Oct 11 2016, 3:27 PM

Can you provide a more complete motivating example where our diagnostics were bad? I'm having a hard time figuring it out from the test

agutowski added a comment.EditedOct 11 2016, 4:17 PM
In D25458#567697, @rnk wrote:

Can you provide a more complete motivating example where our diagnostics were bad? I'm having a hard time figuring it out from the test

Sure, compiling the following program in C++ for i386 on Windows emits warnings about implicit declarations of __emul and __emulu:

int main() {
  __umul(1, 2);
  return 0;
}
agutowski abandoned this revision.Oct 13 2016, 6:31 PM

It's part of a bigger problem (Clang shows warnings about functions guessed by typo-fixing in other cases as well), but it's not that important and I can't see any straighforward solution that would do more good than harm, so I'm closing this revision for now.