Skip to content

Commit dd41538

Browse files
authored
Merge pull request #21142 from MathiasVP/ir-support-for-assertions
C++: Generate IR for assertions in release builds
2 parents 6ae1ea7 + 64a7d7d commit dd41538

File tree

14 files changed

+1688
-7
lines changed

14 files changed

+1688
-7
lines changed

cpp/ql/lib/semmle/code/cpp/Element.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ class Element extends ElementBase {
192192
*/
193193
predicate isAffectedByMacro() { affectedByMacro(this) }
194194

195+
/**
196+
* INTERNAL: Do not use.
197+
*
198+
* Holds if this element is affected by the expansion of `mi`.
199+
*/
200+
predicate isAffectedByMacro(MacroInvocation mi) {
201+
affectedbymacroexpansion(underlyingElement(this), unresolveElement(mi))
202+
}
203+
195204
private Element getEnclosingElementPref() {
196205
enclosingfunction(underlyingElement(this), unresolveElement(result)) or
197206
result.(Function) = stmtEnclosingElement(this) or

cpp/ql/lib/semmle/code/cpp/Macro.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ class MacroInvocation extends MacroAccess {
239239
macro_argument_unexpanded(underlyingElement(this), i, result)
240240
}
241241

242+
/** Gets the number of arguments for this macro invocation. */
243+
int getNumberOfArguments() { result = count(int i | exists(this.getUnexpandedArgument(i)) | i) }
244+
242245
/**
243246
* Gets the `i`th _expanded_ argument of this macro invocation, where the
244247
* first argument has `i = 0`. The result has been expanded for macros _and_

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Expr extends StmtParent, @expr {
2323
predicate hasChild(Expr e, int n) { e = this.getChild(n) }
2424

2525
/** Gets the enclosing function of this expression, if any. */
26-
Function getEnclosingFunction() { result = exprEnclosingElement(this) }
26+
override Function getEnclosingFunction() { result = exprEnclosingElement(this) }
2727

2828
/** Gets the nearest enclosing set of curly braces around this expression in the source, if any. */
2929
BlockStmt getEnclosingBlock() { result = this.getEnclosingStmt().getEnclosingBlock() }

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/InstructionTag.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,11 @@ newtype TInstructionTag =
104104
} or
105105
SizeofVlaDimensionTag(int index) {
106106
exists(VlaDeclStmt v | exists(v.getTransitiveVlaDimensionStmt(index)))
107-
}
107+
} or
108+
AssertionVarAddressTag() or
109+
AssertionVarLoadTag() or
110+
AssertionOpTag() or
111+
AssertionBranchTag()
108112

109113
class InstructionTag extends TInstructionTag {
110114
final string toString() { result = getInstructionTagId(this) }
@@ -296,4 +300,12 @@ string getInstructionTagId(TInstructionTag tag) {
296300
tag = CoAwaitBranchTag() and result = "CoAwaitBranch"
297301
or
298302
tag = BoolToIntConversionTag() and result = "BoolToIntConversion"
303+
or
304+
tag = AssertionVarAddressTag() and result = "AssertionVarAddress"
305+
or
306+
tag = AssertionVarLoadTag() and result = "AssertionVarLoad"
307+
or
308+
tag = AssertionOpTag() and result = "AssertionOp"
309+
or
310+
tag = AssertionBranchTag() and result = "AssertionBranch"
299311
}

0 commit comments

Comments
 (0)