Skip to content

Commit f92f84e

Browse files
committed
Merge remote-tracking branch 'upstream/main' into BlockStmt
2 parents 0935d1e + 075ce6e commit f92f84e

File tree

7 files changed

+4384
-73
lines changed

7 files changed

+4384
-73
lines changed

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,3 +1268,31 @@ class SpaceshipExpr extends BinaryOperation, @spaceshipexpr {
12681268

12691269
override string getOperator() { result = "<=>" }
12701270
}
1271+
1272+
/**
1273+
* A C/C++ `co_await` expression.
1274+
* ```
1275+
* co_await foo();
1276+
* ```
1277+
*/
1278+
class CoAwaitExpr extends UnaryOperation, @co_await {
1279+
override string getAPrimaryQlClass() { result = "CoAwaitExpr" }
1280+
1281+
override string getOperator() { result = "co_await" }
1282+
1283+
override int getPrecedence() { result = 16 }
1284+
}
1285+
1286+
/**
1287+
* A C/C++ `co_yield` expression.
1288+
* ```
1289+
* co_yield 1;
1290+
* ```
1291+
*/
1292+
class CoYieldExpr extends UnaryOperation, @co_yield {
1293+
override string getAPrimaryQlClass() { result = "CoYieldExpr" }
1294+
1295+
override string getOperator() { result = "co_yield" }
1296+
1297+
override int getPrecedence() { result = 2 }
1298+
}

cpp/ql/src/semmle/code/cpp/stmts/Stmt.qll

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,67 @@ class LabelStmt extends Stmt, @stmt_label {
662662
override predicate mayBeGloballyImpure() { none() }
663663
}
664664

665+
/**
666+
* A C/C++ `co_return` statement.
667+
*
668+
* For example:
669+
* ```
670+
* co_return 1+2;
671+
* ```
672+
* or
673+
* ```
674+
* co_return;
675+
* ```
676+
*/
677+
class CoReturnStmt extends Stmt, @stmt_co_return {
678+
override string getAPrimaryQlClass() { result = "CoReturnStmt" }
679+
680+
/**
681+
* Gets the operand of this 'co_return' statement.
682+
*
683+
* For example, for
684+
* ```
685+
* co_return 1+2;
686+
* ```
687+
* the operand is a function call `return_value(1+2)`, and for
688+
* ```
689+
* co_return;
690+
* ```
691+
* the operand is a function call `return_void()`.
692+
*/
693+
FunctionCall getOperand() { result = this.getChild(0) }
694+
695+
/**
696+
* Gets the expression of this 'co_return' statement, if any.
697+
*
698+
* For example, for
699+
* ```
700+
* co_return 1+2;
701+
* ```
702+
* the result is `1+2`, and there is no result for
703+
* ```
704+
* co_return;
705+
* ```
706+
*/
707+
Expr getExpr() { result = this.getOperand().getArgument(0) }
708+
709+
/**
710+
* Holds if this 'co_return' statement has an expression.
711+
*
712+
* For example, this holds for
713+
* ```
714+
* co_return 1+2;
715+
* ```
716+
* but not for
717+
* ```
718+
* co_return;
719+
* ```
720+
*/
721+
predicate hasExpr() { exists(this.getExpr()) }
722+
723+
override string toString() { result = "co_return ..." }
724+
}
725+
665726
/**
666727
* A C/C++ 'return' statement.
667728
*

cpp/ql/src/semmlecode.cpp.dbscheme

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,8 @@ funbind(
12281228
| @builtinaddressof
12291229
| @vec_fill
12301230
| @un_log_op_expr
1231+
| @co_await
1232+
| @co_yield
12311233
;
12321234

12331235
@bin_log_op_expr = @andlogicalexpr | @orlogicalexpr;
@@ -1647,6 +1649,8 @@ case @expr.kind of
16471649
| 324 = @builtinconvertvector
16481650
| 325 = @builtincomplex
16491651
| 326 = @spaceshipexpr
1652+
| 327 = @co_await
1653+
| 328 = @co_yield
16501654
;
16511655

16521656
@var_args_expr = @vastartexpr
@@ -1851,6 +1855,7 @@ case @stmt.kind of
18511855
| 33 = @stmt_handler
18521856
// ... 34 @stmt_finally_end deprecated
18531857
| 35 = @stmt_constexpr_if
1858+
| 37 = @stmt_co_return
18541859
;
18551860

18561861
type_vla(

0 commit comments

Comments
 (0)