Skip to content

Commit 119d4a4

Browse files
committed
C++: Fix unintended consequence in IR.
1 parent f430cf9 commit 119d4a4

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ class TranslatedSideEffects extends TranslatedElement, TTranslatedSideEffects {
343343

344344
override predicate hasInstruction(Opcode opcode, InstructionTag tag, CppType type) {
345345
expr.getTarget() instanceof AllocationFunction and
346+
not exists(NewOrNewArrayExpr newExpr |
347+
// we synthesize allocator calls for `new` and `new[]`, so don't add instructions to
348+
// the existing allocator call when it exists.
349+
newExpr.getAllocatorCall() = expr
350+
) and
346351
opcode instanceof Opcode::InitializeDynamicAllocation and
347352
tag = OnlyInstructionTag() and
348353
type = getUnknownType()
@@ -358,6 +363,11 @@ class TranslatedSideEffects extends TranslatedElement, TTranslatedSideEffects {
358363
tag = OnlyInstructionTag() and
359364
kind = gotoEdge() and
360365
expr.getTarget() instanceof AllocationFunction and
366+
not exists(NewOrNewArrayExpr newExpr |
367+
// we synthesize allocator calls for `new` and `new[]`, so don't add instructions to
368+
// the existing allocator call when it exists.
369+
newExpr.getAllocatorCall() = expr
370+
) and
361371
if exists(getChild(0))
362372
then result = getChild(0).getFirstInstruction()
363373
else result = getParent().getChildSuccessor(this)

0 commit comments

Comments
 (0)