This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Fixes an assertion failure while instantiation a template with an incomplete typo corrected type
ClosedPublic

Authored by Mordante on Jul 12 2019, 9:43 AM.

Details

Summary

This fixes bug 35682. When a template in instantiated with an incomplete typo corrected type an assertion can trigger if the -ferror-limit is used to reduce the number of errors. The issue can be reproduced with the following code:

#include <utility>
        
using SetKeyType = String;                                                      
std::pair<SetKeyType, int> v;

and compiled with: clang -stdlib=libc++ -ferror-limit=1 -c bug.cc
This requires the stdlib=libc++ option, without it the assertion does not trigger. Neither does it trigger when the -ferror-limit=1 is not used. The test case is based on this sample but no longer requires the -stdlib=libc++ option.

Diff Detail

Event Timeline

Mordante created this revision.Jul 12 2019, 9:43 AM

Test?

clang/lib/Sema/SemaTemplate.cpp
732

no else after return

Mordante marked 2 inline comments as done.Jul 12 2019, 10:02 AM

Thanks for feedback. I'll whether I can find a way to generate a nice test case.

clang/lib/Sema/SemaTemplate.cpp
732

Will do in the next update.

Mordante updated this revision to Diff 210128.Jul 16 2019, 10:10 AM
Mordante marked an inline comment as done.
Mordante retitled this revision from Fixes a clang frontend assertion failure (bug 35682) to Fixes an assertion failure while instantiation a template with an incomplete typo corrected type.
Mordante edited the summary of this revision. (Show Details)

Fixes @lebedev.ri's remark and adds the requested test.
While working on the test I discovered the initial assumption in bug 35682 was incorrect. Updated the title and summary accordingly.

lebedev.ri added inline comments.Jul 16 2019, 10:22 AM
clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
10–11

Please don't pull in any external headers - just mock what you need.

Mordante updated this revision to Diff 210146.Jul 16 2019, 12:00 PM

Remove the includes from the test.
Changed the std::is_constructible to is_same since the latter is easier to mock.

Mordante marked an inline comment as done.Jul 16 2019, 12:00 PM

Test looks good, adding a few more potential reviewers..

Mordante updated this revision to Diff 218221.Aug 31 2019, 7:04 AM
Mordante retitled this revision from Fixes an assertion failure while instantiation a template with an incomplete typo corrected type to [Sema] Fixes an assertion failure while instantiation a template with an incomplete typo corrected type.

Update bug number references:

  • Removed from the source
  • Use PR35682 in the test

Note: I tried to use -verify instead of FileCheck but that doesn't seem to work well since -ferror-limit 1 reports no line number. Other tests with -ferror-limit 1 also use FileCheck.

aaron.ballman added inline comments.Sep 4 2019, 2:07 PM
clang/lib/Sema/SemaTemplate.cpp
727

The call to std::move() shouldn't be necessary.

clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
2

Do you intend to test %clang_cc1 instead? Can the test be rewritten to use -verify rather than FileCheck? If the test crashes or asserts, that will cause the test to fail anyway, so it doesn't seem like it needs to FileCheck.

Mordante marked 3 inline comments as done.Sep 5 2019, 12:33 PM
Mordante added inline comments.
clang/test/SemaTemplate/instantiate-incomplete-typo-suggested-error-limit.cpp
2

As discussed on IRC this is not possible due to the fact there is an error without line number.
(frontend): too many errors emitted, stopping now

Mordante updated this revision to Diff 218965.Sep 5 2019, 12:34 PM
Mordante marked an inline comment as done.

Removes the unnecessary std::move as suggested by @aaron.ballman.

This revision is now accepted and ready to land.Sep 6 2019, 5:03 AM

Thanks for the review.
Could you commit this patch? I don't have commit access.

aaron.ballman closed this revision.Sep 7 2019, 1:12 PM

Thanks for the review.
Could you commit this patch? I don't have commit access.

Happy to do so -- I've commit in r371320.