Skip to content

Commit 1ad533a

Browse files
authored
Merge pull request github#13873 from jketema/ir-range-test
C++: Add semantic range analysis test as IR test
2 parents 8702efd + f7923d9 commit 1ad533a

File tree

4 files changed

+176
-0
lines changed

4 files changed

+176
-0
lines changed

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15463,6 +15463,79 @@ ir.cpp:
1546315463
# 2021| Type = [Struct] TernaryNonPodObj
1546415464
# 2021| ValueCategory = lvalue
1546515465
# 2022| getStmt(4): [ReturnStmt] return ...
15466+
# 2024| [TopLevelFunction] void CommaTestHelper(unsigned int)
15467+
# 2024| <params>:
15468+
# 2024| getParameter(0): [Parameter] (unnamed parameter 0)
15469+
# 2024| Type = [IntType] unsigned int
15470+
# 2026| [TopLevelFunction] unsigned int CommaTest(unsigned int)
15471+
# 2026| <params>:
15472+
# 2026| getParameter(0): [Parameter] x
15473+
# 2026| Type = [IntType] unsigned int
15474+
# 2026| getEntryPoint(): [BlockStmt] { ... }
15475+
# 2027| getStmt(0): [DeclStmt] declaration
15476+
# 2027| getDeclarationEntry(0): [VariableDeclarationEntry] definition of y
15477+
# 2027| Type = [IntType] unsigned int
15478+
# 2028| getStmt(1): [ExprStmt] ExprStmt
15479+
# 2028| getExpr(): [AssignExpr] ... = ...
15480+
# 2028| Type = [IntType] unsigned int
15481+
# 2028| ValueCategory = lvalue
15482+
# 2028| getLValue(): [VariableAccess] y
15483+
# 2028| Type = [IntType] unsigned int
15484+
# 2028| ValueCategory = lvalue
15485+
# 2028| getRValue(): [ConditionalExpr] ... ? ... : ...
15486+
# 2028| Type = [IntType] unsigned int
15487+
# 2028| ValueCategory = prvalue
15488+
# 2028| getCondition(): [LTExpr] ... < ...
15489+
# 2028| Type = [BoolType] bool
15490+
# 2028| ValueCategory = prvalue
15491+
# 2028| getLesserOperand(): [VariableAccess] x
15492+
# 2028| Type = [IntType] unsigned int
15493+
# 2028| ValueCategory = prvalue(load)
15494+
# 2028| getGreaterOperand(): [Literal] 100
15495+
# 2028| Type = [IntType] int
15496+
# 2028| Value = [Literal] 100
15497+
# 2028| ValueCategory = prvalue
15498+
# 2028| getGreaterOperand().getFullyConverted(): [CStyleCast] (unsigned int)...
15499+
# 2028| Conversion = [IntegralConversion] integral conversion
15500+
# 2028| Type = [IntType] unsigned int
15501+
# 2028| Value = [CStyleCast] 100
15502+
# 2028| ValueCategory = prvalue
15503+
# 2029| getThen(): [CommaExpr] ... , ...
15504+
# 2029| Type = [IntType] unsigned int
15505+
# 2029| ValueCategory = prvalue
15506+
# 2029| getLeftOperand(): [FunctionCall] call to CommaTestHelper
15507+
# 2029| Type = [VoidType] void
15508+
# 2029| ValueCategory = prvalue
15509+
# 2029| getArgument(0): [VariableAccess] x
15510+
# 2029| Type = [IntType] unsigned int
15511+
# 2029| ValueCategory = prvalue(load)
15512+
# 2029| getRightOperand(): [VariableAccess] x
15513+
# 2029| Type = [IntType] unsigned int
15514+
# 2029| ValueCategory = prvalue(load)
15515+
# 2030| getElse(): [CommaExpr] ... , ...
15516+
# 2030| Type = [IntType] int
15517+
# 2030| ValueCategory = prvalue
15518+
# 2030| getLeftOperand(): [FunctionCall] call to CommaTestHelper
15519+
# 2030| Type = [VoidType] void
15520+
# 2030| ValueCategory = prvalue
15521+
# 2030| getArgument(0): [VariableAccess] x
15522+
# 2030| Type = [IntType] unsigned int
15523+
# 2030| ValueCategory = prvalue(load)
15524+
# 2030| getRightOperand(): [Literal] 10
15525+
# 2030| Type = [IntType] int
15526+
# 2030| Value = [Literal] 10
15527+
# 2030| ValueCategory = prvalue
15528+
# 2029| getThen().getFullyConverted(): [ParenthesisExpr] (...)
15529+
# 2029| Type = [IntType] unsigned int
15530+
# 2029| ValueCategory = prvalue
15531+
# 2030| getElse().getFullyConverted(): [CStyleCast] (unsigned int)...
15532+
# 2030| Conversion = [IntegralConversion] integral conversion
15533+
# 2030| Type = [IntType] unsigned int
15534+
# 2030| ValueCategory = prvalue
15535+
# 2030| getExpr(): [ParenthesisExpr] (...)
15536+
# 2030| Type = [IntType] int
15537+
# 2030| ValueCategory = prvalue
15538+
# 2031| getStmt(2): [ReturnStmt] return ...
1546615539
perf-regression.cpp:
1546715540
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
1546815541
# 4| <params>:

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,4 +2021,13 @@ void TernaryTestNonPodObj(bool a, TernaryNonPodObj x, TernaryNonPodObj y, Ternar
20212021
(z = a ? x : y) = TernaryNonPodObj();
20222022
}
20232023

