From 44b6af652ecf1e0ac14fe5dc2de12d0db8faff2d Mon Sep 17 00:00:00 2001 From: Robert Marsh Date: Mon, 5 Dec 2022 12:37:16 -0500 Subject: [PATCH] C++: use Options::exits() for noreturn functions --- .../aliased_ssa/internal/SSAConstruction.qll | 20 +++++++++++-------- .../raw/internal/IRConstruction.qll | 5 +---- .../raw/internal/TranslatedCall.qll | 7 ++++++- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll b/cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll index 233db262118..2269765f99f 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/internal/SSAConstruction.qll @@ -34,9 +34,13 @@ private module Cached { cached predicate hasUnreachedInstructionCached(IRFunction irFunc) { - exists(OldInstruction oldInstruction | + exists(OldIR::Instruction oldInstruction | irFunc = oldInstruction.getEnclosingIRFunction() and - Reachability::isInfeasibleInstructionSuccessor(oldInstruction, _) + ( + Reachability::isInfeasibleInstructionSuccessor(oldInstruction, _) + or + oldInstruction.getOpcode() instanceof Opcode::Unreached + ) ) } @@ -368,18 +372,18 @@ private module Cached { kind instanceof GotoEdge else ( exists(OldInstruction oldInstruction | - oldInstruction = getOldInstruction(instruction) and + ( + oldInstruction = getOldInstruction(instruction) + or + instruction = getChi(oldInstruction) + ) + and ( if Reachability::isInfeasibleInstructionSuccessor(oldInstruction, kind) then result = unreachedInstruction(instruction.getEnclosingIRFunction()) else result = getNewInstruction(oldInstruction.getSuccessor(kind)) ) ) - or - exists(OldInstruction oldInstruction | - instruction = getChi(oldInstruction) and - result = getNewInstruction(oldInstruction.getSuccessor(kind)) - ) ) } diff --git a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/IRConstruction.qll b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/IRConstruction.qll index c08fc2a2a8d..be8f2fbab39 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/IRConstruction.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/IRConstruction.qll @@ -396,10 +396,7 @@ Instruction getPrimaryInstructionForSideEffect(SideEffectInstruction instruction predicate hasUnreachedInstruction(IRFunction func) { exists(Call c | c.getEnclosingFunction() = func.getFunction() and - ( - c.getTarget().hasSpecifier("_Noreturn") or - c.getTarget().getAnAttribute().hasName("noreturn") - ) + any(Options opt).exits(c.getTarget()) ) } diff --git a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedCall.qll b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedCall.qll index 6619a227e3f..e7226eb505a 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedCall.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/TranslatedCall.qll @@ -8,6 +8,7 @@ private import SideEffects private import TranslatedElement private import TranslatedExpr private import TranslatedFunction +private import DefaultOptions as DefaultOptions /** * Gets the `CallInstruction` from the `TranslatedCallExpr` for the specified expression. @@ -68,7 +69,7 @@ abstract class TranslatedCall extends TranslatedExpr { child = getSideEffects() and if this.isNoReturn() then result = any(UnreachedInstruction instr | this.getEnclosingFunction().getFunction() = instr.getEnclosingFunction()) - else result = getParent().getChildSuccessor(this) + else result = this.getParent().getChildSuccessor(this) } override Instruction getInstructionSuccessor(InstructionTag tag, EdgeKind kind) { @@ -272,6 +273,10 @@ abstract class TranslatedCallExpr extends TranslatedNonConstantExpr, TranslatedC } final override int getNumberOfArguments() { result = expr.getNumberOfArguments() } + + final override predicate isNoReturn() { + any(Options opt).exits(expr.getTarget()) + } } /**