Skip to content

Commit 8a75532

Browse files
committed
C++: Add more sizeof VLA tests
1 parent f68d347 commit 8a75532

9 files changed

+209
-0
lines changed

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

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24996,6 +24996,101 @@ ir.cpp:
2499624996
# 2811| Type = [CTypedefType,Size_t] size_t
2499724997
# 2811| Value = [CStyleCast] 0
2499824998
# 2811| ValueCategory = prvalue
24999+
# 2814| [TopLevelFunction] void vla_sizeof_test4(int, size_t)
25000+
# 2814| <params>:
25001+
# 2814| getParameter(0): [Parameter] len1
25002+
# 2814| Type = [IntType] int
25003+
# 2814| getParameter(1): [Parameter] len2
25004+
# 2814| Type = [CTypedefType,Size_t] size_t
25005+
# 2814| getEntryPoint(): [BlockStmt] { ... }
25006+
# 2815| getStmt(0): [DeclStmt] declaration
25007+
# 2815| getDeclarationEntry(0): [VariableDeclarationEntry] definition of tmp1
25008+
# 2815| Type = [ArrayType] int[][]
25009+
# 2815| getStmt(1): [VlaDimensionStmt] VLA dimension size
25010+
# 2815| getDimensionExpr(): [VariableAccess] len1
25011+
# 2815| Type = [IntType] int
25012+
# 2815| ValueCategory = prvalue(load)
25013+
# 2815| getStmt(2): [VlaDimensionStmt] VLA dimension size
25014+
# 2815| getDimensionExpr(): [VariableAccess] len2
25015+
# 2815| Type = [CTypedefType,Size_t] size_t
25016+
# 2815| ValueCategory = prvalue(load)
25017+
# 2815| getStmt(3): [VlaDeclStmt] VLA declaration
25018+
# 2816| getStmt(4): [DeclStmt] declaration
25019+
# 2816| getDeclarationEntry(0): [VariableDeclarationEntry] definition of z
25020+
# 2816| Type = [CTypedefType,Size_t] size_t
25021+
# 2816| getVariable().getInitializer(): [Initializer] initializer for z
25022+
# 2816| getExpr(): [SizeofExprOperator] sizeof(<expr>)
25023+
# 2816| Type = [LongType] unsigned long
25024+
# 2816| ValueCategory = prvalue
25025+
# 2816| getExprOperand(): [ArrayExpr] access to array
25026+
# 2816| Type = [ArrayType] int[]
25027+
# 2816| ValueCategory = lvalue
25028+
# 2816| getArrayBase(): [VariableAccess] tmp1
25029+
# 2816| Type = [ArrayType] int[][]
25030+
# 2816| ValueCategory = lvalue
25031+
# 2816| getArrayOffset(): [Literal] 1
25032+
# 2816| Type = [IntType] int
25033+
# 2816| Value = [Literal] 1
25034+
# 2816| ValueCategory = prvalue
25035+
# 2816| getArrayBase().getFullyConverted(): [ArrayToPointerConversion] array to pointer conversion
25036+
# 2816| Type = [PointerType] int(*)[]
25037+
# 2816| ValueCategory = prvalue
25038+
# 2816| getExprOperand().getFullyConverted(): [ParenthesisExpr] (...)
25039+
# 2816| Type = [ArrayType] int[]
25040+
# 2816| ValueCategory = lvalue
25041+
# 2817| getStmt(5): [ReturnStmt] return ...
25042+
# 2819| [TopLevelFunction] void vla_sizeof_test5(int, size_t)
25043+
# 2819| <params>:
25044+
# 2819| getParameter(0): [Parameter] len1
25045+
# 2819| Type = [IntType] int
25046+
# 2819| getParameter(1): [Parameter] len2
25047+
# 2819| Type = [CTypedefType,Size_t] size_t
25048+
# 2819| getEntryPoint(): [BlockStmt] { ... }
25049+
# 2820| getStmt(0): [DeclStmt] declaration
25050+
# 2820| getDeclarationEntry(0): [VariableDeclarationEntry] definition of tmp1
25051+
# 2820| Type = [ArrayType] int[][]
25052+
# 2820| getStmt(1): [VlaDimensionStmt] VLA dimension size
25053+
# 2820| getDimensionExpr(): [VariableAccess] len1
25054+
# 2820| Type = [IntType] int
25055+
# 2820| ValueCategory = prvalue(load)
25056+
# 2820| getStmt(2): [VlaDimensionStmt] VLA dimension size
25057+
# 2820| getDimensionExpr(): [VariableAccess] len2
25058+
# 2820| Type = [CTypedefType,Size_t] size_t
25059+
# 2820| ValueCategory = prvalue(load)
25060+
# 2820| getStmt(3): [VlaDeclStmt] VLA declaration
25061+
# 2821| getStmt(4): [DeclStmt] declaration
25062+
# 2821| getDeclarationEntry(0): [VariableDeclarationEntry] definition of z
25063+
# 2821| Type = [CTypedefType,Size_t] size_t
25064+
# 2821| getVariable().getInitializer(): [Initializer] initializer for z
25065+
# 2821| getExpr(): [SizeofExprOperator] sizeof(<expr>)
25066+
# 2821| Type = [LongType] unsigned long
25067+
# 2821| ValueCategory = prvalue
25068+
# 2821| getExprOperand(): [ArrayExpr] access to array
25069+
# 2821| Type = [ArrayType] int[]
25070+
# 2821| ValueCategory = lvalue
25071+
# 2821| getArrayBase(): [PointerDereferenceExpr] * ...
25072+
# 2821| Type = [ArrayType] int[][]
25073+
# 2821| ValueCategory = lvalue
25074+
# 2821| getOperand(): [AddressOfExpr] & ...
25075+
# 2821| Type = [PointerType] int(*)[][]
25076+
# 2821| ValueCategory = prvalue
25077+
# 2821| getOperand(): [VariableAccess] tmp1
25078+
# 2821| Type = [ArrayType] int[][]
25079+
# 2821| ValueCategory = lvalue
25080+
# 2821| getArrayOffset(): [Literal] 1
25081+
# 2821| Type = [IntType] int
25082+
# 2821| Value = [Literal] 1
25083+
# 2821| ValueCategory = prvalue
25084+
# 2821| getArrayBase().getFullyConverted(): [ParenthesisExpr] (...)
25085+
# 2821| Type = [PointerType] int(*)[]
25086+
# 2821| ValueCategory = prvalue
25087+
# 2821| getExpr(): [ArrayToPointerConversion] array to pointer conversion
25088+
# 2821| Type = [PointerType] int(*)[]
25089+
# 2821| ValueCategory = prvalue
25090+
# 2821| getExprOperand().getFullyConverted(): [ParenthesisExpr] (...)
25091+
# 2821| Type = [ArrayType] int[]
25092+
# 2821| ValueCategory = lvalue
25093+
# 2822| getStmt(5): [ReturnStmt] return ...
2499925094
ir23.cpp:
2500025095
# 1| [TopLevelFunction] bool consteval_1()
2500125096
# 1| <params>:

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20617,6 +20617,52 @@ ir.cpp:
2061720617
# 2811| m2811_3(unsigned long) = Store[#return] : &:r2811_1, r2811_2
2061820618
#-----| Goto -> Block 1
2061920619