2024+
void CommaTestHelper(unsigned int);
2025+
2026+
unsigned int CommaTest(unsigned int x) {
2027+
unsigned int y;
2028+
y = x < 100 ?
2029+
(CommaTestHelper(x), x) :
2030+
(CommaTestHelper(x), 10);
2031+
}
2032+
20242033
// semmle-extractor-options: -std=c++17 --clang

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9524,6 +9524,44 @@
95249524
| ir.cpp:2021:23:2021:40 | SideEffect | ~m2021_27 |
95259525
| ir.cpp:2021:23:2021:40 | Unary | r2021_20 |
95269526
| ir.cpp:2021:23:2021:40 | Unary | r2021_28 |
9527+
| ir.cpp:2026:14:2026:22 | ChiPartial | partial:m2026_3 |
9528+
| ir.cpp:2026:14:2026:22 | ChiTotal | total:m2026_2 |
9529+
| ir.cpp:2026:37:2026:37 | Address | &:r2026_5 |
9530+
| ir.cpp:2027:16:2027:16 | Address | &:r2027_1 |
9531+
| ir.cpp:2028:3:2028:3 | Address | &:r2028_9 |
9532+
| ir.cpp:2028:7:2028:7 | Address | &:r2028_1 |
9533+
| ir.cpp:2028:7:2028:7 | Left | r2028_2 |
9534+
| ir.cpp:2028:7:2028:7 | Load | m2026_6 |
9535+
| ir.cpp:2028:7:2028:13 | Condition | r2028_4 |
9536+
| ir.cpp:2028:7:2030:28 | Address | &:r2028_7 |
9537+
| ir.cpp:2028:7:2030:28 | Address | &:r2028_11 |
9538+
| ir.cpp:2028:7:2030:28 | Address | &:r2028_13 |
9539+
| ir.cpp:2028:7:2030:28 | Load | m2028_6 |
9540+
| ir.cpp:2028:7:2030:28 | Phi | from 2:m2028_12 |
9541+
| ir.cpp:2028:7:2030:28 | Phi | from 3:m2028_14 |
9542+
| ir.cpp:2028:7:2030:28 | StoreValue | r2028_8 |
9543+
| ir.cpp:2028:11:2028:13 | Right | r2028_3 |
9544+
| ir.cpp:2029:6:2029:20 | CallTarget | func:r2029_1 |
9545+
| ir.cpp:2029:6:2029:20 | ChiPartial | partial:m2029_5 |
9546+
| ir.cpp:2029:6:2029:20 | ChiTotal | total:m2026_4 |
9547+
| ir.cpp:2029:6:2029:20 | SideEffect | ~m2026_4 |
9548+
| ir.cpp:2029:6:2029:26 | StoreValue | r2029_9 |
9549+
| ir.cpp:2029:22:2029:22 | Address | &:r2029_2 |
9550+
| ir.cpp:2029:22:2029:22 | Arg(0) | 0:r2029_3 |
9551+
| ir.cpp:2029:22:2029:22 | Load | m2026_6 |
9552+
| ir.cpp:2029:26:2029:26 | Address | &:r2029_7 |
9553+
| ir.cpp:2029:26:2029:26 | Load | m2026_6 |
9554+
| ir.cpp:2029:26:2029:26 | Unary | r2029_8 |
9555+
| ir.cpp:2030:5:2030:28 | StoreValue | r2030_9 |
9556+
| ir.cpp:2030:6:2030:20 | CallTarget | func:r2030_1 |
9557+
| ir.cpp:2030:6:2030:20 | ChiPartial | partial:m2030_5 |
9558+
| ir.cpp:2030:6:2030:20 | ChiTotal | total:m2026_4 |
9559+
| ir.cpp:2030:6:2030:20 | SideEffect | ~m2026_4 |
9560+
| ir.cpp:2030:6:2030:27 | Unary | r2030_8 |
9561+
| ir.cpp:2030:22:2030:22 | Address | &:r2030_2 |
9562+
| ir.cpp:2030:22:2030:22 | Arg(0) | 0:r2030_3 |
9563+
| ir.cpp:2030:22:2030:22 | Load | m2026_6 |
9564+
| ir.cpp:2030:26:2030:27 | Unary | r2030_7 |
95279565
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
95289566
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
95299567
| perf-regression.cpp:6:3:6:5 | Address | &:r6_7 |

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11015,6 +11015,62 @@ ir.cpp:
1101511015
# 2021| mu2021_36(glval<TernaryNonPodObj>) = Store[#temp2021:10] : &:r2021_35, r2021_34
1101611016
#-----| Goto -> Block 10
1101711017

