Commit Graph

1503 Commits

Author SHA1 Message Date
Jonas Jensen
b4f19eebdd C++: Revert the getName() changes
This reverts the `getName()` parts of 56e88cbac0 and 0a2e28858a.
2019-05-29 14:15:45 +02:00
Geoffrey White
574a1d8501 Merge pull request #1037 from kevinbackhouse/RangeAnalysisAssignAddOverflow
Better overflow detection for AssignAdd/AssignSub
2019-05-29 09:54:06 +01:00
Jonas Jensen
b0a7f207e4 Merge pull request #1343 from rdmarsh2/rdmarsh/cpp/getUnspecifiedType
C++: add getUnspecifiedType() for exprs and decls
2019-05-28 20:10:28 +01:00
Robert Marsh
d20efe49dd C++: respond to PR comments 2019-05-28 07:51:59 -07:00
Jonas Jensen
d2fa7aad1c Merge pull request #1336 from geoffw0/cached2
CPP: Cache Expr.getType().
2019-05-27 12:48:56 +01:00
Geoffrey White
170691b467 CPP: Comment as suggested. 2019-05-24 16:16:45 +01:00
Geoffrey White
6bac1e6e99 CPP: Accept CWE-190 test change. 2019-05-24 16:16:45 +01:00
Geoffrey White
15e2248440 Merge pull request #1359 from jbj/definitions-column-order
C++: definitions.ql performance tweaks
2019-05-24 12:43:57 +01:00
Jonas Jensen
dd5a2552c7 C++: Compute locations only for elements in result
This gains some performance by not computing locations for all
expressions since we are only interested in calls and variable accesses.
The `Top::hasLocationInfo` predicate goes from 2m28s to 1m32s on
Chromium.
2019-05-22 15:52:49 +01:00
Jonas Jensen
81f627c1c4 C++: pragma[noopt] Top::hasLocationInfo perf tweak
This predicate was slow, mostly because it's just very large. A manual
join order cuts the run time on Chromium from

    definitions::Top::hasLocationInfo_dispred#ffffff ..................... 3m23s
    definitions::MacroAccessWithHasLocationInfo::hasLocationInfo#ffffff .. 1m56s

to

    definitions::Top::hasLocationInfo#ffffff .... 2m28s

The main slowdown was the two uses of `SCAN` to reorder columns in the
RA.
2019-05-22 15:52:33 +01:00
Ian Lynagh
6a77ac8a13 C++: Follow extractor changes for 0136 2019-05-21 17:07:21 +01:00
Robert Marsh
2dd1c06409 C++: fix use of getUnspecifiedType on Node 2019-05-21 11:06:15 +01:00
Geoffrey White
67527820a1 Merge pull request #1335 from EdoDodo/optimise-preprocessor
C++: Optimise quadratic code in PreprocessorBranchDirective
2019-05-20 15:58:33 +01:00
Robert Marsh
dbdaa1d3f3 C++: Replace getUnderlyingType().getUnspecifiedType() 2019-05-20 15:23:08 +01:00
Robert Marsh
e899120270 C++: replace getType().getUnspecifiedType() 2019-05-20 15:08:28 +01:00
Robert Marsh
a72fff7ed0 C++: add getUnspecifiedType() for exprs and decls 2019-05-20 14:49:19 +01:00
Anders Schack-Mulligen
9ebeac25ad Merge pull request #1329 from hvitved/dataflow/performance
Data flow: performance improvements
2019-05-20 14:27:03 +02:00
Edoardo Pirovano
30198c326d C++: Optimise quadratic code in PreprocessorBranchDirective 2019-05-20 12:57:47 +01:00
Tom Hvitved
bc00877ff2 Data flow: Add nomagic to storeCand() 2019-05-20 12:05:20 +02:00
Tom Hvitved
360c7a1ac5 Address review comments 2019-05-20 09:59:17 +02:00
Geoffrey White
36cd4d44d1 CPP: Cache Expr.getType(). 2019-05-17 16:18:41 +01:00
Robert Marsh
762c977be7 Merge pull request #1326 from jbj/addressConstantVariable-isConstexpr
C++: Use isConstexpr instead of workaround in AddressConstantExpr
2019-05-16 15:18:56 -07:00
Robert Marsh
5f77ac4cf5 Merge pull request #1325 from jbj/reachableRecursive
C++: reachableRecursive refactor for performance
2019-05-16 14:05:57 -07:00
Jonas Jensen
947aaa9e4e C++: reachableRecursive refactor for performance
The `reachable` predicate is large and slow to compute. It's part of a
mutual recursion that's non-linear, meaning it has a recursive call on
both sides of an `and`.

This change removes a part of the base case that has no effect on
recursive cases. The removed part is added back after the recursion has
finished.

Before, on Wireshark:

    ControlFlowGraph::Cached::reachable#f .......... 20.8s (executed 9800 times)
    ConstantExprs::successors_adapted#ff ........... 4.2s (executed 615 times)
    ConstantExprs::potentiallyReturningFunction#f .. 3.9s (executed 9799 times)
    ConstantExprs::possiblePredecessor#f ........... 2.9s (executed 788 times)

After, on Wireshark:

    ConstantExprs::reachableRecursive#f ............ 13.2s (executed 9800 times)
    ConstantExprs::successors_adapted#ff ........... 4.2s (executed 615 times)
    ConstantExprs::potentiallyReturningFunction#f .. 4.3s (executed 9799 times)
    ConstantExprs::possiblePredecessor#f ........... 2.6s (executed 788 times)

