Commit Graph

3597 Commits

Author SHA1 Message Date
Mathias Vorreiter Pedersen
1dd5926f41 C++: Generalize new case in adjustedSink to all AssignOperations 2020-02-11 17:15:42 +01:00
Geoffrey White
75a50a1714 C++: Understand formatting function varargs as needing null termination. 2020-02-11 15:25:59 +00:00
Geoffrey White
de8d84dfff C++: Clearer comments in NoSpaceForZeroTerminator.ql. 2020-02-11 15:25:59 +00:00
Geoffrey White
2f290bd528 C++: Additional test cases. 2020-02-11 15:25:59 +00:00
Robert Marsh
d672f8f863 C++: unflip cause strings in FunctionWithWrapper 2020-02-10 15:57:38 -08:00
Robert Marsh
d09f78db29 C++: fix cartesian product in FunctionWithWrapper 2020-02-10 13:02:58 -08:00
Dave Bartolomeo
405850e02b Merge pull request #2805 from jbj/dataflow-sideeffect-join
C++: IR DataFlowUtil::modelFlow join order fix
2020-02-10 13:04:51 -07:00
Robert Marsh
58bba86be4 C++: autoformat 2020-02-10 09:52:23 -08:00
Mathias Vorreiter Pedersen
bcd84efe8d C++: Add += and friends to adjustedSink 2020-02-10 15:50:52 +01:00
Jonas Jensen
cf1bc693b4 C++: Fix coversEntireVariable perf in AliasedSSA
This predicate got an unfortunate join order, leading to these tuple
counts on ElektraInitiative/libelektra:

    (290s) Tuple counts for AliasedSSA::VariableMemoryLocation::coversEntireVariable_dispred#f:
    57117     ~0%     {3} r1 = SCAN IRType::IRType::getByteSize_dispred#ff AS I OUTPUT 0, (I.<1> * 8), I.<0>
    421445272 ~0%     {3} r2 = JOIN r1 WITH AliasedSSA::VariableMemoryLocation#fffffff_5601#join_rhs AS R ON FIRST 2 OUTPUT R.<3>, r1.<2>, R.<2>
    103282    ~2%     {1} r3 = JOIN r2 WITH AliasConfiguration::Allocation::getIRType_dispred#ff AS R ON FIRST 2 OUTPUT r2.<2>
                      return r3

With this commit, we get these tuple counts instead:

    (0s) Tuple counts for AliasedSSA::VariableMemoryLocation::varIRTypeHasBitRange#bff:
    361874 ~0%     {3} r1 = SCAN AliasedSSA::VariableMemoryLocation#fffffff AS I OUTPUT I.<1>, 0, I.<0>
    361874 ~0%     {3} r2 = JOIN r1 WITH AliasConfiguration::Allocation::getIRType_dispred#ff AS R ON FIRST 1 OUTPUT R.<1>, 0, r1.<2>
    361874 ~1%     {3} r3 = JOIN r2 WITH IRType::IRType::getByteSize_dispred#ff AS R ON FIRST 1 OUTPUT r2.<2>, 0, (R.<1> * 8)
                   return r3

    (0s) Tuple counts for AliasedSSA::VariableMemoryLocation::coversEntireVariable_dispred#f:
    103282 ~2%     {1} r1 = JOIN AliasedSSA::VariableMemoryLocation#fffffff_056#join_rhs AS L WITH AliasedSSA::VariableMemoryLocation::varIRTypeHasBitRange#bff AS R ON FIRST 3 OUTPUT L.<0>
    103282 ~2%     {1} r2 = STREAM DEDUP r1
                   return r2