20620+
# 2814| void vla_sizeof_test4(int, size_t)
20621+
# 2814| Block 0
20622+
# 2814| v2814_1(void) = EnterFunction :
20623+
# 2814| m2814_2(unknown) = AliasedDefinition :
20624+
# 2814| m2814_3(unknown) = InitializeNonLocal :
20625+
# 2814| m2814_4(unknown) = Chi : total:m2814_2, partial:m2814_3
20626+
# 2814| r2814_5(glval<int>) = VariableAddress[len1] :
20627+
# 2814| m2814_6(int) = InitializeParameter[len1] : &:r2814_5
20628+
# 2814| r2814_7(glval<unsigned long>) = VariableAddress[len2] :
20629+
# 2814| m2814_8(unsigned long) = InitializeParameter[len2] : &:r2814_7
20630+
# 2815| r2815_1(glval<int[][]>) = VariableAddress[tmp1] :
20631+
# 2815| m2815_2(int[][]) = Uninitialized[tmp1] : &:r2815_1
20632+
# 2815| r2815_3(glval<int>) = VariableAddress[len1] :
20633+
# 2815| r2815_4(int) = Load[len1] : &:r2815_3, m2814_6
20634+
# 2815| r2815_5(glval<unsigned long>) = VariableAddress[len2] :
20635+
# 2815| r2815_6(unsigned long) = Load[len2] : &:r2815_5, m2814_8
20636+
# 2815| v2815_7(void) = NoOp :
20637+
# 2816| r2816_1(glval<unsigned long>) = VariableAddress[z] :
20638+
# 2816| r2816_2(unsigned long) = Constant[4] :
20639+
# 2816| r2816_3(unsigned long) = CopyValue : r2815_6
20640+
# 2816| r2816_4(unsigned long) = Mul : r2816_2, r2816_3
20641+
# 2816| m2816_5(unsigned long) = Store[z] : &:r2816_1, r2816_4
20642+
# 2817| v2817_1(void) = NoOp :
20643+
# 2814| v2814_9(void) = ReturnVoid :
20644+
# 2814| v2814_10(void) = AliasedUse : m2814_3
20645+
# 2814| v2814_11(void) = ExitFunction :
20646+
20647+
# 2819| void vla_sizeof_test5(int, size_t)
20648+
# 2819| Block 0
20649+
# 2819| v2819_1(void) = EnterFunction :
20650+
# 2819| m2819_2(unknown) = AliasedDefinition :
20651+
# 2819| m2819_3(unknown) = InitializeNonLocal :
20652+
# 2819| m2819_4(unknown) = Chi : total:m2819_2, partial:m2819_3
20653+
# 2819| r2819_5(glval<int>) = VariableAddress[len1] :
20654+
# 2819| m2819_6(int) = InitializeParameter[len1] : &:r2819_5
20655+
# 2819| r2819_7(glval<unsigned long>) = VariableAddress[len2] :
20656+
# 2819| m2819_8(unsigned long) = InitializeParameter[len2] : &:r2819_7
20657+
# 2820| r2820_1(glval<int[][]>) = VariableAddress[tmp1] :
20658+
# 2820| m2820_2(int[][]) = Uninitialized[tmp1] : &:r2820_1
20659+
# 2820| r2820_3(glval<int>) = VariableAddress[len1] :
20660+
# 2820| r2820_4(int) = Load[len1] : &:r2820_3, m2819_6
20661+
# 2820| r2820_5(glval<unsigned long>) = VariableAddress[len2] :
20662+
# 2820| r2820_6(unsigned long) = Load[len2] : &:r2820_5, m2819_8
20663+
# 2820| v2820_7(void) = NoOp :
20664+
# 2821| r2821_1(glval<unsigned long>) = VariableAddress[z] :
20665+
2062020666
ir23.cpp:
2062120667
# 1| bool consteval_1()
2062220668
# 1| Block 0

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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) |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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) |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,4 +2811,14 @@ size_t vla_sizeof_test3(int len1, size_t len2, char len3, bool b) {
28112811
return 0;
28122812
}
28132813

