Skip to content

Commit 9f8c961

Browse files
committed
C++: Use the unconverted expression available for a non-'ExprNode' when one exists.
1 parent b201fd0 commit 9f8c961

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@
33
* `toString` for `Instruction` and `Operand` dataflow nodes.
44
*/
55

6+
private import cpp
67
private import semmle.code.cpp.ir.IR
78
private import codeql.util.Unit
89
private import Node0ToString
910
private import DataFlowUtil
1011
private import DataFlowPrivate
1112

13+
/**
14+
* Gets the string representation of the unconverted expression `loc` if
15+
* `loc` is an `Expression`.
16+
*
17+
* Otherwise, this gets the string representation of `loc`.
18+
*/
19+
private string unconvertedAstToString(Locatable loc) {
20+
result = loc.(Expr).getUnconverted().toString()
21+
or
22+
not loc instanceof Expr and
23+
result = loc.toString()
24+
}
25+
1226
private class NormalNode0ToString extends Node0ToString {
1327
NormalNode0ToString() {
1428
// Silence warning about `this` not being bound.
@@ -18,14 +32,10 @@ private class NormalNode0ToString extends Node0ToString {
1832
override string instructionToString(Instruction i) {
1933
if i.(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
2034
then result = "this"
21-
else result = i.getAst().toString()
35+
else result = unconvertedAstToString(i.getAst())
2236
}
2337

24-
override string operandToString(Operand op) {
25-
if op.getDef().(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
26-
then result = "this"
27-
else result = op.getDef().getAst().toString()
28-
}
38+
override string operandToString(Operand op) { result = this.instructionToString(op.getDef()) }
2939

3040
override string toExprString(Node n) {
3141
result = n.asExpr(0).toString()

0 commit comments

Comments
 (0)