2020-02-10 15:18:34 +01:00
Jonas Jensen
47c12817ad C++: IR DataFlowUtil::modelFlow join order fix
We had these tuple counts on ElektraInitiative/libelektra (note that the
`modelFlow` predicate got inlined into
`simpleInstructionLocalFlowStep`):

    (652s) Tuple counts for DataFlowUtil::simpleInstructionLocalFlowStep#ff:
    ...
    19701      ~1%      {4} r27 = JOIN r26 WITH Instruction::SideEffectInstruction::getPrimaryInstruction_dispred#3#ff_10#join_rhs AS R ON FIRST 1 OUTPUT R.<1>, r26.<2>, r26.<1>, r26.<0>
    7908       ~0%      {3} r28 = JOIN r27 WITH SSAConstruction::Cached::getInstructionIndex#ff@staged_ext AS R ON FIRST 2 OUTPUT r27.<0>, r27.<2>, r27.<3>
    4023       ~0%      {3} r29 = JOIN r28 WITH Instruction::WriteSideEffectInstruction#class#ff AS R ON FIRST 1 OUTPUT r28.<1>, r28.<2>, r28.<0>
    ...
    1060807009 ~3%      {3} r34 = JOIN r33 WITH SSAConstruction::Cached::getInstructionIndex#ff_10#join_rhs AS R ON FIRST 1 OUTPUT R.<1>, r33.<1>, r33.<2>
    15670      ~5%      {2} r35 = JOIN r34 WITH Instruction::SideEffectInstruction::getPrimaryInstruction_dispred#3#ff AS R ON FIRST 2 OUTPUT r34.<0>, r34.<2>
    7973       ~0%      {2} r36 = JOIN r35 WITH Instruction::ReadSideEffectInstruction::getSideEffectOperand_dispred#ff AS R ON FIRST 1 OUTPUT R.<1>, r35.<1>
    ...

In this predicate there are two cases (`WriteSideEffectInstruction` and
`ReadSideEffectInstruction`) where we need to join on both the call and
the argument index of a side effect. It works well enough for the first
case, `WriteSideEffectInstruction`, where the call is joined on before
the index, but it explodes in the second case,
`ReadSideEffectInstruction`, where the index is joined first. To fix the
second case, and to guard against future optimizer accidents in the
first case, this commit changes both of those cases to use a new helper
predicate that makes it possible to join on both columns at once. The
resulting tuple counts are:

    (3s) Tuple counts for DataFlowUtil::simpleInstructionLocalFlowStep#ff:
    ...
    7908    ~0%      {3} r27 = JOIN r26 WITH DataFlowUtil::getSideEffectFor#fff AS R ON FIRST 2 OUTPUT R.<2>, r26.<2>, r26.<0>
    4023    ~0%      {3} r28 = JOIN r27 WITH Instruction::WriteSideEffectInstruction#class#ff AS R ON FIRST 1 OUTPUT r27.<1>, r27.<2>, r27.<0>
    ...
    15670   ~5%      {2} r33 = JOIN r32 WITH DataFlowUtil::getSideEffectFor#fff AS R ON FIRST 2 OUTPUT R.<2>, r32.<2>
    7973    ~0%      {2} r34 = JOIN r33 WITH Instruction::ReadSideEffectInstruction::getSideEffectOperand_dispred#ff AS R ON FIRST 1 OUTPUT R.<1>, r33.<1>
    ...

The bulge is now limited to a factor of two, and that's just because I
didn't write separate versions of `getSideEffectFor` for
`ReadSideEffectInstruction` and `WriteSideEffectInstruction`.
2020-02-10 15:11:30 +01:00
Mathias Vorreiter Pedersen
99a9d7f676 C++: Simplify 2020-02-10 13:01:40 +01:00
Mathias Vorreiter Pedersen
6804018a64 C++: Accept output 2020-02-10 11:37:40 +01:00
Mathias Vorreiter Pedersen
522c629441 C++: Move fix to adjustedSink to avoid generating too many instructions 2020-02-10 11:37:26 +01:00
Mathias Vorreiter Pedersen
52bc25b608 C++: Accept output 2020-02-10 08:50:29 +01:00
Mathias Vorreiter Pedersen
bb30275e2e C++: Fix false negatives for postfix crement expressions 2020-02-09 21:35:07 +01:00
Tom Hvitved
9b699618a8 Data flow: Improve performance of flowFwdStore() 2020-02-09 19:34:04 +01:00
Robert Marsh
3266a89023 C++: document DynamicAllocationInstruction 2020-02-07 16:56:57 -08:00
Robert Marsh
7f69cdfb56 C++: Dynamic allocations in IR alias analysis 2020-02-07 16:37:36 -08:00
Robert Marsh
05c8610bbc C++: tests for alias analysis of malloc 2020-02-07 16:35:58 -08:00
Robert Marsh
68097116b0 C++:autoformat 2020-02-07 15:51:23 -08:00
Robert Marsh
d1d19a7446 Merge branch 'master' into rdmarsh/cpp/ir-flow-through-outparams
Update test expectations
2020-02-07 12:24:05 -08:00
Agustin Gianni
033eeab41e cpp: Adds a member predicate to get a FunctionAccess from a Function
- Adds a member predicate to get a FunctionAccess from a Function
- Adds QLDoc to getACallToThisFunction.
2020-02-07 16:45:14 +01:00
Tom Hvitved
f30a42ce26 Data flow: Fix bad join-order in TPathNodeSink
Avoids a Cartesian product on nodes:

