Skip to content

Commit 799f33e

Browse files
committed
C++: Add more postfix-crement tests
1 parent 9dd3b33 commit 799f33e

File tree

5 files changed

+415
-0
lines changed

5 files changed

+415
-0
lines changed

cpp/ql/test/library-tests/dataflow/asExpr/test.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,16 @@ void test_aggregate_literal() {
4242
void test_postfix_crement(int *p, int q) {
4343
p++; // $ asExpr="... ++" asIndirectExpr="... ++" asExpr=p asIndirectExpr=p
4444
q++; // $ asExpr="... ++" asExpr=q
45+
(p++); // $ numberOfNodes="... ++: 2" numberOfIndirectNodes="... ++: 2" asExpr="... ++" asIndirectExpr="... ++" MISSING: asExpr=p asIndirectExpr=p
46+
(q++); // $ numberOfNodes="... ++: 2" asExpr="... ++" MISSING: asExpr=q
4547
(void)(p++); // $ numberOfNodes="... ++: 2" asExpr="... ++" numberOfIndirectNodes="... ++: 2" asIndirectExpr="... ++" MISSING: asExpr=p asIndirectExpr=p
4648
(void)(q++); // $ numberOfNodes="... ++: 2" asExpr="... ++" MISSING: asExpr=q
49+
(void)p++; // $ asExpr="... ++" asIndirectExpr="... ++" asExpr=p asIndirectExpr=p
50+
(void)q++; // $ asExpr="... ++" asExpr=q
4751
int *p1 = p++; // $ asExpr="... ++" asIndirectExpr="... ++" asExpr="p(... ++)" asIndirectExpr="p(*... ++)"
4852
int q1 = q++; // $ asExpr="... ++" asExpr="q(... ++)"
53+
(int*)(p++); // $ numberOfIndirectNodes="... ++: 2" asExpr="... ++" asIndirectExpr="... ++" MISSING: asExpr="p(... ++)" asIndirectExpr="p(*... ++)"
54+
(int)(q++); // $ asExpr="... ++" MISSING: asExpr="q(... ++)"
55+
int *p2 = (int*)(p++); // $ asExpr="... ++" asIndirectExpr="... ++" asExpr="p(... ++)" asIndirectExpr="p(*... ++)"
56+
int q2 = (int)(q++); // $ asExpr="... ++" asExpr="q(... ++)"
4957
}

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

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24262,6 +24262,180 @@ ir.cpp:
2426224262
# 2725| getExpr().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
2426324263
# 2725| Type = [PlainCharType] char
2426424264
# 2725| ValueCategory = prvalue(load)
24265+
# 2728| [TopLevelFunction] void test_postfix_crement(int*, int)
24266+
# 2728| <params>:
24267+
# 2728| getParameter(0): [Parameter] p
24268+
# 2728| Type = [IntPointerType] int *
24269+
# 2728| getParameter(1): [Parameter] q
24270+
# 2728| Type = [IntType] int
24271+
# 2728| getEntryPoint(): [BlockStmt] { ... }
24272+
# 2729| getStmt(0): [ExprStmt] ExprStmt
24273+
# 2729| getExpr(): [PostfixIncrExpr] ... ++
24274+
# 2729| Type = [IntPointerType] int *
24275+
# 2729| ValueCategory = prvalue
24276+
# 2729| getOperand(): [VariableAccess] p
24277+
# 2729| Type = [IntPointerType] int *
24278+
# 2729| ValueCategory = lvalue
24279+
# 2730| getStmt(1): [ExprStmt] ExprStmt
24280+
# 2730| getExpr(): [PostfixIncrExpr] ... ++
24281+
# 2730| Type = [IntType] int
24282+
# 2730| ValueCategory = prvalue
24283+
# 2730| getOperand(): [VariableAccess] q
24284+
# 2730| Type = [IntType] int
24285+
# 2730| ValueCategory = lvalue
24286+
# 2731| getStmt(2): [ExprStmt] ExprStmt
24287+
# 2731| getExpr(): [PostfixIncrExpr] ... ++
24288+
# 2731| Type = [IntPointerType] int *
24289+
# 2731| ValueCategory = prvalue
24290+
# 2731| getOperand(): [VariableAccess] p
24291+
# 2731| Type = [IntPointerType] int *
24292+
# 2731| ValueCategory = lvalue
24293+
# 2731| getExpr().getFullyConverted(): [ParenthesisExpr] (...)
24294+
# 2731| Type = [IntPointerType] int *
24295+
# 2731| ValueCategory = prvalue
24296+
# 2732| getStmt(3): [ExprStmt] ExprStmt
24297+
# 2732| getExpr(): [PostfixIncrExpr] ... ++
24298+
# 2732| Type = [IntType] int
24299+
# 2732| ValueCategory = prvalue
24300+
# 2732| getOperand(): [VariableAccess] q
24301+
# 2732| Type = [IntType] int
24302+
# 2732| ValueCategory = lvalue
24303+
# 2732| getExpr().getFullyConverted(): [ParenthesisExpr] (...)
24304+
# 2732| Type = [IntType] int
24305+
# 2732| ValueCategory = prvalue
24306+
# 2733| getStmt(4): [ExprStmt] ExprStmt
24307+
# 2733| getExpr(): [PostfixIncrExpr] ... ++
24308+
# 2733| Type = [IntPointerType] int *
24309+
# 2733| ValueCategory = prvalue
24310+
# 2733| getOperand(): [VariableAccess] p
24311+
# 2733| Type = [IntPointerType] int *
24312+
# 2733| ValueCategory = lvalue
24313+
# 2733| getExpr().getFullyConverted(): [CStyleCast] (void)...
24314+
# 2733| Conversion = [VoidConversion] conversion to void
24315+
# 2733| Type = [VoidType] void
24316+
# 2733| ValueCategory = prvalue
24317+
# 2733| getExpr(): [ParenthesisExpr] (...)
24318+
# 2733| Type = [IntPointerType] int *
24319+
# 2733| ValueCategory = prvalue
24320+
# 2734| getStmt(5): [ExprStmt] ExprStmt
24321+
# 2734| getExpr(): [PostfixIncrExpr] ... ++
24322+
# 2734| Type = [IntType] int
24323+
# 2734| ValueCategory = prvalue
24324+
# 2734| getOperand(): [VariableAccess] q
24325+
# 2734| Type = [IntType] int
24326+
# 2734| ValueCategory = lvalue
24327+
# 2734| getExpr().getFullyConverted(): [CStyleCast] (void)...
24328+
# 2734| Conversion = [VoidConversion] conversion to void
24329+
# 2734| Type = [VoidType] void
24330+
# 2734| ValueCategory = prvalue
24331+
# 2734| getExpr(): [ParenthesisExpr] (...)
24332+
# 2734| Type = [IntType] int
24333+
# 2734| ValueCategory = prvalue
24334+
# 2735| getStmt(6): [ExprStmt] ExprStmt
24335+
# 2735| getExpr(): [PostfixIncrExpr] ... ++
24336+
# 2735| Type = [IntPointerType] int *
24337+
# 2735| ValueCategory = prvalue
24338+
# 2735| getOperand(): [VariableAccess] p
24339+
# 2735| Type = [IntPointerType] int *
24340+
# 2735| ValueCategory = lvalue
24341+
# 2735| getExpr().getFullyConverted(): [CStyleCast] (void)...
24342+
# 2735| Conversion = [VoidConversion] conversion to void
24343+
# 2735| Type = [VoidType] void
24344+
# 2735| ValueCategory = prvalue
24345+
# 2736| getStmt(7): [ExprStmt] ExprStmt
24346+
# 2736| getExpr(): [PostfixIncrExpr] ... ++
24347+
# 2736| Type = [IntType] int
24348+
# 2736| ValueCategory = prvalue
24349+
# 2736| getOperand(): [VariableAccess] q
24350+
# 2736| Type = [IntType] int
24351+
# 2736| ValueCategory = lvalue
24352+
# 2736| getExpr().getFullyConverted(): [CStyleCast] (void)...
24353+
# 2736| Conversion = [VoidConversion] conversion to void
24354+
# 2736| Type = [VoidType] void
24355+
# 2736| ValueCategory = prvalue
24356+
# 2737| getStmt(8): [DeclStmt] declaration
24357+
# 2737| getDeclarationEntry(0): [VariableDeclarationEntry] definition of p1
24358+
# 2737| Type = [IntPointerType] int *
24359+
# 2737| getVariable().getInitializer(): [Initializer] initializer for p1
24360+
# 2737| getExpr(): [PostfixIncrExpr] ... ++
24361+
# 2737| Type = [IntPointerType] int *
24362+
# 2737| ValueCategory = prvalue
24363+
# 2737| getOperand(): [VariableAccess] p
24364+
# 2737| Type = [IntPointerType] int *
24365+
# 2737| ValueCategory = lvalue
24366+
# 2738| getStmt(9): [DeclStmt] declaration
24367+
# 2738| getDeclarationEntry(0): [VariableDeclarationEntry] definition of q1
24368+
# 2738| Type = [IntType] int
24369+
# 2738| getVariable().getInitializer(): [Initializer] initializer for q1
24370+
# 2738| getExpr(): [PostfixIncrExpr] ... ++
24371+
# 2738| Type = [IntType] int
24372+
# 2738| ValueCategory = prvalue
24373+
# 2738| getOperand(): [VariableAccess] q
24374+
# 2738| Type = [IntType] int
24375+
# 2738| ValueCategory = lvalue
24376+
# 2739| getStmt(10): [ExprStmt] ExprStmt
24377+
# 2739| getExpr(): [PostfixIncrExpr] ... ++
24378+
# 2739| Type = [IntPointerType] int *
24379+
# 2739| ValueCategory = prvalue
24380+
# 2739| getOperand(): [VariableAccess] p
24381+
# 2739| Type = [IntPointerType] int *
24382+
# 2739| ValueCategory = lvalue
24383+
# 2739| getExpr().getFullyConverted(): [CStyleCast] (int *)...
24384+
# 2739| Conversion = [PointerConversion] pointer conversion
24385+
# 2739| Type = [IntPointerType] int *
24386+
# 2739| ValueCategory = prvalue
24387+
# 2739| getExpr(): [ParenthesisExpr] (...)
24388+
# 2739| Type = [IntPointerType] int *
24389+
# 2739| ValueCategory = prvalue
24390+
# 2740| getStmt(11): [ExprStmt] ExprStmt
24391+
# 2740| getExpr(): [PostfixIncrExpr] ... ++
24392+
# 2740| Type = [IntType] int
24393+
# 2740| ValueCategory = prvalue
24394+
# 2740| getOperand(): [VariableAccess] q
24395+
# 2740| Type = [IntType] int
24396+
# 2740| ValueCategory = lvalue
24397+
# 2740| getExpr().getFullyConverted(): [CStyleCast] (int)...
24398+
# 2740| Conversion = [IntegralConversion] integral conversion
24399+
# 2740| Type = [IntType] int
24400+
# 2740| ValueCategory = prvalue
24401+
# 2740| getExpr(): [ParenthesisExpr] (...)
24402+
# 2740| Type = [IntType] int
24403+
# 2740| ValueCategory = prvalue
24404+
# 2741| getStmt(12): [DeclStmt] declaration
24405+
# 2741| getDeclarationEntry(0): [VariableDeclarationEntry] definition of p2
24406+
# 2741| Type = [IntPointerType] int *
24407+
# 2741| getVariable().getInitializer(): [Initializer] initializer for p2
24408+
# 2741| getExpr(): [PostfixIncrExpr] ... ++
24409+
# 2741| Type = [IntPointerType] int *
24410+
# 2741| ValueCategory = prvalue
24411+
# 2741| getOperand(): [VariableAccess] p
24412+
# 2741| Type = [IntPointerType] int *
24413+
# 2741| ValueCategory = lvalue
24414+
# 2741| getExpr().getFullyConverted(): [CStyleCast] (int *)...
24415+
# 2741| Conversion = [PointerConversion] pointer conversion
24416+
# 2741| Type = [IntPointerType] int *
24417+
# 2741| ValueCategory = prvalue
24418+
# 2741| getExpr(): [ParenthesisExpr] (...)
24419+
# 2741| Type = [IntPointerType] int *
24420+
# 2741| ValueCategory = prvalue
24421+
# 2742| getStmt(13): [DeclStmt] declaration
24422+
# 2742| getDeclarationEntry(0): [VariableDeclarationEntry] definition of q2
24423+
# 2742| Type = [IntType] int
24424+
# 2742| getVariable().getInitializer(): [Initializer] initializer for q2
24425+
# 2742| getExpr(): [PostfixIncrExpr] ... ++
24426+
# 2742| Type = [IntType] int
24427+
# 2742| ValueCategory = prvalue
24428+
# 2742| getOperand(): [VariableAccess] q
24429+
# 2742| Type = [IntType] int
24430+
# 2742| ValueCategory = lvalue
24431+
# 2742| getExpr().getFullyConverted(): [CStyleCast] (int)...
24432+
# 2742| Conversion = [IntegralConversion] integral conversion
24433+
# 2742| Type = [IntType] int
24434+
# 2742| ValueCategory = prvalue
24435+
# 2742| getExpr(): [ParenthesisExpr] (...)
24436+
# 2742| Type = [IntType] int
24437+
# 2742| ValueCategory = prvalue
24438+
# 2743| getStmt(14): [ReturnStmt] return ...
2426524439
ir23.cpp:
2426624440
# 1| [TopLevelFunction] bool consteval_1()
2426724441
# 1| <params>:

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

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20156,6 +20156,115 @@ ir.cpp:
2015620156
# 2724| v2724_12(void) = AliasedUse : ~m2725_8
2015720157
# 2724| v2724_13(void) = ExitFunction :
2015820158

20159+
# 2728| void test_postfix_crement(int*, int)
20160+
# 2728| Block 0
20161+
# 2728| v2728_1(void) = EnterFunction :
20162+
# 2728| m2728_2(unknown) = AliasedDefinition :
20163+
# 2728| m2728_3(unknown) = InitializeNonLocal :
20164+
# 2728| m2728_4(unknown) = Chi : total:m2728_2, partial:m2728_3
20165+
# 2728| r2728_5(glval<int *>) = VariableAddress[p] :
20166+
# 2728| m2728_6(int *) = InitializeParameter[p] : &:r2728_5
20167+
# 2728| r2728_7(int *) = Load[p] : &:r2728_5, m2728_6
20168+
# 2728| m2728_8(unknown) = InitializeIndirection[p] : &:r2728_7
20169+
# 2728| m2728_9(unknown) = Chi : total:m2728_4, partial:m2728_8
20170+
# 2728| r2728_10(glval<int>) = VariableAddress[q] :
20171+
# 2728| m2728_11(int) = InitializeParameter[q] : &:r2728_10
20172+
# 2729| r2729_1(glval<int *>) = VariableAddress[p] :
20173+
# 2729| r2729_2(int *) = Load[p] : &:r2729_1, m2728_6
20174+
# 2729| r2729_3(int) = Constant[1] :
20175+
# 2729| r2729_4(int *) = PointerAdd[4] : r2729_2, r2729_3
20176+
# 2729| m2729_5(int *) = Store[p] : &:r2729_1, r2729_4
20177+
# 2730| r2730_1(glval<int>) = VariableAddress[q] :
20178+
# 2730| r2730_2(int) = Load[q] : &:r2730_1, m2728_11
20179+
# 2730| r2730_3(int) = Constant[1] :
20180+
# 2730| r2730_4(int) = Add : r2730_2, r2730_3
20181+
# 2730| m2730_5(int) = Store[q] : &:r2730_1, r2730_4
20182+
# 2731| r2731_1(glval<int *>) = VariableAddress[p] :
20183+
# 2731| r2731_2(int *) = Load[p] : &:r2731_1, m2729_5
20184+
# 2731| r2731_3(int) = Constant[1] :
20185+
# 2731| r2731_4(int *) = PointerAdd[4] : r2731_2, r2731_3
20186+
# 2731| m2731_5(int *) = Store[p] : &:r2731_1, r2731_4
20187+
# 2732| r2732_1(glval<int>) = VariableAddress[q] :
20188+
# 2732| r2732_2(int) = Load[q] : &:r2732_1, m2730_5
20189+
# 2732| r2732_3(int) = Constant[1] :
20190+
# 2732| r2732_4(int) = Add : r2732_2, r2732_3
20191+
# 2732| m2732_5(int) = Store[q] : &:r2732_1, r2732_4
20192+
# 2733| r2733_1(glval<int *>) = VariableAddress[p] :
20193+
# 2733| r2733_2(int *) = Load[p] : &:r2733_1, m2731_5
20194+
# 2733| r2733_3(int) = Constant[1] :
20195+
# 2733| r2733_4(int *) = PointerAdd[4] : r2733_2, r2733_3
20196+
# 2733| m2733_5(int *) = Store[p] : &:r2733_1, r2733_4
20197+
# 2733| v2733_6(void) = Convert : r2733_2
20198+
# 2734| r2734_1(glval<int>) = VariableAddress[q] :
20199+
# 2734| r2734_2(int) = Load[q] : &:r2734_1, m2732_5
20200+
# 2734| r2734_3(int) = Constant[1] :
20201+
# 2734| r2734_4(int) = Add : r2734_2, r2734_3
20202+
# 2734| m2734_5(int) = Store[q] : &:r2734_1, r2734_4
20203+
# 2734| v2734_6(void) = Convert : r2734_2
20204+
# 2735| r2735_1(glval<int *>) = VariableAddress[p] :
20205+
# 2735| r2735_2(int *) = Load[p] : &:r2735_1, m2733_5
20206+
# 2735| r2735_3(int) = Constant[1] :
20207+
# 2735| r2735_4(int *) = PointerAdd[4] : r2735_2, r2735_3
20208+
# 2735| m2735_5(int *) = Store[p] : &:r2735_1, r2735_4
20209+
# 2735| v2735_6(void) = Convert : r2735_2
20210+
# 2736| r2736_1(glval<int>) = VariableAddress[q] :
20211+
# 2736| r2736_2(int) = Load[q] : &:r2736_1, m2734_5
20212+
# 2736| r2736_3(int) = Constant[1] :
20213+
# 2736| r2736_4(int) = Add : r2736_2, r2736_3
20214+
# 2736| m2736_5(int) = Store[q] : &:r2736_1, r2736_4
20215+
# 2736| v2736_6(void) = Convert : r2736_2
20216+
# 2737| r2737_1(glval<int *>) = VariableAddress[p1] :
20217+
# 2737| r2737_2(glval<int *>) = VariableAddress[p] :
20218+
# 2737| r2737_3(int *) = Load[p] : &:r2737_2, m2735_5
20219+
# 2737| r2737_4(int) = Constant[1] :
20220+
# 2737| r2737_5(int *) = PointerAdd[4] : r2737_3, r2737_4
20221+
# 2737| m2737_6(int *) = Store[p] : &:r2737_2, r2737_5
20222+
# 2737| r2737_7(int *) = CopyValue : r2737_3
20223+
# 2737| m2737_8(int *) = Store[p1] : &:r2737_1, r2737_7
20224+
# 2738| r2738_1(glval<int>) = VariableAddress[q1] :
20225+
# 2738| r2738_2(glval<int>) = VariableAddress[q] :
20226+
# 2738| r2738_3(int) = Load[q] : &:r2738_2, m2736_5
20227+
# 2738| r2738_4(int) = Constant[1] :
20228+
# 2738| r2738_5(int) = Add : r2738_3, r2738_4
20229+
# 2738| m2738_6(int) = Store[q] : &:r2738_2, r2738_5
20230+
# 2738| r2738_7(int) = CopyValue : r2738_3
20231+
# 2738| m2738_8(int) = Store[q1] : &:r2738_1, r2738_7
20232+
# 2739| r2739_1(glval<int *>) = VariableAddress[p] :
20233+
# 2739| r2739_2(int *) = Load[p] : &:r2739_1, m2737_6
20234+
# 2739| r2739_3(int) = Constant[1] :
20235+
# 2739| r2739_4(int *) = PointerAdd[4] : r2739_2, r2739_3
20236+
# 2739| m2739_5(int *) = Store[p] : &:r2739_1, r2739_4
20237+
# 2739| r2739_6(int *) = Convert : r2739_2
20238+
# 2740| r2740_1(glval<int>) = VariableAddress[q] :
20239+
# 2740| r2740_2(int) = Load[q] : &:r2740_1, m2738_6
20240+
# 2740| r2740_3(int) = Constant[1] :
20241+
# 2740| r2740_4(int) = Add : r2740_2, r2740_3
20242+
# 2740| m2740_5(int) = Store[q] : &:r2740_1, r2740_4
20243+
# 2740| r2740_6(int) = Convert : r2740_2
20244+
# 2741| r2741_1(glval<int *>) = VariableAddress[p2] :
20245+
# 2741| r2741_2(glval<int *>) = VariableAddress[p] :
20246+
# 2741| r2741_3(int *) = Load[p] : &:r2741_2, m2739_5
20247+
# 2741| r2741_4(int) = Constant[1] :
20248+
# 2741| r2741_5(int *) = PointerAdd[4] : r2741_3, r2741_4
20249+
# 2741| m2741_6(int *) = Store[p] : &:r2741_2, r2741_5
20250+
# 2741| r2741_7(int *) = CopyValue : r2741_3
20251+
# 2741| r2741_8(int *) = Convert : r2741_7
20252+
# 2741| m2741_9(int *) = Store[p2] : &:r2741_1, r2741_8
20253+
# 2742| r2742_1(glval<int>) = VariableAddress[q2] :
20254+
# 2742| r2742_2(glval<int>) = VariableAddress[q] :
20255+
# 2742| r2742_3(int) = Load[q] : &:r2742_2, m2740_5
20256+
# 2742| r2742_4(int) = Constant[1] :
20257+
# 2742| r2742_5(int) = Add : r2742_3, r2742_4
20258+
# 2742| m2742_6(int) = Store[q] : &:r2742_2, r2742_5
20259+
# 2742| r2742_7(int) = CopyValue : r2742_3
20260+
# 2742| r2742_8(int) = Convert : r2742_7
20261+
# 2742| m2742_9(int) = Store[q2] : &:r2742_1, r2742_8
20262+
# 2743| v2743_1(void) = NoOp :
20263+
# 2728| v2728_12(void) = ReturnIndirection[p] : &:r2728_7, m2728_8
20264+
# 2728| v2728_13(void) = ReturnVoid :
20265+
# 2728| v2728_14(void) = AliasedUse : ~m2728_9
20266+
# 2728| v2728_15(void) = ExitFunction :
20267+
2015920268
ir23.cpp:
2016020269
# 1| bool consteval_1()
2016120270
# 1| Block 0

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2725,4 +2725,21 @@ char UseBracketOperator(const WithBracketOperator x, int i) {
27252725
return x[i];
27262726
}
27272727

2728+
void test_postfix_crement(int *p, int q) {
2729+
p++;
2730+
q++;
2731+
(p++);
2732+
(q++);
2733+
(void)(p++);
2734+
(void)(q++);
2735+
(void)p++;
2736+
(void)q++;
2737+
int *p1 = p++;
2738+
int q1 = q++;
2739+
(int*)(p++);
2740+
(int)(q++);
2741+
int *p2 = (int*)(p++);
2742+
int q2 = (int)(q++);
2743+
}
2744+
27282745
// semmle-extractor-options: -std=c++20 --clang

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy