Page MenuHomePhabricator

[Sema] Fix a crash when nonnull checking
ClosedPublic

Authored by hliao on Mar 27 2019, 1:39 PM.

Details

Summary
  • Non-null checking is triggered during prototype substitution from a template instantiation, if expressions in decltype contains nullptr chcking. Skip non-null checking in that case as the protype is not finalized yet. Also, the nullptr checking in decltype is only used for type inspection instead of codegen. Ignoring that is harmless.

Diff Detail

Repository
rL LLVM

Event Timeline

hliao created this revision.Mar 27 2019, 1:39 PM

@rsmith, @jlebar I'm out of my depth here and could use some language lawyering help.

I uh... I also think this is an @rsmith question, I have no idea.

hliao added a comment.EditedMar 28 2019, 5:50 AM

just explain what's the issue is and hope that help reviewers to get this fix quick.

  • In Sema::DiagnoseAlwaysNonNullPointer, we issue warnings if a nonnull parameter is used in null checking. It need the function declaration to check parameter attributes. That usually works but fails if that function decl is not ready yet.
  • In template instantiation, we first create the function prototype followed by instantiating the function body. When the function prototype is being formed, we may create binary or other expressions for semantic checking. But, in that phase, i.e. Sema::SubstFunctionDeclType, we don't have a fully specialized function prototype yet to check the parameter number and run into the assertion @ line 11596.

Hope that help to get the picture of this fix. Thanks.

Rakete1111 accepted this revision.Mar 28 2019, 2:43 PM
Rakete1111 added a subscriber: Rakete1111.

Otherwise LGTM.

clang/test/SemaTemplate/decltype.cpp
1 ↗(On Diff #192514)

test/SemaCXX/nonnull.cpp would be a better place to put this test.

2 ↗(On Diff #192514)

This is redundant :)

4 ↗(On Diff #192514)

If you move the test as above you can drop this line.

This revision is now accepted and ready to land.Mar 28 2019, 2:43 PM
tra added inline comments.Mar 28 2019, 3:04 PM
clang/test/SemaTemplate/decltype.cpp
1 ↗(On Diff #192514)

test/SemaCXX/nonnull.cpp tests attribute((nonnull)). Placing this test there would be... odd.

The test could use a more descriptive name, though. Just decltype is way too generic. early-func-template-decltype? Or PR-somthing-something, if there's a bug for this crasher.

hliao added a comment.Mar 28 2019, 7:02 PM

just search bugzilla and, fortunately, found this issue is reported 2+ years ago @ https://bugs.llvm.org/show_bug.cgi?id=30559. I will revise the test case to PR30559 and move it into test/SemaCXX/nonnull.cpp

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2019, 8:54 PM