Skip to content

Commit 836c47a

Browse files
committed
C++: test for constructor init without constructor
1 parent 6acf49d commit 836c47a

File tree

5 files changed

+139
-0
lines changed

5 files changed

+139
-0
lines changed

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11332,6 +11332,64 @@ ir.cpp:
1133211332
# 1447| Type = [Struct] POD_Derived
1133311333
# 1447| ValueCategory = prvalue
1133411334
# 1448| getStmt(4): [ReturnStmt] return ...
11335+
# 1450| [CopyAssignmentOperator] Inheritance_Test_B& Inheritance_Test_B::operator=(Inheritance_Test_B const&)
11336+
# 1450| <params>:
11337+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
11338+
#-----| Type = [LValueReferenceType] const Inheritance_Test_B &
11339+
# 1450| [Constructor] void Inheritance_Test_B::Inheritance_Test_B()
11340+
# 1450| <params>:
11341+
# 1451| [Destructor] void Inheritance_Test_B::~Inheritance_Test_B()
11342+
# 1451| <params>:
11343+
# 1451| getEntryPoint(): [BlockStmt] { ... }
11344+
# 1451| getStmt(0): [ReturnStmt] return ...
11345+
# 1451| <destructions>:
11346+
# 1454| [CopyAssignmentOperator] Inheritance_Test_A& Inheritance_Test_A::operator=(Inheritance_Test_A const&)
11347+
# 1454| <params>:
11348+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
11349+
#-----| Type = [LValueReferenceType] const Inheritance_Test_A &
11350+
# 1454| [MoveAssignmentOperator] Inheritance_Test_A& Inheritance_Test_A::operator=(Inheritance_Test_A&&)
11351+
# 1454| <params>:
11352+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
11353+
#-----| Type = [RValueReferenceType] Inheritance_Test_A &&
11354+
# 1454| [CopyConstructor] void Inheritance_Test_A::Inheritance_Test_A(Inheritance_Test_A const&)
11355+
# 1454| <params>:
11356+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
11357+
#-----| Type = [LValueReferenceType] const Inheritance_Test_A &
11358+
# 1454| [MoveConstructor] void Inheritance_Test_A::Inheritance_Test_A(Inheritance_Test_A&&)
11359+
# 1454| <params>:
11360+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
11361+
#-----| Type = [RValueReferenceType] Inheritance_Test_A &&
11362+
# 1454| [Destructor] void Inheritance_Test_A::~Inheritance_Test_A()
11363+
# 1454| <params>:
11364+
# 1457| [Constructor] void Inheritance_Test_A::Inheritance_Test_A()
11365+
# 1457| <params>:
11366+
# 1457| <initializations>:
11367+
# 1457| getInitializer(0): (no string representation)
11368+
# 1457| Type = [Struct] Inheritance_Test_B
11369+
# 1457| ValueCategory = prvalue
11370+
# 1457| getInitializer(1): [ConstructorFieldInit] constructor init of field x
11371+
# 1457| Type = [IntType] int
11372+
# 1457| ValueCategory = prvalue
11373+
# 1457| getExpr(): [Literal] 42
11374+
# 1457| Type = [IntType] int
11375+
# 1457| Value = [Literal] 42
11376+
# 1457| ValueCategory = prvalue
11377+
# 1457| getEntryPoint(): [BlockStmt] { ... }
11378+
# 1458| getStmt(0): [ExprStmt] ExprStmt
11379+
# 1458| getExpr(): [AssignExpr] ... = ...
11380+
# 1458| Type = [IntType] int
11381+
# 1458| ValueCategory = lvalue
11382+
# 1458| getLValue(): [PointerFieldAccess] y
11383+
# 1458| Type = [IntType] int
11384+
# 1458| ValueCategory = lvalue
11385+
# 1458| getQualifier(): [ThisExpr] this
11386+
# 1458| Type = [PointerType] Inheritance_Test_A *
11387+
# 1458| ValueCategory = prvalue(load)
11388+
# 1458| getRValue(): [Literal] 3
11389+
# 1458| Type = [IntType] int
11390+
# 1458| Value = [Literal] 3
11391+
# 1458| ValueCategory = prvalue
11392+
# 1459| getStmt(1): [ReturnStmt] return ...
1133511393
perf-regression.cpp:
1133611394
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
1133711395
# 4| <params>:

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,4 +1447,15 @@ void temporary_hierarchy() {
14471447
float f = (returnValue<POD_Derived>()).f();
14481448
}
14491449

