This is an archive of the discontinued LLVM Phabricator instance.

Thread safety analysis: Examine constructor arguments
ClosedPublic

Authored by aaronpuchert on Sep 24 2018, 3:48 PM.

Details

Summary

Instead of only examining call arguments, we also examine constructor
arguments applying the same rules.

That was an oppurtunity for refactoring the examination procedure to
work with iterators instead of integer indices. For the case of
CallExprs no functional change is intended.

Diff Detail

Event Timeline

aaronpuchert created this revision.Sep 24 2018, 3:48 PM

There is a (technical) merge conflict between this change and D52395, but that shouldn't be of any concern for the review. The issues are rather independent. (I think.)

This generally looks sensible to me.

lib/Analysis/ThreadSafety.cpp
1970

How should this interact with variadic functions? Either ones that use ... with a C varargs function, or ones that use parameter packs in C++. (I realize this is basically existing code, but the question remains.)

2039

Can you add a comment for the bool argument? e.g., /*OperatorFun*/false

aaronpuchert added inline comments.Sep 27 2018, 2:21 PM
lib/Analysis/ThreadSafety.cpp
1970

For instantiated variadic templates we match against the instantiation of the template, so we can match the parameters just as for an ordinary function. My understanding is that the thread safety analysis doesn't run over templates, only instantiations, so that should be fine.

With C variadic arguments we should have a shorter parameter list, so we don't check the matching variadic arguments. However, if I'm not mistakten, the variadic arguments are passed by value, so the reference checks aren't needed.

Maybe I can add some tests for these cases.

2039

Depending on OperatorFun, we shift some of the iterators. We could also do that on the caller site. I'll see if that looks better.

aaron.ballman added inline comments.Sep 27 2018, 3:17 PM
lib/Analysis/ThreadSafety.cpp
1970

Good points -- we're likely fine here, but if we lack some test coverage for this, it'd be good to add some. If you find you need to add tests that wind up Just Working, feel free to commit them without review.

This looks good, and resolves an outstanding bug that was on my list. Thanks for the patch!

lib/Analysis/ThreadSafety.cpp
1537

Nit: capitalization does not match other methods.

delesley added inline comments.Sep 27 2018, 3:31 PM
lib/Analysis/ThreadSafety.cpp
2035

As a side note, we should probably special-case the move constructor too, with AK_Written. That should be in a separate patch, though, and needs to be sequestered under -Wthread-safety-beta, which is complicated.

aaronpuchert marked 4 inline comments as done.

Moved iterator shifting to VisitCallExpr, eliminated boolean variables, and minor corrections as suggested in the review. There remains no intended functional change to VisitCallExpr.

aaronpuchert marked 2 inline comments as done.Oct 1 2018, 5:19 PM

Since the (remaining) arguments are examined in a separate function, I thought I'd eliminate the boolean variables in VisitCallExpr. Apparently I prefer control flow over booleans, but if you disagree I can obviously change it back.

lib/Analysis/ThreadSafety.cpp
2035

I think your arguments from D52395 apply here as well: the move constructor does not necessarily write. Many simple types are trivially move constructible, and then the move constructor is effectively the same as the copy constructor.

delesley accepted this revision.Oct 4 2018, 3:50 PM
delesley added inline comments.
lib/Analysis/ThreadSafety.cpp
2035

Good point.

This revision is now accepted and ready to land.Oct 4 2018, 3:50 PM
This revision was automatically updated to reflect the committed changes.