```
[2020-02-07 11:01:22] (432s) Tuple counts for dom#DataFlowImpl::TPathNodeSink#ff:
                      0          ~0%      {2} r1 = JOIN DataFlowImpl::Configuration::isSource_dispred#ff AS L WITH DataFlowImpl::Configuration::isSink_dispred#ff AS R ON FIRST 2 OUTPUT R.<1>, R.<0>
                      101611     ~0%      {2} r2 = SCAN DataFlowImpl::PathNodeMid#class#ffffff AS I OUTPUT I.<5>, I.<0>
                      3534537047 ~3%      {3} r3 = JOIN r2 WITH DataFlowImpl::Configuration::isSink_dispred#ff AS R ON FIRST 1 OUTPUT r2.<1>, R.<1>, R.<0>
                      251        ~41%     {3} r4 = JOIN r3 WITH project#DataFlowImpl::pathStep#fffff AS R ON FIRST 2 OUTPUT R.<2>, r3.<2>, r3.<1>
                      251        ~50%     {2} r5 = JOIN r4 WITH DataFlowImpl::TNil#ff_1#join_rhs AS R ON FIRST 1 OUTPUT r4.<2>, r4.<1>
                      251        ~50%     {2} r6 = r1 \/ r5
                      323        ~67%     {3} r7 = JOIN r6 WITH DataFlowImpl::flow#ff AS R ON FIRST 1 OUTPUT r6.<1>, r6.<0>, R.<1>
                      288        ~58%     {3} r8 = SELECT r7 ON r7.<2> >= r7.<0>
                      251        ~53%     {3} r9 = SELECT r8 ON r8.<2> <= r8.<0>
                      251        ~50%     {2} r10 = SCAN r9 OUTPUT r9.<1>, r9.<0>
```
2020-02-07 12:08:31 +01:00
Jonas Jensen
19286bd82a Merge pull request #2765 from MathiasVP/ir-gvn-ast-wrapper-fixup
C++: Make AST GVN a wrapper for IR-based GVN
2020-02-07 08:49:15 +01:00
Robert Marsh
dac4f0fac0 Merge pull request #2763 from jbj/ir-VariableNode
C++: DefaultTaintTracking perf fix for globals
2020-02-06 18:54:14 -05:00
Robert Marsh
2d3a742b7f C++: autoformat and accept test changes 2020-02-06 13:41:00 -08:00
Robert Marsh
692207472a Merge branch 'master' into rdmarsh/cpp/ir-flow-through-outparams 2020-02-06 11:42:30 -08:00
Tom Hvitved
b3af3ad12f Data flow: Fix bad join order in getReturnPosition()
Joining on the enclosing callable before the kind is crucial, as witnessed by this pipeline:

