diff --git a/cpp/ql/test/library-tests/ir/ir/PrintAST.expected b/cpp/ql/test/library-tests/ir/ir/PrintAST.expected index 98f4aba0494..3cd0c9b4dc3 100644 --- a/cpp/ql/test/library-tests/ir/ir/PrintAST.expected +++ b/cpp/ql/test/library-tests/ir/ir/PrintAST.expected @@ -14377,6 +14377,37 @@ ir.cpp: # 1885| Type = [ClassTemplateInstantiation,Struct] Bar2 # 1885| ValueCategory = lvalue # 1886| getStmt(2): [ReturnStmt] return ... +# 1891| [TopLevelFunction] int test_global_template_int() +# 1891| : +# 1891| getEntryPoint(): [BlockStmt] { ... } +# 1892| getStmt(0): [DeclStmt] declaration +# 1892| getDeclarationEntry(0): [VariableDeclarationEntry] definition of local_int +# 1892| Type = [IntType] int +# 1892| getVariable().getInitializer(): [Initializer] initializer for local_int +# 1892| getExpr(): [VariableAccess] global_template +# 1892| Type = [IntType] int +# 1892| ValueCategory = prvalue(load) +# 1893| getStmt(1): [DeclStmt] declaration +# 1893| getDeclarationEntry(0): [VariableDeclarationEntry] definition of local_char +# 1893| Type = [PlainCharType] char +# 1893| getVariable().getInitializer(): [Initializer] initializer for local_char +# 1893| getExpr(): [VariableAccess] global_template +# 1893| Type = [PlainCharType] char +# 1893| ValueCategory = prvalue(load) +# 1894| getStmt(2): [ReturnStmt] return ... +# 1894| getExpr(): [AddExpr] ... + ... +# 1894| Type = [IntType] int +# 1894| ValueCategory = prvalue +# 1894| getLeftOperand(): [VariableAccess] local_int +# 1894| Type = [IntType] int +# 1894| ValueCategory = prvalue(load) +# 1894| getRightOperand(): [VariableAccess] local_char +# 1894| Type = [PlainCharType] char +# 1894| ValueCategory = prvalue(load) +# 1894| getRightOperand().getFullyConverted(): [CStyleCast] (int)... +# 1894| Conversion = [IntegralConversion] integral conversion +# 1894| Type = [IntType] int +# 1894| ValueCategory = prvalue perf-regression.cpp: # 4| [CopyAssignmentOperator] Big& Big::operator=(Big const&) # 4| : diff --git a/cpp/ql/test/library-tests/ir/ir/ir.cpp b/cpp/ql/test/library-tests/ir/ir/ir.cpp index 5a8d500fa43..8d478d0f035 100644 --- a/cpp/ql/test/library-tests/ir/ir/ir.cpp +++ b/cpp/ql/test/library-tests/ir/ir/ir.cpp @@ -1886,4 +1886,12 @@ namespace missing_declaration_entries { } } +template T global_template = 42; + +int test_global_template_int() { + int local_int = global_template; + char local_char = global_template; + return local_int + (int)local_char; +} + // semmle-extractor-options: -std=c++17 --clang diff --git a/cpp/ql/test/library-tests/ir/ir/operand_locations.expected b/cpp/ql/test/library-tests/ir/ir/operand_locations.expected index ef85dfb1279..d6091c27466 100644 --- a/cpp/ql/test/library-tests/ir/ir/operand_locations.expected +++ b/cpp/ql/test/library-tests/ir/ir/operand_locations.expected @@ -8751,6 +8751,38 @@ | ir.cpp:1885:11:1885:50 | ChiPartial | partial:m1885_4 | | ir.cpp:1885:11:1885:50 | ChiTotal | total:m1883_4 | | ir.cpp:1885:11:1885:50 | SideEffect | ~m1883_4 | +| ir.cpp:1889:24:1889:24 | Address | &:r1889_3 | +| ir.cpp:1889:24:1889:24 | Address | &:r1889_3 | +| ir.cpp:1889:24:1889:24 | SideEffect | ~m1889_6 | +| ir.cpp:1889:24:1889:24 | SideEffect | ~m1889_6 | +| ir.cpp:1889:42:1889:43 | ChiPartial | partial:m1889_5 | +| ir.cpp:1889:42:1889:43 | ChiPartial | partial:m1889_5 | +| ir.cpp:1889:42:1889:43 | ChiTotal | total:m1889_2 | +| ir.cpp:1889:42:1889:43 | ChiTotal | total:m1889_2 | +| ir.cpp:1889:42:1889:43 | StoreValue | r1889_4 | +| ir.cpp:1889:42:1889:43 | StoreValue | r1889_4 | +| ir.cpp:1891:5:1891:28 | Address | &:r1891_5 | +| ir.cpp:1891:5:1891:28 | ChiPartial | partial:m1891_3 | +| ir.cpp:1891:5:1891:28 | ChiTotal | total:m1891_2 | +| ir.cpp:1891:5:1891:28 | Load | m1894_8 | +| ir.cpp:1891:5:1891:28 | SideEffect | m1891_3 | +| ir.cpp:1892:9:1892:17 | Address | &:r1892_1 | +| ir.cpp:1892:21:1892:40 | Address | &:r1892_2 | +| ir.cpp:1892:21:1892:40 | Load | ~m1891_3 | +| ir.cpp:1892:21:1892:40 | StoreValue | r1892_3 | +| ir.cpp:1893:10:1893:19 | Address | &:r1893_1 | +| ir.cpp:1893:23:1893:43 | Address | &:r1893_2 | +| ir.cpp:1893:23:1893:43 | Load | ~m1891_3 | +| ir.cpp:1893:23:1893:43 | StoreValue | r1893_3 | +| ir.cpp:1894:5:1894:39 | Address | &:r1894_1 | +| ir.cpp:1894:12:1894:20 | Address | &:r1894_2 | +| ir.cpp:1894:12:1894:20 | Left | r1894_3 | +| ir.cpp:1894:12:1894:20 | Load | m1892_4 | +| ir.cpp:1894:12:1894:38 | StoreValue | r1894_7 | +| ir.cpp:1894:24:1894:38 | Right | r1894_6 | +| ir.cpp:1894:29:1894:38 | Address | &:r1894_4 | +| ir.cpp:1894:29:1894:38 | Load | m1893_4 | +| ir.cpp:1894:29:1894:38 | Unary | r1894_5 | | perf-regression.cpp:6:3:6:5 | Address | &:r6_5 | | perf-regression.cpp:6:3:6:5 | Address | &:r6_5 | | perf-regression.cpp:6:3:6:5 | Address | &:r6_7 | diff --git a/cpp/ql/test/library-tests/ir/ir/raw_ir.expected b/cpp/ql/test/library-tests/ir/ir/raw_ir.expected index 07ffa1082f4..abcc5bbe0c7 100644 --- a/cpp/ql/test/library-tests/ir/ir/raw_ir.expected +++ b/cpp/ql/test/library-tests/ir/ir/raw_ir.expected @@ -10057,6 +10057,54 @@ ir.cpp: # 1883| v1883_5(void) = AliasedUse : ~m? # 1883| v1883_6(void) = ExitFunction : +# 1889| char global_template +# 1889| Block 0 +# 1889| v1889_1(void) = EnterFunction : +# 1889| mu1889_2(unknown) = AliasedDefinition : +# 1889| r1889_3(glval) = VariableAddress[global_template] : +# 1889| r1889_4(char) = Constant[42] : +# 1889| mu1889_5(char) = Store[global_template] : &:r1889_3, r1889_4 +# 1889| v1889_6(void) = ReturnVoid : +# 1889| v1889_7(void) = AliasedUse : ~m? +# 1889| v1889_8(void) = ExitFunction : + +# 1889| int global_template +# 1889| Block 0 +# 1889| v1889_1(void) = EnterFunction : +# 1889| mu1889_2(unknown) = AliasedDefinition : +# 1889| r1889_3(glval) = VariableAddress[global_template] : +# 1889| r1889_4(int) = Constant[42] : +# 1889| mu1889_5(int) = Store[global_template] : &:r1889_3, r1889_4 +# 1889| v1889_6(void) = ReturnVoid : +# 1889| v1889_7(void) = AliasedUse : ~m? +# 1889| v1889_8(void) = ExitFunction : + +# 1891| int test_global_template_int() +# 1891| Block 0 +# 1891| v1891_1(void) = EnterFunction : +# 1891| mu1891_2(unknown) = AliasedDefinition : +# 1891| mu1891_3(unknown) = InitializeNonLocal : +# 1892| r1892_1(glval) = VariableAddress[local_int] : +# 1892| r1892_2(glval) = VariableAddress[global_template] : +# 1892| r1892_3(int) = Load[global_template] : &:r1892_2, ~m? +# 1892| mu1892_4(int) = Store[local_int] : &:r1892_1, r1892_3 +# 1893| r1893_1(glval) = VariableAddress[local_char] : +# 1893| r1893_2(glval) = VariableAddress[global_template] : +# 1893| r1893_3(char) = Load[global_template] : &:r1893_2, ~m? +# 1893| mu1893_4(char) = Store[local_char] : &:r1893_1, r1893_3 +# 1894| r1894_1(glval) = VariableAddress[#return] : +# 1894| r1894_2(glval) = VariableAddress[local_int] : +# 1894| r1894_3(int) = Load[local_int] : &:r1894_2, ~m? +# 1894| r1894_4(glval) = VariableAddress[local_char] : +# 1894| r1894_5(char) = Load[local_char] : &:r1894_4, ~m? +# 1894| r1894_6(int) = Convert : r1894_5 +# 1894| r1894_7(int) = Add : r1894_3, r1894_6 +# 1894| mu1894_8(int) = Store[#return] : &:r1894_1, r1894_7 +# 1891| r1891_4(glval) = VariableAddress[#return] : +# 1891| v1891_5(void) = ReturnValue : &:r1891_4, ~m? +# 1891| v1891_6(void) = AliasedUse : ~m? +# 1891| v1891_7(void) = ExitFunction : + perf-regression.cpp: # 6| void Big::Big() # 6| Block 0