Skip to content

Commit 2303dac

Browse files
committed
C++: Implemented getKind to new GVN class and added predicates for obtaining expressions from a GVN
1 parent 8041804 commit 2303dac

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

cpp/ql/src/semmle/code/cpp/ir/internal/ASTValueNumbering.qll

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class GVN extends TValueNumber {
5656
final string toString() { result = "GVN" }
5757

5858
final Location getLocation() {
59-
result = rank[1](Location l |
59+
result =
60+
rank[1](Location l |
6061
l = getAnExpr().getLocation()
6162
|
6263
l
@@ -66,8 +67,36 @@ class GVN extends TValueNumber {
6667
)
6768
}
6869

70+
final string getKind() {
71+
this instanceof TVariableAddressValueNumber and result = "VariableAddress"
72+
or
73+
this instanceof TInitializeParameterValueNumber and result = "InitializeParameter"
74+
or
75+
this instanceof TInitializeThisValueNumber and result = "InitializeThis"
76+
or
77+
this instanceof TStringConstantValueNumber and result = "StringConstant"
78+
or
79+
this instanceof TFieldAddressValueNumber and result = "FieldAddress"
80+
or
81+
this instanceof TBinaryValueNumber and result = "Binary"
82+
or
83+
this instanceof TPointerArithmeticValueNumber and result = "PointerArithmetic"
84+
or
85+
this instanceof TUnaryValueNumber and result = "Unary"
86+
or
87+
this instanceof TInheritanceConversionValueNumber and result = "InheritanceConversion"
88+
or
89+
this instanceof TUniqueValueNumber and result = "Unique"
90+
}
91+
92+
/** Gets an expression that has this GVN. */
93+
Expr getAnExpr() { result = getAnUnconvertedExpr() }
94+
95+
/** Gets an expression that has this GVN. */
96+
Expr getAnUnconvertedExpr() { result = getAnInstruction().getUnconvertedResultExpression() }
97+
6998
/** Gets an expression that has this GVN. */
70-
Expr getAnExpr() { result = getAnInstruction().getConvertedResultExpression() }
99+
Expr getAConvertedExpr() { result = getAnInstruction().getConvertedResultExpression() }
71100
}
72101

73102
/** Gets the global value number of expression `e`. */

0 commit comments

Comments
 (0)