2814+
void vla_sizeof_test4(int len1, size_t len2) {
2815+
int tmp1[len1][len2];
2816+
size_t z = sizeof(1[tmp1]);
2817+
}
2818+
2819+
void vla_sizeof_test5(int len1, size_t len2) {
2820+
int tmp1[len1][len2];
2821+
size_t z = sizeof((*&tmp1)[1]);
2822+
}
2823+
28142824
// semmle-extractor-options: -std=c++20 --clang

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
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) |
23
unexpectedOperand
34
duplicateOperand
45
missingPhiOperand
56
missingOperandType
67
duplicateChiOperand
78
sideEffectWithoutPrimary
89
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) |
911
ambiguousSuccessors
1012
unexplainedLoop
1113
unnecessaryPhiInstruction
@@ -21,6 +23,7 @@ lostReachability
2123
backEdgeCountMismatch
2224
useNotDominatedByDefinition
2325
| 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) |
2427
switchInstructionWithoutDefaultEdge
2528
notMarkedAsConflated
2629
wronglyMarkedAsConflated

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18760,6 +18760,57 @@ ir.cpp:
1876018760
# 2811| mu2811_3(unsigned long) = Store[#return] : &:r2811_1, r2811_2
1876118761
#-----| Goto -> Block 1
1876218762

