Skip to content

Commit f4df388

Browse files
committed
C++: Handle *& sequences in sizeof VLA expressions
1 parent 438cc96 commit f4df388

File tree

8 files changed

+22
-14
lines changed

8 files changed

+22
-14
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4098,8 +4098,14 @@ private VlaDeclStmt getVlaDeclStmt(Expr expr, int pointerDerefCount) {
40984098
expr.(VariableAccess).getTarget() = result.getVariable() and
40994099
pointerDerefCount = 0
41004100
or
4101+
not expr.(PointerDereferenceExpr).getOperand() instanceof AddressOfExpr and
41014102
result = getVlaDeclStmt(expr.(PointerDereferenceExpr).getOperand(), pointerDerefCount - 1)
41024103
or
4104+
// Skip sequences of the form `*&...`
4105+
result =
4106+
getVlaDeclStmt(expr.(PointerDereferenceExpr).getOperand().(AddressOfExpr).getOperand(),
4107+
pointerDerefCount)
4108+
or
41034109
result = getVlaDeclStmt(expr.(ArrayExpr).getArrayBase(), pointerDerefCount - 1)
41044110
}
41054111

cpp/ql/test/library-tests/ir/ir/aliased_ir.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20662,6 +20662,14 @@ ir.cpp:
2066220662
# 2820| r2820_6(unsigned long) = Load[len2] : &:r2820_5, m2819_8
2066320663
# 2820| v2820_7(void) = NoOp :
2066420664
# 2821| r2821_1(glval<unsigned long>) = VariableAddress[z] :
20665+
# 2821| r2821_2(unsigned long) = Constant[4] :
20666+
# 2821| r2821_3(unsigned long) = CopyValue : r2820_6
20667+
# 2821| r2821_4(unsigned long) = Mul : r2821_2, r2821_3
20668+
# 2821| m2821_5(unsigned long) = Store[z] : &:r2821_1, r2821_4
20669+
# 2822| v2822_1(void) = NoOp :
20670+
# 2819| v2819_9(void) = ReturnVoid :
20671+
# 2819| v2819_10(void) = AliasedUse : m2819_3
20672+
# 2819| v2819_11(void) = ExitFunction :
2066520673

2066620674
ir23.cpp:
2066720675
# 1| bool consteval_1()

cpp/ql/test/library-tests/ir/ir/aliased_ssa_consistency.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9-
| ir.cpp:2821:10:2821:10 | VariableAddress: definition of z | Instruction 'VariableAddress: definition of z' has no successors in function '$@'. | ir.cpp:2819:6:2819:21 | void vla_sizeof_test5(int, size_t) | void vla_sizeof_test5(int, size_t) |
109
ambiguousSuccessors
1110
unexplainedLoop
1211
unnecessaryPhiInstruction

cpp/ql/test/library-tests/ir/ir/aliased_ssa_consistency_unsound.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9-
| ir.cpp:2821:10:2821:10 | VariableAddress: definition of z | Instruction 'VariableAddress: definition of z' has no successors in function '$@'. | ir.cpp:2819:6:2819:21 | void vla_sizeof_test5(int, size_t) | void vla_sizeof_test5(int, size_t) |
109
ambiguousSuccessors
1110
unexplainedLoop
1211
unnecessaryPhiInstruction

cpp/ql/test/library-tests/ir/ir/raw_consistency.expected

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
missingOperand
2-
| ir.cpp:2821:14:2821:32 | Store: sizeof(<expr>) | Instruction 'Store' is missing an expected operand with tag 'StoreValue' in function '$@'. | ir.cpp:2819:6:2819:21 | void vla_sizeof_test5(int, size_t) | void vla_sizeof_test5(int, size_t) |
32
unexpectedOperand
43
duplicateOperand
54
missingPhiOperand
65
missingOperandType
76
duplicateChiOperand
87
sideEffectWithoutPrimary
98
instructionWithoutSuccessor
10-
| ir.cpp:2821:10:2821:10 | VariableAddress: definition of z | Instruction 'VariableAddress: definition of z' has no successors in function '$@'. | ir.cpp:2819:6:2819:21 | void vla_sizeof_test5(int, size_t) | void vla_sizeof_test5(int, size_t) |
119
ambiguousSuccessors
1210
unexplainedLoop
1311
unnecessaryPhiInstruction
@@ -23,7 +21,6 @@ lostReachability
2321
backEdgeCountMismatch
2422
useNotDominatedByDefinition
2523
| ir.cpp:1535:8:1535:8 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:1535:8:1535:8 | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() |
26-
| ir.cpp:2821:10:2821:10 | Address | Operand 'Address' is not dominated by its definition in function '$@'. | ir.cpp:2819:6:2819:21 | void vla_sizeof_test5(int, size_t) | void vla_sizeof_test5(int, size_t) |
2724
switchInstructionWithoutDefaultEdge
2825
notMarkedAsConflated
2926
wronglyMarkedAsConflated

cpp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18803,13 +18803,14 @@ ir.cpp:
1880318803
# 2820| r2820_6(unsigned long) = Load[len2] : &:r2820_5, ~m?
1880418804
# 2820| v2820_7(void) = NoOp :
1880518805
# 2821| r2821_1(glval<unsigned long>) = VariableAddress[z] :
18806-
18807-
# 2821| Block 1
18808-
# 2821| mu2821_2(unsigned long) = Store[z] : &:r2821_1
18809-
# 2822| v2822_1(void) = NoOp :
18810-
# 2819| v2819_8(void) = ReturnVoid :
18811-
# 2819| v2819_9(void) = AliasedUse : ~m?
18812-
# 2819| v2819_10(void) = ExitFunction :
18806+
# 2821| r2821_2(unsigned long) = Constant[4] :
18807+
# 2821| r2821_3(unsigned long) = CopyValue : r2820_6
18808+
# 2821| r2821_4(unsigned long) = Mul : r2821_2, r2821_3
18809+
# 2821| mu2821_5(unsigned long) = Store[z] : &:r2821_1, r2821_4
18810+
# 2822| v2822_1(void) = NoOp :
18811+
# 2819| v2819_8(void) = ReturnVoid :
18812+
# 2819| v2819_9(void) = AliasedUse : ~m?
18813+
# 2819| v2819_10(void) = ExitFunction :
1881318814

1881418815
ir23.cpp:
1881518816
# 1| bool consteval_1()

cpp/ql/test/library-tests/ir/ir/unaliased_ssa_consistency.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9-
| ir.cpp:2821:10:2821:10 | VariableAddress: definition of z | Instruction 'VariableAddress: definition of z' has no successors in function '$@'. | ir.cpp:2819:6:2819:21 | void vla_sizeof_test5(int, size_t) | void vla_sizeof_test5(int, size_t) |
109
ambiguousSuccessors
1110
unexplainedLoop
1211
unnecessaryPhiInstruction

cpp/ql/test/library-tests/ir/ir/unaliased_ssa_consistency_unsound.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9-
| ir.cpp:2821:10:2821:10 | VariableAddress: definition of z | Instruction 'VariableAddress: definition of z' has no successors in function '$@'. | ir.cpp:2819:6:2819:21 | void vla_sizeof_test5(int, size_t) | void vla_sizeof_test5(int, size_t) |
109
ambiguousSuccessors
1110
unexplainedLoop
1211
unnecessaryPhiInstruction

0 commit comments

Comments
 (0)