Skip to content

Commit d0e766d

Browse files
committed
C++: Add a testcase with invalid IR.
1 parent bb08611 commit d0e766d

File tree

5 files changed

+100
-0
lines changed

5 files changed

+100
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24550,6 +24550,37 @@ ir.cpp:
2455024550
# 2771| Type = [LValueReferenceType] ThreeWay &
2455124551
# 2771| ValueCategory = prvalue
2455224552
# 2772| getStmt(2): [ReturnStmt] return ...
24553+
# 2774| [TopLevelFunction] void test_allocation_with_initializer()
24554+
# 2774| <params>:
24555+
# 2774| getEntryPoint(): [BlockStmt] { ... }
24556+
# 2775| getStmt(0): [DeclStmt] declaration
24557+
# 2775| getDeclarationEntry(0): [VariableDeclarationEntry] definition of p1
24558+
# 2775| Type = [IntPointerType] int *
24559+
# 2775| getVariable().getInitializer(): [Initializer] initializer for p1
24560+
# 2775| getExpr(): [NewExpr] new
24561+
# 2775| Type = [IntPointerType] int *
24562+
# 2775| ValueCategory = prvalue
24563+
# 2775| getInitializer(): [Literal] 42
24564+
# 2775| Type = [IntType] int
24565+
# 2775| Value = [Literal] 42
24566+
# 2775| ValueCategory = prvalue
24567+
# 2776| getStmt(1): [DeclStmt] declaration
24568+
# 2776| getDeclarationEntry(0): [VariableDeclarationEntry] definition of p2
24569+
# 2776| Type = [PointerType] long *
24570+
# 2776| getVariable().getInitializer(): [Initializer] initializer for p2
24571+
# 2776| getExpr(): [NewExpr] new
24572+
# 2776| Type = [PointerType] long *
24573+
# 2776| ValueCategory = prvalue
24574+
# 2776| getInitializer(): [Literal] 42
24575+
# 2776| Type = [IntType] int
24576+
# 2776| Value = [Literal] 42
24577+
# 2776| ValueCategory = prvalue
24578+
# 2776| getInitializer().getFullyConverted(): [CStyleCast] (long)...
24579+
# 2776| Conversion = [IntegralConversion] integral conversion
24580+
# 2776| Type = [LongType] long
24581+
# 2776| Value = [CStyleCast] 42
24582+
# 2776| ValueCategory = prvalue
24583+
# 2777| getStmt(2): [ReturnStmt] return ...
2455324584
ir23.cpp:
2455424585
# 1| [TopLevelFunction] bool consteval_1()
2455524586
# 1| <params>:

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20395,6 +20395,38 @@ ir.cpp:
2039520395
# 2769| v2769_14(void) = AliasedUse : ~m2771_8
2039620396
# 2769| v2769_15(void) = ExitFunction :
2039720397

20398+
# 2774| void test_allocation_with_initializer()
20399+
# 2774| Block 0
20400+
# 2774| v2774_1(void) = EnterFunction :
20401+
# 2774| m2774_2(unknown) = AliasedDefinition :
20402+
# 2774| m2774_3(unknown) = InitializeNonLocal :
20403+
# 2774| m2774_4(unknown) = Chi : total:m2774_2, partial:m2774_3
20404+
# 2775| r2775_1(glval<int *>) = VariableAddress[p1] :
20405+
# 2775| r2775_2(glval<unknown>) = FunctionAddress[operator new] :
20406+
# 2775| r2775_3(unsigned long) = Constant[4] :
20407+
# 2775| r2775_4(void *) = Call[operator new] : func:r2775_2, 0:r2775_3
20408+
# 2775| m2775_5(unknown) = ^CallSideEffect : ~m2774_4
20409+
# 2775| m2775_6(unknown) = Chi : total:m2774_4, partial:m2775_5
20410+
# 2775| m2775_7(unknown) = ^InitializeDynamicAllocation : &:r2775_4
20411+
# 2775| r2775_8(int *) = Convert : r2775_4
20412+
# 2775| r2775_9(int) = Constant[42] :
20413+
# 2775| m2775_10(int) = Store[?] : &:r2775_8, r2775_9
20414+
# 2775| m2775_11(unknown) = Chi : total:m2775_7, partial:m2775_10
20415+
# 2775| m2775_12(int *) = Store[p1] : &:r2775_1, r2775_8
20416+
# 2776| r2776_1(glval<long *>) = VariableAddress[p2] :
20417+
# 2776| r2776_2(glval<unknown>) = FunctionAddress[operator new] :
20418+
# 2776| r2776_3(unsigned long) = Constant[8] :
20419+
# 2776| r2776_4(void *) = Call[operator new] : func:r2776_2, 0:r2776_3
20420+
# 2776| m2776_5(unknown) = ^CallSideEffect : ~m2775_6
20421+
# 2776| m2776_6(unknown) = Chi : total:m2775_6, partial:m2776_5
20422+
# 2776| m2776_7(unknown) = ^InitializeDynamicAllocation : &:r2776_4
20423+
# 2776| r2776_8(long *) = Convert : r2776_4
20424+
# 2776| m2776_9(long *) = Store[p2] : &:r2776_1, r2776_8
20425+
# 2777| v2777_1(void) = NoOp :
20426+
# 2774| v2774_5(void) = ReturnVoid :
20427+
# 2774| v2774_6(void) = AliasedUse : ~m2776_6
20428+
# 2774| v2774_7(void) = ExitFunction :
20429+
2039820430
ir23.cpp:
2039920431
# 1| bool consteval_1()
2040020432
# 1| Block 0

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2771,4 +2771,9 @@ void test_three_way(int a, int b, ThreeWay c, ThreeWay d) {
27712771
auto y = c <=> d;
27722772
}
27732773