1450+
struct Inheritance_Test_B {
1451+
~Inheritance_Test_B() {}
1452+
};
1453+
1454+
struct Inheritance_Test_A : public Inheritance_Test_B {
1455+
int x;
1456+
int y;
1457+
Inheritance_Test_A() : x(42) {
1458+
y = 3;
1459+
}
1460+
};
14501461
// semmle-extractor-options: -std=c++17 --clang

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6626,6 +6626,31 @@
66266626
| ir.cpp:1447:44:1447:44 | ChiTotal | total:m1447_5 |
66276627
| ir.cpp:1447:44:1447:44 | SideEffect | ~m1447_5 |
66286628
| ir.cpp:1447:44:1447:44 | StoreValue | r1447_8 |
6629+
| ir.cpp:1451:3:1451:21 | Address | &:r1451_5 |
6630+
| ir.cpp:1451:3:1451:21 | Address | &:r1451_5 |
6631+
| ir.cpp:1451:3:1451:21 | Address | &:r1451_7 |
6632+
| ir.cpp:1451:3:1451:21 | Address | &:r1451_7 |
6633+
| ir.cpp:1451:3:1451:21 | ChiPartial | partial:m1451_3 |
6634+
| ir.cpp:1451:3:1451:21 | ChiTotal | total:m1451_2 |
6635+
| ir.cpp:1451:3:1451:21 | Load | m1451_6 |
6636+
| ir.cpp:1451:3:1451:21 | SideEffect | m1451_3 |
6637+
| ir.cpp:1451:3:1451:21 | SideEffect | m1451_8 |
6638+
| ir.cpp:1457:3:1457:20 | Address | &:r1457_5 |
6639+
| ir.cpp:1457:3:1457:20 | Address | &:r1457_5 |
6640+
| ir.cpp:1457:3:1457:20 | Address | &:r1457_7 |
6641+
| ir.cpp:1457:3:1457:20 | Address | &:r1457_7 |
6642+
| ir.cpp:1457:3:1457:20 | ChiPartial | partial:m1457_3 |
6643+
| ir.cpp:1457:3:1457:20 | ChiTotal | total:m1457_2 |
6644+
| ir.cpp:1457:3:1457:20 | Load | m1457_6 |
6645+
| ir.cpp:1457:3:1457:20 | SideEffect | m1457_3 |
6646+
| ir.cpp:1457:3:1457:20 | SideEffect | m1458_6 |
6647+
| ir.cpp:1458:5:1458:5 | Address | &:r1458_2 |
6648+
| ir.cpp:1458:5:1458:5 | Address | &:r1458_4 |
6649+
| ir.cpp:1458:5:1458:5 | Load | m1457_6 |
6650+
| ir.cpp:1458:5:1458:5 | Unary | r1458_3 |
6651+
| ir.cpp:1458:5:1458:9 | ChiPartial | partial:m1458_5 |
6652+
| ir.cpp:1458:5:1458:9 | ChiTotal | total:m1457_8 |
6653+
| ir.cpp:1458:9:1458:9 | StoreValue | r1458_1 |
66296654
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
66306655
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
66316656
| perf-regression.cpp:6:3:6:5 | Address | &:r6_7 |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ containsLoopOfForwardEdges
1717
lostReachability
1818
backEdgeCountMismatch
1919
useNotDominatedByDefinition
20+
| ir.cpp:1457:3:1457:20 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:1457:3:1457:20 | void Inheritance_Test_A::Inheritance_Test_A() | void Inheritance_Test_A::Inheritance_Test_A() |
2021
switchInstructionWithoutDefaultEdge
2122
notMarkedAsConflated
2223
wronglyMarkedAsConflated

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7858,6 +7858,50 @@ ir.cpp:
78587858
# 1443| v1443_5(void) = AliasedUse : ~m?
78597859
# 1443| v1443_6(void) = ExitFunction :
78607860

