This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][UninitializedObjectChecker] Drop lambda support
AbandonedPublic

Authored by Szelethus on Jun 19 2018, 2:47 AM.

Details

Summary

After some thinking, I don't think this checker should support lambdas.

Reason 1.: While this is due to the analyzer not being smart enough just yet, the checker doesn't find uninitialized variables that were captured but value, but it does find find them if they were captured by reference. I think this makes little sense -- capturing by reference could be intentional, if the lambda function assigns a value to it, while capturing an undefined variable by value almost never makes sense. This could be fixed, but...

Reason 2.: I don't think lambda misuse should be the responsibility of this checker. It just doesn't make sense, as lambda misuse in not really an uninitialized value problem. It should rather be handled by a standalone lambda checker.

Diff Detail

Event Timeline

Szelethus created this revision.Jun 19 2018, 2:47 AM

[...]lambda misuse in not really an uninitialized value problem.

I guess you can make the argument that it its. Even then, in my opinion this checker is overkill for lambdas.

  • If the captured variable has a non-default constructor, UninitializedValueChecker will analyze it,
  • if the captured variable has a default constructor, or if Pedantic is disabled and all fields are uninitialized, we probably don't want to warn for them anyways,
  • if the captured variable is primitive (BuiltinType or EnumeralType) we can just easily iterate over the captured fields to check whether they are undefined, and make a decision whether to warn for them or not.

My point is, a standalone cplusplus.LambdaMisuse checker would be a lot more fitting to handle these cases.

But I'd love to hear your thoughts on this one! This functionality could totally be squeezed into the checker (with better warning messages), if we were to come to the conclusion that it should be.

Szelethus abandoned this revision.Jun 19 2018, 10:57 AM

Turns out I was very wrong on this one. Lambdas should be ignored as data members, but not in general.

Sorry about the spam, I think I should've sit longer on this one. I'll submit another patch tomorrow that will correctly explain my current way of thinking on this issue.