From 2303dac0b7f669dcdeffa0175029ffafa04b97f4 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Wed, 5 Feb 2020 11:16:57 +0100 Subject: [PATCH] C++: Implemented getKind to new GVN class and added predicates for obtaining expressions from a GVN --- .../cpp/ir/internal/ASTValueNumbering.qll | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/cpp/ql/src/semmle/code/cpp/ir/internal/ASTValueNumbering.qll b/cpp/ql/src/semmle/code/cpp/ir/internal/ASTValueNumbering.qll index 7a09f47ac5d..c3e2f66594e 100644 --- a/cpp/ql/src/semmle/code/cpp/ir/internal/ASTValueNumbering.qll +++ b/cpp/ql/src/semmle/code/cpp/ir/internal/ASTValueNumbering.qll @@ -56,7 +56,8 @@ class GVN extends TValueNumber { final string toString() { result = "GVN" } final Location getLocation() { - result = rank[1](Location l | + result = + rank[1](Location l | l = getAnExpr().getLocation() | l @@ -66,8 +67,36 @@ class GVN extends TValueNumber { ) } + final string getKind() { + this instanceof TVariableAddressValueNumber and result = "VariableAddress" + or + this instanceof TInitializeParameterValueNumber and result = "InitializeParameter" + or + this instanceof TInitializeThisValueNumber and result = "InitializeThis" + or + this instanceof TStringConstantValueNumber and result = "StringConstant" + or + this instanceof TFieldAddressValueNumber and result = "FieldAddress" + or + this instanceof TBinaryValueNumber and result = "Binary" + or + this instanceof TPointerArithmeticValueNumber and result = "PointerArithmetic" + or + this instanceof TUnaryValueNumber and result = "Unary" + or + this instanceof TInheritanceConversionValueNumber and result = "InheritanceConversion" + or + this instanceof TUniqueValueNumber and result = "Unique" + } + /** Gets an expression that has this GVN. */ - Expr getAnExpr() { result = getAnInstruction().getConvertedResultExpression() } + Expr getAnExpr() { result = getAnUnconvertedExpr() } + + /** Gets an expression that has this GVN. */ + Expr getAnUnconvertedExpr() { result = getAnInstruction().getUnconvertedResultExpression() } + + /** Gets an expression that has this GVN. */ + Expr getAConvertedExpr() { result = getAnInstruction().getConvertedResultExpression() } } /** Gets the global value number of expression `e`. */