Skip to content

Commit 3d38133

Browse files
committed
C++: Add a test with global variable templates.
1 parent 3f03cc2 commit 3d38133

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-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
@@ -14377,6 +14377,37 @@ ir.cpp:
1437714377
# 1885| Type = [ClassTemplateInstantiation,Struct] Bar2<int>
1437814378
# 1885| ValueCategory = lvalue
1437914379
# 1886| getStmt(2): [ReturnStmt] return ...
14380+
# 1891| [TopLevelFunction] int test_global_template_int()
14381+
# 1891| <params>:
14382+
# 1891| getEntryPoint(): [BlockStmt] { ... }
14383+
# 1892| getStmt(0): [DeclStmt] declaration
14384+
# 1892| getDeclarationEntry(0): [VariableDeclarationEntry] definition of local_int
14385+
# 1892| Type = [IntType] int
14386+
# 1892| getVariable().getInitializer(): [Initializer] initializer for local_int
14387+
# 1892| getExpr(): [VariableAccess] global_template
14388+
# 1892| Type = [IntType] int
14389+
# 1892| ValueCategory = prvalue(load)
14390+
# 1893| getStmt(1): [DeclStmt] declaration
14391+
# 1893| getDeclarationEntry(0): [VariableDeclarationEntry] definition of local_char
14392+
# 1893| Type = [PlainCharType] char
14393+
# 1893| getVariable().getInitializer(): [Initializer] initializer for local_char
14394+
# 1893| getExpr(): [VariableAccess] global_template
14395+
# 1893| Type = [PlainCharType] char
14396+
# 1893| ValueCategory = prvalue(load)
14397+
# 1894| getStmt(2): [ReturnStmt] return ...
14398+
# 1894| getExpr(): [AddExpr] ... + ...
14399+
# 1894| Type = [IntType] int
14400+
# 1894| ValueCategory = prvalue
14401+
# 1894| getLeftOperand(): [VariableAccess] local_int
14402+
# 1894| Type = [IntType] int
14403+
# 1894| ValueCategory = prvalue(load)
14404+
# 1894| getRightOperand(): [VariableAccess] local_char
14405+
# 1894| Type = [PlainCharType] char
14406+
# 1894| ValueCategory = prvalue(load)
14407+
# 1894| getRightOperand().getFullyConverted(): [CStyleCast] (int)...
14408+
# 1894| Conversion = [IntegralConversion] integral conversion
14409+
# 1894| Type = [IntType] int
14410+
# 1894| ValueCategory = prvalue
1438014411
perf-regression.cpp:
1438114412
# 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&)
1438214413
# 4| <params>:

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,4 +1886,12 @@ namespace missing_declaration_entries {
18861886
}
18871887
}
18881888

1889+
template<typename T> T global_template = 42;
1890+
1891+
int test_global_template_int() {
1892+
int local_int = global_template<int>;
1893+
char local_char = global_template<char>;
1894+
return local_int + (int)local_char;
1895+
}
1896+
18891897
// semmle-extractor-options: -std=c++17 --clang

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8751,6 +8751,38 @@
87518751
| ir.cpp:1885:11:1885:50 | ChiPartial | partial:m1885_4 |
87528752
| ir.cpp:1885:11:1885:50 | ChiTotal | total:m1883_4 |
87538753
| ir.cpp:1885:11:1885:50 | SideEffect | ~m1883_4 |
8754+
| ir.cpp:1889:24:1889:24 | Address | &:r1889_3 |
8755+
| ir.cpp:1889:24:1889:24 | Address | &:r1889_3 |
8756+
| ir.cpp:1889:24:1889:24 | SideEffect | ~m1889_6 |
8757+
| ir.cpp:1889:24:1889:24 | SideEffect | ~m1889_6 |
8758+
| ir.cpp:1889:42:1889:43 | ChiPartial | partial:m1889_5 |
8759+
| ir.cpp:1889:42:1889:43 | ChiPartial | partial:m1889_5 |
8760+
| ir.cpp:1889:42:1889:43 | ChiTotal | total:m1889_2 |
8761+
| ir.cpp:1889:42:1889:43 | ChiTotal | total:m1889_2 |
8762+
| ir.cpp:1889:42:1889:43 | StoreValue | r1889_4 |
8763+
| ir.cpp:1889:42:1889:43 | StoreValue | r1889_4 |
8764+
| ir.cpp:1891:5:1891:28 | Address | &:r1891_5 |
8765+
| ir.cpp:1891:5:1891:28 | ChiPartial | partial:m1891_3 |
8766+
| ir.cpp:1891:5:1891:28 | ChiTotal | total:m1891_2 |
8767+
| ir.cpp:1891:5:1891:28 | Load | m1894_8 |
8768+
| ir.cpp:1891:5:1891:28 | SideEffect | m1891_3 |
8769+
| ir.cpp:1892:9:1892:17 | Address | &:r1892_1 |
8770+
| ir.cpp:1892:21:1892:40 | Address | &:r1892_2 |
8771+
| ir.cpp:1892:21:1892:40 | Load | ~m1891_3 |
8772+
| ir.cpp:1892:21:1892:40 | StoreValue | r1892_3 |
8773+
| ir.cpp:1893:10:1893:19 | Address | &:r1893_1 |
8774+
| ir.cpp:1893:23:1893:43 | Address | &:r1893_2 |
8775+
| ir.cpp:1893:23:1893:43 | Load | ~m1891_3 |
8776+
| ir.cpp:1893:23:1893:43 | StoreValue | r1893_3 |
8777+
| ir.cpp:1894:5:1894:39 | Address | &:r1894_1 |
8778+
| ir.cpp:1894:12:1894:20 | Address | &:r1894_2 |
8779+
| ir.cpp:1894:12:1894:20 | Left | r1894_3 |
8780+
| ir.cpp:1894:12:1894:20 | Load | m1892_4 |
8781+
| ir.cpp:1894:12:1894:38 | StoreValue | r1894_7 |
8782+
| ir.cpp:1894:24:1894:38 | Right | r1894_6 |
8783+
| ir.cpp:1894:29:1894:38 | Address | &:r1894_4 |
8784+
| ir.cpp:1894:29:1894:38 | Load | m1893_4 |
8785+
| ir.cpp:1894:29:1894:38 | Unary | r1894_5 |
87548786
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
87558787
| perf-regression.cpp:6:3:6:5 | Address | &:r6_5 |
87568788
| perf-regression.cpp:6:3:6:5 | Address | &:r6_7 |

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10057,6 +10057,54 @@ ir.cpp:
1005710057
# 1883| v1883_5(void) = AliasedUse : ~m?
1005810058
# 1883| v1883_6(void) = ExitFunction :
1005910059

