mirror of
https://github.com/github/codeql.git
synced 2026-05-01 19:55:15 +02:00
C++: Add ConditionDeclExpr convenience predicates
Also expand the QLDoc.
This commit is contained in:
@@ -60,7 +60,7 @@ predicate nullCheckInCondition(Expr e, Variable v, Declaration qualifier) {
|
||||
or exists(NotExpr exp | exp = e and nullCheckInCondition(exp.getAnOperand(), v, qualifier))
|
||||
or exists(FunctionCall c | c = e and nullCheckInCondition(c.getAnArgument(), v, qualifier) and
|
||||
c.getTarget().getName() = "__builtin_expect")
|
||||
or exists(ConditionDeclExpr d | d = e and nullCheckInCondition(d.getExpr(), v, qualifier))
|
||||
or exists(ConditionDeclExpr d | d = e and nullCheckInCondition(d.getVariableAccess(), v, qualifier))
|
||||
}
|
||||
|
||||
predicate hasNullCheck(Function enclosing, Variable v, Declaration qualifier) {
|
||||
|
||||
@@ -144,13 +144,30 @@ class AssignPointerSubExpr extends AssignOperation, @assignpsubexpr {
|
||||
/**
|
||||
* A C++ variable declaration in an expression where a condition is expected.
|
||||
* For example, on the `ConditionDeclExpr` in `if (bool c = x < y)`,
|
||||
* `getExpr()` is an access to `c` (with possible casts), and `getVariable` is
|
||||
* the variable `c`, which has an initializer `x < y`.
|
||||
* `getVariableAccess()` is an access to `c` (with possible casts),
|
||||
* `getVariable` is the variable `c`, which has an initializer `x < y`, and
|
||||
* `getInitializingExpr` is `x < y`.
|
||||
*/
|
||||
class ConditionDeclExpr extends Expr, @condition_decl {
|
||||
/** Gets the access using the condition for this declaration. */
|
||||
/**
|
||||
* DEPRECATED: Use `getVariableAccess` or `getInitializingExpr` instead.
|
||||
* Gets the access using the condition for this declaration.
|
||||
*/
|
||||
deprecated
|
||||
Expr getExpr() { result = this.getChild(0) }
|
||||
|
||||
/**
|
||||
* Gets the compiler-generated variable access that conceptually occurs after
|
||||
* the initialization of the declared variable.
|
||||
*/
|
||||
VariableAccess getVariableAccess() { result = this.getChild(0) }
|
||||
|
||||
/**
|
||||
* Gets the expression that initializes the declared variable. This predicate
|
||||
* always has a result.
|
||||
*/
|
||||
Expr getInitializingExpr() { result = this.getVariable().getInitializer().getExpr() }
|
||||
|
||||
/** Gets the variable that is declared. */
|
||||
Variable getVariable() { condition_decl_bind(underlyingElement(this),unresolveElement(result)) }
|
||||
|
||||
|
||||
@@ -2691,6 +2691,6 @@ class TranslatedConditionDeclExpr extends TranslatedNonConstantExpr {
|
||||
}
|
||||
|
||||
private TranslatedExpr getConditionExpr() {
|
||||
result = getTranslatedExpr(condDeclExpr.getExpr().getFullyConverted())
|
||||
result = getTranslatedExpr(condDeclExpr.getVariableAccess().getFullyConverted())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user