C++: Add TranslatedElement::isIRConstant

Now that there exist constants with no QL-representable value, we need
to make sure they're not treated as constants in the IR.
This commit is contained in:
Jonas Jensen
2019-01-15 17:34:56 +01:00
parent 3edadc311f
commit d81e6e9bb8
2 changed files with 12 additions and 5 deletions

View File

@@ -49,6 +49,13 @@ private Element getRealParent(Expr expr) {
)
}
/**
* Holds if `expr` is a constant of a type that can be replaced directly with
* its value in the IR. This does not include address constants as we have no
* means to express those as QL values.
*/
predicate isIRConstant(Expr expr) { exists(expr.getValue()) }
/**
* Holds if `expr` and all of its descendants should be ignored for the purposes
* of IR generation due to some property of `expr` itself. Unlike
@@ -63,7 +70,7 @@ private predicate ignoreExprAndDescendants(Expr expr) {
getRealParent(expr) instanceof SwitchCase or
// Ignore descendants of constant expressions, since we'll just substitute the
// constant value.
getRealParent(expr).(Expr).isConstant() or
isIRConstant(getRealParent(expr)) or
// The `DestructorCall` node for a `DestructorFieldDestruction` has a `FieldAccess`
// node as its qualifier, but that `FieldAccess` does not have a child of its own.
// We'll ignore that `FieldAccess`, and supply the receiver as part of the calling
@@ -146,7 +153,7 @@ private predicate translateStmt(Stmt stmt) {
*/
private predicate isNativeCondition(Expr expr) {
expr instanceof BinaryLogicalOperation and
not expr.isConstant()
not isIRConstant(expr)
}
/**
@@ -159,7 +166,7 @@ private predicate isFlexibleCondition(Expr expr) {
expr instanceof NotExpr
) and
usedAsCondition(expr) and
not expr.isConstant()
not isIRConstant(expr)
}
/**

View File

@@ -962,7 +962,7 @@ class TranslatedFunctionAccess extends TranslatedNonConstantExpr {
abstract class TranslatedNonConstantExpr extends TranslatedCoreExpr {
TranslatedNonConstantExpr() {
this = TTranslatedValueExpr(expr) and
not expr.isConstant()
not isIRConstant(expr)
}
}
@@ -974,7 +974,7 @@ abstract class TranslatedNonConstantExpr extends TranslatedCoreExpr {
abstract class TranslatedConstantExpr extends TranslatedCoreExpr {
TranslatedConstantExpr() {
this = TTranslatedValueExpr(expr) and
expr.isConstant()
isIRConstant(expr)
}
override final Instruction getFirstInstruction() {