10060+
# 1889| char global_template<char>
10061+
# 1889| Block 0
10062+
# 1889| v1889_1(void) = EnterFunction :
10063+
# 1889| mu1889_2(unknown) = AliasedDefinition :
10064+
# 1889| r1889_3(glval<char>) = VariableAddress[global_template] :
10065+
# 1889| r1889_4(char) = Constant[42] :
10066+
# 1889| mu1889_5(char) = Store[global_template] : &:r1889_3, r1889_4
10067+
# 1889| v1889_6(void) = ReturnVoid :
10068+
# 1889| v1889_7(void) = AliasedUse : ~m?
10069+
# 1889| v1889_8(void) = ExitFunction :
10070+
10071+
# 1889| int global_template<int>
10072+
# 1889| Block 0
10073+
# 1889| v1889_1(void) = EnterFunction :
10074+
# 1889| mu1889_2(unknown) = AliasedDefinition :
10075+
# 1889| r1889_3(glval<int>) = VariableAddress[global_template] :
10076+
# 1889| r1889_4(int) = Constant[42] :
10077+
# 1889| mu1889_5(int) = Store[global_template] : &:r1889_3, r1889_4
10078+
# 1889| v1889_6(void) = ReturnVoid :
10079+
# 1889| v1889_7(void) = AliasedUse : ~m?
10080+
# 1889| v1889_8(void) = ExitFunction :
10081+
10082+
# 1891| int test_global_template_int()
10083+
# 1891| Block 0
10084+
# 1891| v1891_1(void) = EnterFunction :
10085+
# 1891| mu1891_2(unknown) = AliasedDefinition :
10086+
# 1891| mu1891_3(unknown) = InitializeNonLocal :
10087+
# 1892| r1892_1(glval<int>) = VariableAddress[local_int] :
10088+
# 1892| r1892_2(glval<int>) = VariableAddress[global_template] :
10089+
# 1892| r1892_3(int) = Load[global_template] : &:r1892_2, ~m?
10090+
# 1892| mu1892_4(int) = Store[local_int] : &:r1892_1, r1892_3
10091+
# 1893| r1893_1(glval<char>) = VariableAddress[local_char] :
10092+
# 1893| r1893_2(glval<char>) = VariableAddress[global_template] :
10093+
# 1893| r1893_3(char) = Load[global_template] : &:r1893_2, ~m?
10094+
# 1893| mu1893_4(char) = Store[local_char] : &:r1893_1, r1893_3
10095+
# 1894| r1894_1(glval<int>) = VariableAddress[#return] :
10096+
# 1894| r1894_2(glval<int>) = VariableAddress[local_int] :
10097+
# 1894| r1894_3(int) = Load[local_int] : &:r1894_2, ~m?
10098+
# 1894| r1894_4(glval<char>) = VariableAddress[local_char] :
10099+
# 1894| r1894_5(char) = Load[local_char] : &:r1894_4, ~m?
10100+
# 1894| r1894_6(int) = Convert : r1894_5
10101+
# 1894| r1894_7(int) = Add : r1894_3, r1894_6
10102+
# 1894| mu1894_8(int) = Store[#return] : &:r1894_1, r1894_7
10103+
# 1891| r1891_4(glval<int>) = VariableAddress[#return] :
10104+
# 1891| v1891_5(void) = ReturnValue : &:r1891_4, ~m?
10105+
# 1891| v1891_6(void) = AliasedUse : ~m?
10106+
# 1891| v1891_7(void) = ExitFunction :
10107+
1006010108
perf-regression.cpp:
1006110109
# 6| void Big::Big()
1006210110
# 6| Block 0

0 commit comments

Comments
 (0)