Skip to content

Comments

C++: Add StackVariable class, preferred over LocalScopeVariable#2381

Merged
geoffw0 merged 14 commits intogithub:masterfrom
jbj:StackVariable
Dec 3, 2019
Merged

C++: Add StackVariable class, preferred over LocalScopeVariable#2381
geoffw0 merged 14 commits intogithub:masterfrom
jbj:StackVariable

Conversation

@jbj
Copy link
Contributor

@jbj jbj commented Nov 19, 2019

Fixes #2352.

This is a very extensive fix for a very small bug, but it's the second time we had reports about a FP due to thread_local, and similar problems might exist in 5-10 other queries. This PR attempts to address them all at once while at the same time reducing our use of the awkardly-named LocalScopeVariable and LocalScopeVariableReachability classes.

jbj added 12 commits November 19, 2019 11:23
The new `StackVariable` class actually denotes what its name suggests.
This is now a copy of `LocalScopeVariableReachability.qll`, just with
`s/LocalScopeVariable/StackVariable/g`. It can be used as a drop-in
replacement since the `LocalScopeVariableReachability.qll` library
implementation was already restricted to `SemanticStackVariable`.
This library is a drop-in replacement for
`LocalScopeVariableReachability`, so no changes are expected.
This means we'll no longer get SSA definitions for thread-local
local-scope variables.
Most of the implementation was already in terms of
`SemanticStackVariable`, so not much should have changed.
In these files it was possible to remove calls to `isStatic` by
switching from `LocalScopeVariable` to `StackVariable`. This changes
semantics, hopefully for the better, to treat `thread_local` locals the
same as `static` locals.
These changes should not affect semantics since these uses of
`LocalScopeVariable` were already constrained to stack variables by
their use of SSA or def-use.
This might cause fewer variables to be analysed because not every use of
`LocalScopeVariable` was constrained by the def-use library. Hopefully
this leads to an improved nullness analysis since it avoids treating
`static T *x = nullptr;` the same as `static T *x; x = nullptr;`.
@jbj jbj added the C++ label Nov 19, 2019
@jbj jbj requested a review from a team as a code owner November 19, 2019 11:00
Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously this is a lot to review, but the improvements LGTM both in terms of library usability and potential improvements to query results.

I'd like to be reassured about the exact impact of these changes on our queries, and I have a small concern that there may be edge cases in SSA, def-use, reachability etc we haven't thought about. Perhaps a query differences run would be worthwhile?

Copy link
Contributor Author

@jbj jbj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these changes could have all sorts of subtle implications. I'll start a dist compare.

jbj added 2 commits November 28, 2019 17:44
It looks like allowing statics in `Nullness.qll` is fine since it's a
"may be null" analysis rather than a "must be null" analysis.

This reverts commit f5b9837.
Conflicts:
      change-notes/1.24/analysis-cpp.md
      cpp/ql/src/Security/CWE/CWE-131/NoSpaceForZeroTerminator.ql
@jbj
Copy link
Contributor Author

jbj commented Nov 29, 2019

I've run dist-compare, and there were no changes. That's always suspicious, so I've tried my very best to convince myself that I invoked dist-compare correctly.

I first started https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/669, but one of its sub-jobs failed with a transient error, so I killed it. At that point it had built a pair of ODASAs:

16:59:00  Starting building: ODASA #6934
16:59:00  Starting building: ODASA #6935

I started https://jenkins.internal.semmle.com/job/Changes/job/CPP-Differences/670 with the same parameters except that I put "6934,6935" in the LGTMDists field. This job finished and found no differences.

The two ODASA jobs look correct to me: they have a qlSubmoduleShaOverride of d22df24 and 763b18c respectively.

Copy link
Contributor

@geoffw0 geoffw0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I'm happy with this!

@geoffw0 geoffw0 merged commit b752a6c into github:master Dec 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LGTM.com - false positive C++: "Comparison result is always the same" + thread_local

2 participants