2774+
void test_allocation_with_initializer() {
2775+
int* p1 = new int(42);
2776+
long* p2 = new long(42);
2777+
}
2778+
27742779
// semmle-extractor-options: -std=c++20 --clang

cpp/ql/test/library-tests/ir/ir/raw_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:2776:25:2776:26 | Constant: (long)... | Instruction 'Constant: (long)...' has no successors in function '$@'. | ir.cpp:2774:6:2774:37 | void test_allocation_with_initializer() | void test_allocation_with_initializer() |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18547,6 +18547,37 @@ ir.cpp:
1854718547
# 2769| v2769_13(void) = AliasedUse : ~m?
1854818548
# 2769| v2769_14(void) = ExitFunction :
1854918549

18550+
# 2774| void test_allocation_with_initializer()
18551+
# 2774| Block 0
18552+
# 2774| v2774_1(void) = EnterFunction :
18553+
# 2774| mu2774_2(unknown) = AliasedDefinition :
18554+
# 2774| mu2774_3(unknown) = InitializeNonLocal :
18555+
# 2775| r2775_1(glval<int *>) = VariableAddress[p1] :
18556+
# 2775| r2775_2(glval<unknown>) = FunctionAddress[operator new] :
18557+
# 2775| r2775_3(unsigned long) = Constant[4] :
18558+
# 2775| r2775_4(void *) = Call[operator new] : func:r2775_2, 0:r2775_3
18559+
# 2775| mu2775_5(unknown) = ^CallSideEffect : ~m?
18560+
# 2775| mu2775_6(unknown) = ^InitializeDynamicAllocation : &:r2775_4
18561+
# 2775| r2775_7(int *) = Convert : r2775_4
18562+
# 2775| r2775_8(int) = Constant[42] :
18563+
# 2775| mu2775_9(int) = Store[?] : &:r2775_7, r2775_8
18564+
# 2775| mu2775_10(int *) = Store[p1] : &:r2775_1, r2775_7
18565+
# 2776| r2776_1(glval<long *>) = VariableAddress[p2] :
18566+
# 2776| r2776_2(glval<unknown>) = FunctionAddress[operator new] :
18567+
# 2776| r2776_3(unsigned long) = Constant[8] :
18568+
# 2776| r2776_4(void *) = Call[operator new] : func:r2776_2, 0:r2776_3
18569+
# 2776| mu2776_5(unknown) = ^CallSideEffect : ~m?
18570+
# 2776| mu2776_6(unknown) = ^InitializeDynamicAllocation : &:r2776_4
18571+
# 2776| r2776_7(long *) = Convert : r2776_4
18572+
# 2776| mu2776_8(long *) = Store[p2] : &:r2776_1, r2776_7
18573+
# 2777| v2777_1(void) = NoOp :
18574+
# 2774| v2774_4(void) = ReturnVoid :
18575+
# 2774| v2774_5(void) = AliasedUse : ~m?
18576+
# 2774| v2774_6(void) = ExitFunction :
18577+
18578+
# 2776| Block 1
18579+
# 2776| r2776_9(long) = Constant[42] :
18580+
1855018581
ir23.cpp:
1855118582
# 1| bool consteval_1()
1855218583
# 1| Block 0

0 commit comments

Comments
 (0)