18763+
# 2814| void vla_sizeof_test4(int, size_t)
18764+
# 2814| Block 0
18765+
# 2814| v2814_1(void) = EnterFunction :
18766+
# 2814| mu2814_2(unknown) = AliasedDefinition :
18767+
# 2814| mu2814_3(unknown) = InitializeNonLocal :
18768+
# 2814| r2814_4(glval<int>) = VariableAddress[len1] :
18769+
# 2814| mu2814_5(int) = InitializeParameter[len1] : &:r2814_4
18770+
# 2814| r2814_6(glval<unsigned long>) = VariableAddress[len2] :
18771+
# 2814| mu2814_7(unsigned long) = InitializeParameter[len2] : &:r2814_6
18772+
# 2815| r2815_1(glval<int[][]>) = VariableAddress[tmp1] :
18773+
# 2815| mu2815_2(int[][]) = Uninitialized[tmp1] : &:r2815_1
18774+
# 2815| r2815_3(glval<int>) = VariableAddress[len1] :
18775+
# 2815| r2815_4(int) = Load[len1] : &:r2815_3, ~m?
18776+
# 2815| r2815_5(glval<unsigned long>) = VariableAddress[len2] :
18777+
# 2815| r2815_6(unsigned long) = Load[len2] : &:r2815_5, ~m?
18778+
# 2815| v2815_7(void) = NoOp :
18779+
# 2816| r2816_1(glval<unsigned long>) = VariableAddress[z] :
18780+
# 2816| r2816_2(unsigned long) = Constant[4] :
18781+
# 2816| r2816_3(unsigned long) = CopyValue : r2815_6
18782+
# 2816| r2816_4(unsigned long) = Mul : r2816_2, r2816_3
18783+
# 2816| mu2816_5(unsigned long) = Store[z] : &:r2816_1, r2816_4
18784+
# 2817| v2817_1(void) = NoOp :
18785+
# 2814| v2814_8(void) = ReturnVoid :
18786+
# 2814| v2814_9(void) = AliasedUse : ~m?
18787+
# 2814| v2814_10(void) = ExitFunction :
18788+
18789+
# 2819| void vla_sizeof_test5(int, size_t)
18790+
# 2819| Block 0
18791+
# 2819| v2819_1(void) = EnterFunction :
18792+
# 2819| mu2819_2(unknown) = AliasedDefinition :
18793+
# 2819| mu2819_3(unknown) = InitializeNonLocal :
18794+
# 2819| r2819_4(glval<int>) = VariableAddress[len1] :
18795+
# 2819| mu2819_5(int) = InitializeParameter[len1] : &:r2819_4
18796+
# 2819| r2819_6(glval<unsigned long>) = VariableAddress[len2] :
18797+
# 2819| mu2819_7(unsigned long) = InitializeParameter[len2] : &:r2819_6
18798+
# 2820| r2820_1(glval<int[][]>) = VariableAddress[tmp1] :
18799+
# 2820| mu2820_2(int[][]) = Uninitialized[tmp1] : &:r2820_1
18800+
# 2820| r2820_3(glval<int>) = VariableAddress[len1] :
18801+
# 2820| r2820_4(int) = Load[len1] : &:r2820_3, ~m?
18802+
# 2820| r2820_5(glval<unsigned long>) = VariableAddress[len2] :
18803+
# 2820| r2820_6(unsigned long) = Load[len2] : &:r2820_5, ~m?
18804+
# 2820| v2820_7(void) = NoOp :
18805+
# 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 :
18813+
1876318814
ir23.cpp:
1876418815
# 1| bool consteval_1()
1876518816
# 1| Block 0

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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) |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ 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) |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction

0 commit comments

Comments
 (0)