```
[2020-02-06 17:58:21] (1086s) Starting to evaluate predicate DataFlowImplCommon::getReturnPosition#ff/2@83c546
[2020-02-06 18:53:16] (4382s) Tuple counts for DataFlowImplCommon::getReturnPosition#ff:
                      385478      ~1%     {3} r1 = SCAN DataFlowImplCommon::Cached::TReturnPosition0#fff@staged_ext AS I OUTPUT I.<2>, I.<0>, I.<1>
                      385478      ~2%     {3} r2 = JOIN r1 WITH DataFlowImplCommon::Cached::TReturnPosition0#fff_2#join_rhs AS R ON FIRST 1 OUTPUT r1.<2>, r1.<1>, r1.<0>
                      58638116860 ~0%     {3} r3 = JOIN r2 WITH DataFlowImplCommon::ReturnNodeExt::getKind_dispred#ff_10#join_rhs AS R ON FIRST 1 OUTPUT R.<1>, r2.<1>, r2.<2>
                      914049      ~0%     {2} r4 = JOIN r3 WITH DataFlowImplCommon::returnNodeGetEnclosingCallable#ff AS R ON FIRST 2 OUTPUT r3.<0>, r3.<2>
                                          return r4
```
2020-02-06 19:06:40 +01:00
Mathias Vorreiter Pedersen
538c2b205d C++: Accept output 2020-02-06 18:44:08 +01:00
Mathias Vorreiter Pedersen
f02513e376 C++: Exclude UnknownLocation results from getLocation if there is a location that's known 2020-02-06 15:53:22 +01:00
Mathias Vorreiter Pedersen
23ca363b87 C++: Formatting 2020-02-06 15:53:22 +01:00
Mathias Vorreiter Pedersen
98969e3bf9 C++: Accepted ir_gvn output after toString change 2020-02-06 15:53:22 +01:00
Mathias Vorreiter Pedersen
0d181a7101 C++: Add tests and accept output 2020-02-06 15:48:08 +01:00
Mathias Vorreiter Pedersen
69e085dda7 C++: Add getDebugString predicate and use it in ValueNumberPropertyProvider 2020-02-06 15:43:57 +01:00
Mathias Vorreiter Pedersen
ef89e3bdb5 C++: Added charpred to ensure that only instructions that have a source representation have a GVN 2020-02-06 15:43:57 +01:00
Mathias Vorreiter Pedersen
63f1d3ded7 C++: Replace rank[1] with min 2020-02-06 15:43:57 +01:00
Mathias Vorreiter Pedersen
2303dac0b7 C++: Implemented getKind to new GVN class and added predicates for obtaining expressions from a GVN 2020-02-06 15:43:57 +01:00
Robert Marsh
2f91778e7e C++: add IR-based wrapper for value numbering 2020-02-06 15:35:20 +01:00
Robert Marsh
ffaaed0550 C++: separate IR ValueNumber newtype and interface 2020-02-06 15:35:20 +01:00
Jonas Jensen
4997aa7428 Merge pull request #2772 from MathiasVP/more-gvn-loads
C++: Better value numbering support for loading fields in IR
2020-02-06 14:15:27 +01:00
Jonas Jensen
2e883ab4b2 Merge pull request #2760 from geoffw0/defaulttainttest3
C++: Emulate old security library's use of predictable more accurately.
2020-02-06 13:47:27 +01:00
Mathias Vorreiter Pedersen
19e1d82708 Merge pull request #2686 from jbj/ir-crement-load
C++: Move the LoadInstruction from `++` to `e` in `e++`.
2020-02-06 11:53:55 +01:00
Mathias Vorreiter Pedersen
aaa6233a99 C++/C#: Sync identical files 2020-02-06 11:24:07 +01:00
Mathias Vorreiter Pedersen
527181bb6f C++: Rename CongruentCopyInstructionTotal to LoadTotalOverlapInstruction and extend LoadInstruction instead of CopyInstruction 2020-02-06 11:23:42 +01:00
Geoffrey White
2dfeafac30 C++: Interaction with another PR. 2020-02-06 10:21:55 +00:00
Geoffrey White
851c1134f3 C++: Add 'strlen' back. 2020-02-06 10:17:37 +00:00
Geoffrey White
860d0aa42f C++: Remove single argument functions. 2020-02-06 10:17:37 +00:00
Geoffrey White
539d6716f5 C++: Remove commented entries. 2020-02-06 10:17:37 +00:00
Geoffrey White
d54d7e8410 C++: Post-merge fix. 2020-02-06 10:17:37 +00:00