11018+
# 2026| unsigned int CommaTest(unsigned int)
11019+
# 2026| Block 0
11020+
# 2026| v2026_1(void) = EnterFunction :
11021+
# 2026| mu2026_2(unknown) = AliasedDefinition :
11022+
# 2026| mu2026_3(unknown) = InitializeNonLocal :
11023+
# 2026| r2026_4(glval<unsigned int>) = VariableAddress[x] :
11024+
# 2026| mu2026_5(unsigned int) = InitializeParameter[x] : &:r2026_4
11025+
# 2027| r2027_1(glval<unsigned int>) = VariableAddress[y] :
11026+
# 2027| mu2027_2(unsigned int) = Uninitialized[y] : &:r2027_1
11027+
# 2028| r2028_1(glval<unsigned int>) = VariableAddress[x] :
11028+
# 2028| r2028_2(unsigned int) = Load[x] : &:r2028_1, ~m?
11029+
# 2028| r2028_3(unsigned int) = Constant[100] :
11030+
# 2028| r2028_4(bool) = CompareLT : r2028_2, r2028_3
11031+
# 2028| v2028_5(void) = ConditionalBranch : r2028_4
11032+
#-----| False -> Block 4
11033+
#-----| True -> Block 3
11034+
11035+
# 2026| Block 1
11036+
# 2026| r2026_6(glval<unsigned int>) = VariableAddress[#return] :
11037+
# 2026| v2026_7(void) = ReturnValue : &:r2026_6, ~m?
11038+
# 2026| v2026_8(void) = AliasedUse : ~m?
11039+
# 2026| v2026_9(void) = ExitFunction :
11040+
11041+
# 2028| Block 2
11042+
# 2028| r2028_6(glval<unsigned int>) = VariableAddress[#temp2028:7] :
11043+
# 2028| r2028_7(unsigned int) = Load[#temp2028:7] : &:r2028_6, ~m?
11044+
# 2028| r2028_8(glval<unsigned int>) = VariableAddress[y] :
11045+
# 2028| mu2028_9(unsigned int) = Store[y] : &:r2028_8, r2028_7
11046+
# 2031| v2031_1(void) = Unreached :
11047+
11048+
# 2029| Block 3
11049+
# 2029| r2029_1(glval<unknown>) = FunctionAddress[CommaTestHelper] :
11050+
# 2029| r2029_2(glval<unsigned int>) = VariableAddress[x] :
11051+
# 2029| r2029_3(unsigned int) = Load[x] : &:r2029_2, ~m?
11052+
# 2029| v2029_4(void) = Call[CommaTestHelper] : func:r2029_1, 0:r2029_3
11053+
# 2029| mu2029_5(unknown) = ^CallSideEffect : ~m?
11054+
# 2029| r2029_6(glval<unsigned int>) = VariableAddress[x] :
11055+
# 2029| r2029_7(unsigned int) = Load[x] : &:r2029_6, ~m?
11056+
# 2029| r2029_8(unsigned int) = CopyValue : r2029_7
11057+
# 2028| r2028_10(glval<unsigned int>) = VariableAddress[#temp2028:7] :
11058+
# 2028| mu2028_11(unsigned int) = Store[#temp2028:7] : &:r2028_10, r2029_8
11059+
#-----| Goto -> Block 2
11060+
11061+
# 2030| Block 4
11062+
# 2030| r2030_1(glval<unknown>) = FunctionAddress[CommaTestHelper] :
11063+
# 2030| r2030_2(glval<unsigned int>) = VariableAddress[x] :
11064+
# 2030| r2030_3(unsigned int) = Load[x] : &:r2030_2, ~m?
11065+
# 2030| v2030_4(void) = Call[CommaTestHelper] : func:r2030_1, 0:r2030_3
11066+
# 2030| mu2030_5(unknown) = ^CallSideEffect : ~m?
11067+
# 2030| r2030_6(int) = Constant[10] :
11068+
# 2030| r2030_7(int) = CopyValue : r2030_6
11069+
# 2030| r2030_8(unsigned int) = Convert : r2030_7
11070+
# 2028| r2028_12(glval<unsigned int>) = VariableAddress[#temp2028:7] :
11071+
# 2028| mu2028_13(unsigned int) = Store[#temp2028:7] : &:r2028_12, r2030_8
11072+
#-----| Goto -> Block 2
11073+
1101811074
perf-regression.cpp:
1101911075
# 6| void Big::Big()
1102011076
# 6| Block 0

0 commit comments

Comments
 (0)