I've verified that this change doesn't change what's computed by
checking that the output of the following query is unchanged:

    import cpp
    import semmle.code.cpp.controlflow.internal.ConstantExprs

    select
      strictcount(ControlFlowNode n | reachable(n)) as reachable,
      strictcount(ControlFlowNode n1, ControlFlowNode n2 | n2 = n1.getASuccessor()) as edges,
      strictcount(FunctionCall c | aborting(c)) as abortingCall,
      strictcount(Function f | abortingFunction(f)) as abortingFunction
2019-05-16 13:39:23 +02:00
Jonas Jensen
db6a807ff6 C++: Move same-stage predicates into cached module
This change only moves code around -- there are no changes to predicate
bodies or signatures.

The predicates that go in `ConstantExprs.Cached` after this change were
already cached in the same stage or, in the case of the `aborting*`
predicates, did not need to be cached. This is a fortunate consequence
of how the mutual recursion between the predicates happens to work, and
it's not going to be the case after the next commit.
2019-05-16 13:34:50 +02:00
Tom Hvitved
02ca09aa43 Data flow: performance improvements 2019-05-16 07:35:10 +02:00
Robert Marsh
14795863e2 Merge pull request #1303 from jbj/hasQualifiedName
C++: Fix `getQualifiedName` performance issues
2019-05-15 12:42:57 -07:00
Jonas Jensen
d820fc9cd2 C++: Address review comments about the comments 2019-05-15 14:55:26 +02:00
Jonas Jensen
f38253da89 C++: Use isConstexpr instead of workaround
The `addressConstantVariable` predicate was the slowest single predicate
when running the full LGTM suite on Chromium. Fortunately it's only
executed once, but it could be easily made faster by using the new
`Variable.isConstexpr` predicate instead of the slow workaround that was
in its place.
2019-05-15 14:41:05 +02:00
Jonas Jensen
8b012b2cab C++: Remove unneeded import 2019-05-15 14:35:05 +02:00
Geoffrey White
4cc23cce13 CPP: Document. 2019-05-10 16:26:39 +01:00
Geoffrey White
581266c347 CPP: Alternative fix. 2019-05-10 16:26:38 +01:00
Jonas Jensen
639d715d03 Merge pull request #1226 from hvitved/dataflow/prepare-for-csharp
Generalize data-flow library in preparation for C# adoption
2019-05-06 14:42:46 +02:00
Jonas Jensen
b52015a584 C++: QLDoc for QualifiedName.qll 2019-05-06 11:28:56 +02:00
Jonas Jensen
56e88cbac0 C++: Use underlyingElement for QualifiedName calls
Since the types in `QualifiedName.qll` are raw db types, callers need to
use `underlyingElement` and `unresolveElement` as appropriate. This has
no effect right now but will be needed when we switch the AST type
hierarchy to `newtype`s.
2019-05-06 11:24:28 +02:00
Jonas Jensen
662d55fd72 C++: Add tests for qualified names 2019-05-06 10:58:05 +02:00
Tom Hvitved
d9bf0a670e Data flow: Address review comments 2019-05-03 15:00:48 +02:00
Jonas Jensen
b98daae077 C++: Remove deprecated from hasQualifiedName/1
The predicate is still deprecated, but we can't mark it as such until
the queries in our internal repo have migrated away from it.
2019-05-03 13:22:23 +02:00
Jonas Jensen
6d954fe53e C++: Deprecate hasQualifiedName/1
This predicate handles templates differently from the other overloads
with the same name, so it's likely to cause confusion.
2019-05-03 10:37:48 +02:00
Jonas Jensen
5e789901df C++: Remove all uses of hasQualifiedName/1 2019-05-03 10:37:48 +02:00
Jonas Jensen
64a87a863c C++: Remove uses of getQualifiedName
This removes all uses of `Declaration.getQualifiedName` that I think can
be removed without changing any behaviour. The following uses in the
LGTM default suite remain:

* `cpp/ql/src/Security/CWE/CWE-121/UnterminatedVarargsCall.ql` (in `select`).
* `cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowDispatch.qll` (needs template args).
* `cpp/ql/src/semmle/code/cpp/security/FunctionWithWrappers.qll` (used for alert messages).
2019-05-03 10:37:48 +02:00
Jonas Jensen
0a2e28858a C++: Rework how qualified names are computed 2019-05-03 10:37:48 +02:00
Jonas Jensen
b51ce87ae8 C++: Autoformat QualifiedName.qll 2019-05-03 10:37:47 +02:00
Jonas Jensen
b97ff1a72f C++: Take QualifiedName.qll from Ian's branch
This imports `QualifiedName.qll` from
2f74a456290b9e0850b7308582e07f5d68de3a36 and makes minimal changes so it
compiles.

Original author: Ian Lynagh <ian@semmle.com>
2019-05-03 10:37:12 +02:00
Jonas Jensen
93658038bc C++: Use a smaller double literal in test
This number got rounded differently on Linux and Windows, causing the
Windows test to fail.
2019-05-03 09:06:10 +02:00
Tom Hvitved
b6206d7370 Data flow: Introduce ReturnKind 2019-05-02 20:30:50 +02:00
Dave Bartolomeo
7071692373 C++: Clarify comment based on PR feedback 2019-05-02 11:18:10 -07:00
Dave Bartolomeo
34a422c756 C++: Accept test output after value category extractor fix 2019-05-02 11:18:10 -07:00
Dave Bartolomeo
ad966e4bd4 C++: Accept test diffs after imprecise use format change 2019-05-02 11:18:09 -07:00
Dave Bartolomeo
fef58ec1ee C++: Add "~" prefix to inexact uses 2019-05-02 11:18:09 -07:00