Skip to content

Commit 959237e

Browse files
committed
C++: Fix missing type for Phi nodes.
1 parent 2963dc1 commit 959237e

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Node0Impl extends TIRDataFlowNode0 {
4343
/**
4444
* Gets the type of this node.
4545
*
46-
* If `asInstruction().isGLValue()` holds, then the type of this node
46+
* If `isGLValue()` holds, then the type of this node
4747
* should be thought of as "pointer to `getType()`".
4848
*/
4949
DataFlowType getType() { none() } // overridden in subclasses

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,14 @@ class SsaPhiNode extends Node, TSsaPhiNode {
498498

499499
override Declaration getFunction() { result = phi.getBasicBlock().getEnclosingFunction() }
500500

501-
override DataFlowType getType() { result = this.getAnInput().getType().getUnspecifiedType() }
501+
override DataFlowType getType() {
502+
exists(Ssa::SourceVariable sv |
503+
this.getPhiNode().definesAt(sv, _, _, _) and
504+
result = sv.getType()
505+
)
506+
}
507+
508+
override predicate isGLValue() { phi.getSourceVariable().isGLValue() }
502509

503510
final override Location getLocationImpl() { result = phi.getBasicBlock().getLocation() }
504511

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternals.qll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ private module SourceVariables {
4848
* indirections) of this source variable.
4949
*/
5050
abstract BaseSourceVariable getBaseVariable();
51+
52+
/** Holds if this variable is a glvalue. */
53+
predicate isGLValue() { none() }
54+
55+
/**
56+
* Gets the type of this source variable. If `isGLValue()` holds, then
57+
* the type of this source variable should be thought of as "pointer
58+
* to `getType()`".
59+
*/
60+
abstract DataFlowType getType();
5161
}
5262

5363
class SourceIRVariable extends SourceVariable, TSourceIRVariable {
@@ -66,6 +76,12 @@ private module SourceVariables {
6676
ind > 0 and
6777
result = this.getIRVariable().toString() + " indirection"
6878
}
79+
80+
override predicate isGLValue() { ind = 0 }
81+
82+
override DataFlowType getType() {
83+
if ind = 0 then result = var.getType() else result = getTypeImpl(var.getType(), ind - 1)
84+
}
6985
}
7086

7187
class CallVariable extends SourceVariable, TCallVariable {
@@ -84,6 +100,8 @@ private module SourceVariables {
84100
ind > 0 and
85101
result = "Call indirection"
86102
}
103+
104+
override DataFlowType getType() { result = getTypeImpl(call.getResultType(), ind) }
87105
}
88106
}
89107

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
failures
22
astTypeBugs
33
irTypeBugs
4-
| test.cpp:15:3:15:6 | test.cpp:15:3:15:6 | test.cpp:15:3:15:6 | Phi |
5-
| test.cpp:43:10:43:20 | test.cpp:43:10:43:20 | test.cpp:43:10:43:20 | Phi |
6-
| test.cpp:43:10:43:20 | test.cpp:43:10:43:20 | test.cpp:43:10:43:20 | Phi |
7-
| test.cpp:628:3:628:18 | test.cpp:628:3:628:18 | test.cpp:628:3:628:18 | Phi |
8-
| test.cpp:628:3:628:18 | test.cpp:628:3:628:18 | test.cpp:628:3:628:18 | Phi |

0 commit comments

Comments
 (0)