Skip to content

Commit 44b6af6

Browse files
committed
C++: use Options::exits() for noreturn functions
1 parent c01ee59 commit 44b6af6

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ private module Cached {
3434

3535
cached
3636
predicate hasUnreachedInstructionCached(IRFunction irFunc) {
37-
exists(OldInstruction oldInstruction |
37+
exists(OldIR::Instruction oldInstruction |
3838
irFunc = oldInstruction.getEnclosingIRFunction() and
39-
Reachability::isInfeasibleInstructionSuccessor(oldInstruction, _)
39+
(
40+
Reachability::isInfeasibleInstructionSuccessor(oldInstruction, _)
41+
or
42+
oldInstruction.getOpcode() instanceof Opcode::Unreached
43+
)
4044
)
4145
}
4246

@@ -368,18 +372,18 @@ private module Cached {
368372
kind instanceof GotoEdge
369373
else (
370374
exists(OldInstruction oldInstruction |
371-
oldInstruction = getOldInstruction(instruction) and
375+
(
376+
oldInstruction = getOldInstruction(instruction)
377+
or
378+
instruction = getChi(oldInstruction)
379+
)
380+
and
372381
(
373382
if Reachability::isInfeasibleInstructionSuccessor(oldInstruction, kind)
374383
then result = unreachedInstruction(instruction.getEnclosingIRFunction())
375384
else result = getNewInstruction(oldInstruction.getSuccessor(kind))
376385
)
377386
)
378-
or
379-
exists(OldInstruction oldInstruction |
380-
instruction = getChi(oldInstruction) and
381-
result = getNewInstruction(oldInstruction.getSuccessor(kind))
382-
)
383387
)
384388
}
385389

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,7 @@ Instruction getPrimaryInstructionForSideEffect(SideEffectInstruction instruction
396396
predicate hasUnreachedInstruction(IRFunction func) {
397397
exists(Call c |
398398
c.getEnclosingFunction() = func.getFunction() and
399-
(
400-
c.getTarget().hasSpecifier("_Noreturn") or
401-
c.getTarget().getAnAttribute().hasName("noreturn")
402-
)
399+
any(Options opt).exits(c.getTarget())
403400
)
404401
}
405402

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ private import SideEffects
88
private import TranslatedElement
99
private import TranslatedExpr
1010
private import TranslatedFunction
11+
private import DefaultOptions as DefaultOptions
1112

1213
/**
1314
* Gets the `CallInstruction` from the `TranslatedCallExpr` for the specified expression.
@@ -68,7 +69,7 @@ abstract class TranslatedCall extends TranslatedExpr {
6869
child = getSideEffects() and
6970
if this.isNoReturn()
7071
then result = any(UnreachedInstruction instr | this.getEnclosingFunction().getFunction() = instr.getEnclosingFunction())
71-
else result = getParent().getChildSuccessor(this)
72+
else result = this.getParent().getChildSuccessor(this)
7273
}
7374

7475
override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) {
@@ -272,6 +273,10 @@ abstract class TranslatedCallExpr extends TranslatedNonConstantExpr, TranslatedC
272273
}
273274

274275
final override int getNumberOfArguments() { result = expr.getNumberOfArguments() }
276+
277+
final override predicate isNoReturn() {
278+
any(Options opt).exits(expr.getTarget())
279+
}
275280
}
276281

277282
/**

0 commit comments

Comments
 (0)