7861+
# 1451| void Inheritance_Test_B::~Inheritance_Test_B()
7862+
# 1451| Block 0
7863+
# 1451| v1451_1(void) = EnterFunction :
7864+
# 1451| mu1451_2(unknown) = AliasedDefinition :
7865+
# 1451| mu1451_3(unknown) = InitializeNonLocal :
7866+
# 1451| r1451_4(glval<unknown>) = VariableAddress[#this] :
7867+
# 1451| mu1451_5(glval<Inheritance_Test_B>) = InitializeParameter[#this] : &:r1451_4
7868+
# 1451| r1451_6(glval<Inheritance_Test_B>) = Load[#this] : &:r1451_4, ~m?
7869+
# 1451| mu1451_7(Inheritance_Test_B) = InitializeIndirection[#this] : &:r1451_6
7870+
# 1451| v1451_8(void) = NoOp :
7871+
# 1451| v1451_9(void) = ReturnIndirection[#this] : &:r1451_6, ~m?
7872+
# 1451| v1451_10(void) = ReturnVoid :
7873+
# 1451| v1451_11(void) = AliasedUse : ~m?
7874+
# 1451| v1451_12(void) = ExitFunction :
7875+
7876+
# 1457| void Inheritance_Test_A::Inheritance_Test_A()
7877+
# 1457| Block 0
7878+
# 1457| v1457_1(void) = EnterFunction :
7879+
# 1457| mu1457_2(unknown) = AliasedDefinition :
7880+
# 1457| mu1457_3(unknown) = InitializeNonLocal :
7881+
# 1457| r1457_4(glval<unknown>) = VariableAddress[#this] :
7882+
# 1457| mu1457_5(glval<Inheritance_Test_A>) = InitializeParameter[#this] : &:r1457_4
7883+
# 1457| r1457_6(glval<Inheritance_Test_A>) = Load[#this] : &:r1457_4, ~m?
7884+
# 1457| mu1457_7(Inheritance_Test_A) = InitializeIndirection[#this] : &:r1457_6
7885+
#-----| Goto -> Block 2
7886+
7887+
# 1457| Block 1
7888+
# 1457| r1457_8(glval<int>) = FieldAddress[x] : mu1457_5
7889+
# 1457| r1457_9(int) = Constant[42] :
7890+
# 1457| mu1457_10(int) = Store[?] : &:r1457_8, r1457_9
7891+
#-----| Goto -> Block 2
7892+
7893+
# 1458| Block 2
7894+
# 1458| r1458_1(int) = Constant[3] :
7895+
# 1458| r1458_2(glval<unknown>) = VariableAddress[#this] :
7896+
# 1458| r1458_3(Inheritance_Test_A *) = Load[#this] : &:r1458_2, ~m?
7897+
# 1458| r1458_4(glval<int>) = FieldAddress[y] : r1458_3
7898+
# 1458| mu1458_5(int) = Store[?] : &:r1458_4, r1458_1
7899+
# 1459| v1459_1(void) = NoOp :
7900+
# 1457| v1457_11(void) = ReturnIndirection[#this] : &:r1457_6, ~m?
7901+
# 1457| v1457_12(void) = ReturnVoid :
7902+
# 1457| v1457_13(void) = AliasedUse : ~m?
7903+
# 1457| v1457_14(void) = ExitFunction :
7904+
78617905
perf-regression.cpp:
78627906
# 6| void Big::Big()
78637907
# 6| Block 0

0 commit comments

Comments
 (0)