Skip to content

Commit 346ab9d

Browse files
committed
C++: Add struct and variable template tests
1 parent dad517f commit 346ab9d

9 files changed

+342
-0
lines changed

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

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25733,6 +25733,77 @@ ir.cpp:
2573325733
# 2901| getQualifier(): [ThisExpr] this
2573425734
# 2901| Type = [PointerType] StructInit *
2573525735
# 2901| ValueCategory = prvalue(load)
25736+
# 2905| [Constructor] void StructInitFromTemplate<int>::StructInitFromTemplate()
25737+
# 2905| <params>:
25738+
# 2905| <initializations>:
25739+
# 2905| getInitializer(0): [ConstructorDefaultFieldInit] constructor init of field t
25740+
# 2905| Type = [IntType] int
25741+
# 2905| ValueCategory = prvalue
25742+
# 2905| getEntryPoint(): [BlockStmt] { ... }
25743+
# 2905| getStmt(0): [ReturnStmt] return ...
25744+
# 2909| [GlobalVariable] StructInitFromTemplate<int> StructInitFromTemplateVar
25745+
#-----| getInitializer(): [Initializer] initializer for StructInitFromTemplateVar
25746+
#-----| getExpr(): [ConstructorCall] call to StructInitFromTemplate
25747+
#-----| Type = [VoidType] void
25748+
#-----| ValueCategory = prvalue
25749+
#-----| getExpr().getFullyConverted(): [TemporaryObjectExpr] temporary object
25750+
#-----| Type = [ClassTemplateInstantiation,Struct] StructInitFromTemplate<int>
25751+
#-----| ValueCategory = prvalue(load)
25752+
# 2912| [GlobalVariable,VariableTemplateInstantiation] double VariableTemplate<double>
25753+
# 2912| getInitializer(): [Initializer] initializer for VariableTemplate
25754+
# 2912| getExpr(): [Literal] 42
25755+
# 2912| Type = [IntType] int
25756+
# 2912| Value = [Literal] 42
25757+
# 2912| ValueCategory = prvalue
25758+
# 2912| getExpr().getFullyConverted(): [CStyleCast] (double)...
25759+
# 2912| Conversion = [IntegralToFloatingPointConversion] integral to floating point conversion
25760+
# 2912| Type = [DoubleType] double
25761+
# 2912| Value = [CStyleCast] 42.0
25762+
# 2912| ValueCategory = prvalue
25763+
# 2915| [TemplateFunction,TopLevelFunction] T VariableTemplateFunc<T>(T)
25764+
# 2915| <params>:
25765+
# 2915| getParameter(0): [Parameter] x
25766+
# 2915| Type = [TypeTemplateParameter] T
25767+
# 2915| getEntryPoint(): [BlockStmt] { ... }
25768+
# 2916| getStmt(0): [ReturnStmt] return ...
25769+
# 2916| getExpr(): [AddExpr] ... + ...
25770+
# 2916| Type = [UnknownType] unknown
25771+
# 2916| ValueCategory = prvalue
25772+
# 2916| getLeftOperand(): [VariableAccess] VariableTemplate
25773+
# 2916| Type = [UnknownType] unknown
25774+
# 2916| ValueCategory = lvalue
25775+
# 2916| getRightOperand(): [VariableAccess] x
25776+
# 2916| Type = [TypeTemplateParameter] T
25777+
# 2916| ValueCategory = lvalue
25778+
# 2915| [FunctionTemplateInstantiation,TopLevelFunction] double VariableTemplateFunc<double>(double)
25779+
# 2915| <params>:
25780+
# 2915| getParameter(0): [Parameter] x
25781+
# 2915| Type = [DoubleType] double
25782+
# 2915| getEntryPoint(): [BlockStmt] { ... }
25783+
# 2916| getStmt(0): [ReturnStmt] return ...
25784+
# 2916| getExpr(): [AddExpr] ... + ...
25785+
# 2916| Type = [DoubleType] double
25786+
# 2916| ValueCategory = prvalue
25787+
# 2916| getLeftOperand(): [VariableAccess] VariableTemplate
25788+
# 2916| Type = [DoubleType] double
25789+
# 2916| Value = [VariableAccess] 42.0
25790+
# 2916| ValueCategory = prvalue(load)
25791+
# 2916| getRightOperand(): [VariableAccess] x
25792+
# 2916| Type = [DoubleType] double
25793+
# 2916| ValueCategory = prvalue(load)
25794+
# 2919| [GlobalVariable] int VariableTemplateFuncUse
25795+
# 2919| getInitializer(): [Initializer] initializer for VariableTemplateFuncUse
25796+
# 2919| getExpr(): [FunctionCall] call to VariableTemplateFunc
25797+
# 2919| Type = [DoubleType] double
25798+
# 2919| ValueCategory = prvalue
25799+
# 2919| getArgument(0): [Literal] 2.299999999999999822
25800+
# 2919| Type = [DoubleType] double
25801+
# 2919| Value = [Literal] 2.299999999999999822
25802+
# 2919| ValueCategory = prvalue
25803+
# 2919| getExpr().getFullyConverted(): [CStyleCast] (int)...
25804+
# 2919| Conversion = [FloatingPointToIntegralConversion] floating point to integral conversion
25805+
# 2919| Type = [IntType] int
25806+
# 2919| ValueCategory = prvalue
2573625807
ir23.cpp:
2573725808
# 1| [TopLevelFunction] bool consteval_1()
2573825809
# 1| <params>:

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

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21658,6 +21658,133 @@ ir.cpp:
2165821658
# 2901| v2901_18(void) = AliasedUse : m2901_3
2165921659
# 2901| v2901_19(void) = ExitFunction :
2166021660

21661+
# 2905| void StructInitFromTemplate<int>::StructInitFromTemplate()
21662+
# 2905| Block 0
21663+
# 2905| v2905_1(void) = EnterFunction :
21664+
# 2905| m2905_2(unknown) = AliasedDefinition :
21665+
# 2905| m2905_3(unknown) = InitializeNonLocal :
21666+
# 2905| m2905_4(unknown) = Chi : total:m2905_2, partial:m2905_3
21667+
# 2905| r2905_5(glval<unknown>) = VariableAddress[#this] :
21668+
# 2905| m2905_6(glval<StructInitFromTemplate<int>>) = InitializeParameter[#this] : &:r2905_5
21669+
# 2905| r2905_7(glval<StructInitFromTemplate<int>>) = Load[#this] : &:r2905_5, m2905_6
21670+
# 2905| m2905_8(StructInitFromTemplate<int>) = InitializeIndirection[#this] : &:r2905_7
21671+
# 2905| m2905_9(unknown) = Chi : total:m2905_4, partial:m2905_8
21672+
# 2905| r2905_10(glval<unknown>) = FunctionAddress[t] :
21673+
# 2905| v2905_11(void) = Call[t] : func:r2905_10, this:r2905_7
21674+
# 2905| m2905_12(unknown) = ^CallSideEffect : ~m2905_9
21675+
# 2905| m2905_13(unknown) = Chi : total:m2905_9, partial:m2905_12
21676+
# 2905| v2905_14(void) = ^IndirectReadSideEffect[-1] : &:r2905_7, ~m2905_13
21677+
# 2905| m2905_15(StructInitFromTemplate<int>) = ^IndirectMayWriteSideEffect[-1] : &:r2905_7
21678+
# 2905| m2905_16(unknown) = Chi : total:m2905_13, partial:m2905_15
21679+
# 2905| v2905_17(void) = NoOp :
21680+
# 2905| v2905_18(void) = ReturnIndirection[#this] : &:r2905_7, ~m2905_16
21681+
# 2905| v2905_19(void) = ReturnVoid :
21682+
# 2905| v2905_20(void) = AliasedUse : ~m2905_16
21683+
# 2905| v2905_21(void) = ExitFunction :
21684+
21685+
# 2906| T StructInitFromTemplate<T>::t
21686+
# 2906| Block 0
21687+
# 2906| v2906_1(void) = EnterFunction :
21688+
# 2906| m2906_2(unknown) = AliasedDefinition :
21689+
# 2906| m2906_3(unknown) = InitializeNonLocal :
21690+
# 2906| m2906_4(unknown) = Chi : total:m2906_2, partial:m2906_3
21691+
# 2906| r2906_5(glval<unknown>) = VariableAddress[#this] :
21692+
# 2906| m2906_6(glval<StructInitFromTemplate<T>>) = InitializeParameter[#this] : &:r2906_5
21693+
# 2906| r2906_7(glval<StructInitFromTemplate<T>>) = Load[#this] : &:r2906_5, m2906_6
21694+
# 2906| m2906_8(StructInitFromTemplate<T>) = InitializeIndirection[#this] : &:r2906_7
21695+
# 2906| r2906_9(glval<T>) = FieldAddress[t] : r2906_7
21696+
# 2906| r2906_10(glval<T>) = VariableAddress :
21697+
21698+
# 2906| int StructInitFromTemplate<int>::t
21699+
# 2906| Block 0
21700+
# 2906| v2906_1(void) = EnterFunction :
21701+
# 2906| m2906_2(unknown) = AliasedDefinition :
21702+
# 2906| m2906_3(unknown) = InitializeNonLocal :
21703+
# 2906| m2906_4(unknown) = Chi : total:m2906_2, partial:m2906_3
21704+
# 2906| r2906_5(glval<unknown>) = VariableAddress[#this] :
21705+
# 2906| m2906_6(glval<StructInitFromTemplate<int>>) = InitializeParameter[#this] : &:r2906_5
21706+
# 2906| r2906_7(glval<StructInitFromTemplate<int>>) = Load[#this] : &:r2906_5, m2906_6
21707+
# 2906| m2906_8(StructInitFromTemplate<int>) = InitializeIndirection[#this] : &:r2906_7
21708+
# 2906| r2906_9(glval<int>) = FieldAddress[t] : r2906_7
21709+
# 2906| r2906_10(glval<int>) = VariableAddress[#temp2906:11] :
21710+
# 2906| r2906_11(int) = Constant[0] :
21711+
# 2906| m2906_12(int) = Store[#temp2906:11] : &:r2906_10, r2906_11
21712+
# 2906| r2906_13(int) = Load[#temp2906:11] : &:r2906_10, m2906_12
21713+
# 2906| m2906_14(int) = Store[?] : &:r2906_9, r2906_13
21714+
# 2906| m2906_15(unknown) = Chi : total:m2906_8, partial:m2906_14
21715+
# 2906| v2906_16(void) = ReturnVoid :
21716+
# 2906| v2906_17(void) = AliasedUse : m2906_3
21717+
# 2906| v2906_18(void) = ExitFunction :
21718+
21719+
# 2909| StructInitFromTemplate<int> StructInitFromTemplateVar
21720+
# 2909| Block 0
21721+
# 2909| v2909_1(void) = EnterFunction :
21722+
# 2909| m2909_2(unknown) = AliasedDefinition :
21723+
# 2909| r2909_3(glval<StructInitFromTemplate<int>>) = VariableAddress[StructInitFromTemplateVar] :
21724+
#-----| r0_1(glval<StructInitFromTemplate<int>>) = VariableAddress[#temp0:0] :
21725+
#-----| m0_2(StructInitFromTemplate<int>) = Uninitialized[#temp0:0] : &:r0_1
21726+
#-----| m0_3(unknown) = Chi : total:m2909_2, partial:m0_2
21727+
#-----| r0_4(glval<unknown>) = FunctionAddress[StructInitFromTemplate] :
21728+
#-----| v0_5(void) = Call[StructInitFromTemplate] : func:r0_4, this:r0_1
21729+
#-----| m0_6(unknown) = ^CallSideEffect : ~m0_3
21730+
#-----| m0_7(unknown) = Chi : total:m0_3, partial:m0_6
21731+
#-----| m0_8(StructInitFromTemplate<int>) = ^IndirectMayWriteSideEffect[-1] : &:r0_1
21732+
#-----| m0_9(unknown) = Chi : total:m0_7, partial:m0_8
21733+
#-----| r0_10(StructInitFromTemplate<int>) = Load[#temp0:0] : &:r0_1, ~m0_9
21734+
#-----| m0_11(StructInitFromTemplate<int>) = Store[StructInitFromTemplateVar] : &:r2909_3, r0_10
21735+
#-----| m0_12(unknown) = Chi : total:m0_9, partial:m0_11
21736+
# 2909| v2909_4(void) = ReturnVoid :
21737+
# 2909| v2909_5(void) = AliasedUse : ~m0_12
21738+
# 2909| v2909_6(void) = ExitFunction :
21739+
21740+
# 2912| double VariableTemplate<double>
21741+
# 2912| Block 0
21742+
# 2912| v2912_1(void) = EnterFunction :
21743+
# 2912| m2912_2(unknown) = AliasedDefinition :
21744+
# 2912| r2912_3(glval<double>) = VariableAddress[VariableTemplate] :
21745+
# 2912| r2912_4(double) = Constant[42.0] :
21746+
# 2912| m2912_5(double) = Store[VariableTemplate] : &:r2912_3, r2912_4
21747+
# 2912| m2912_6(unknown) = Chi : total:m2912_2, partial:m2912_5
21748+
# 2912| v2912_7(void) = ReturnVoid :
21749+
# 2912| v2912_8(void) = AliasedUse : ~m2912_6
21750+
# 2912| v2912_9(void) = ExitFunction :
21751+
21752+
# 2915| double VariableTemplateFunc<double>(double)
21753+
# 2915| Block 0
21754+
# 2915| v2915_1(void) = EnterFunction :
21755+
# 2915| m2915_2(unknown) = AliasedDefinition :
21756+
# 2915| m2915_3(unknown) = InitializeNonLocal :
21757+
# 2915| m2915_4(unknown) = Chi : total:m2915_2, partial:m2915_3
21758+
# 2915| r2915_5(glval<double>) = VariableAddress[x] :
21759+
# 2915| m2915_6(double) = InitializeParameter[x] : &:r2915_5
21760+
# 2916| r2916_1(glval<double>) = VariableAddress[#return] :
21761+
# 2916| r2916_2(double) = Constant[42.0] :
21762+
# 2916| r2916_3(glval<double>) = VariableAddress[x] :
21763+
# 2916| r2916_4(double) = Load[x] : &:r2916_3, m2915_6
21764+
# 2916| r2916_5(double) = Add : r2916_2, r2916_4
21765+
# 2916| m2916_6(double) = Store[#return] : &:r2916_1, r2916_5
21766+
# 2915| r2915_7(glval<double>) = VariableAddress[#return] :
21767+
# 2915| v2915_8(void) = ReturnValue : &:r2915_7, m2916_6
21768+
# 2915| v2915_9(void) = AliasedUse : m2915_3
21769+
# 2915| v2915_10(void) = ExitFunction :
21770+
21771+
# 2919| int VariableTemplateFuncUse
21772+
# 2919| Block 0
21773+
# 2919| v2919_1(void) = EnterFunction :
21774+
# 2919| m2919_2(unknown) = AliasedDefinition :
21775+
# 2919| r2919_3(glval<int>) = VariableAddress[VariableTemplateFuncUse] :
21776+
# 2919| r2919_4(glval<unknown>) = FunctionAddress[VariableTemplateFunc] :
21777+
# 2919| r2919_5(double) = Constant[2.299999999999999822] :
21778+
# 2919| r2919_6(double) = Call[VariableTemplateFunc] : func:r2919_4, 0:r2919_5
21779+
# 2919| m2919_7(unknown) = ^CallSideEffect : ~m2919_2
21780+
# 2919| m2919_8(unknown) = Chi : total:m2919_2, partial:m2919_7
21781+
# 2919| r2919_9(int) = Convert : r2919_6
21782+
# 2919| m2919_10(int) = Store[VariableTemplateFuncUse] : &:r2919_3, r2919_9
21783+
# 2919| m2919_11(unknown) = Chi : total:m2919_8, partial:m2919_10
21784+
# 2919| v2919_12(void) = ReturnVoid :
21785+
# 2919| v2919_13(void) = AliasedUse : ~m2919_11
21786+
# 2919| v2919_14(void) = ExitFunction :
21787+
2166121788
ir23.cpp:
2166221789
# 1| bool consteval_1()
2166321790
# 1| Block 0

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| ir.cpp:2906:11:2906:13 | VariableAddress: temporary object | Instruction 'VariableAddress: temporary object' has no successors in function '$@'. | ir.cpp:2906:7:2906:7 | T StructInitFromTemplate<T>::t | T StructInitFromTemplate<T>::t |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction
@@ -29,5 +30,6 @@ fieldAddressOnNonPointer
2930
thisArgumentIsNonPointer
3031
| ir.cpp:2548:34:2548:34 | Call: call to operator bool | Call instruction 'Call: call to operator bool' has a `this` argument operand that is not an address, in function '$@'. | ir.cpp:2547:6:2547:23 | void this_inconsistency(bool) | void this_inconsistency(bool) |
3132
nonUniqueIRVariable
33+
| ir.cpp:2906:11:2906:13 | VariableAddress: temporary object | Variable address instruction 'VariableAddress: temporary object' has no associated variable, in function '$@'. | ir.cpp:2906:7:2906:7 | T StructInitFromTemplate<T>::t | T StructInitFromTemplate<T>::t |
3234
nonBooleanOperand
3335
missingCppType

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| ir.cpp:2906:11:2906:13 | VariableAddress: temporary object | Instruction 'VariableAddress: temporary object' has no successors in function '$@'. | ir.cpp:2906:7:2906:7 | T StructInitFromTemplate<T>::t | T StructInitFromTemplate<T>::t |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction
@@ -29,5 +30,6 @@ fieldAddressOnNonPointer
2930
thisArgumentIsNonPointer
3031
| ir.cpp:2548:34:2548:34 | Call: call to operator bool | Call instruction 'Call: call to operator bool' has a `this` argument operand that is not an address, in function '$@'. | ir.cpp:2547:6:2547:23 | void this_inconsistency(bool) | void this_inconsistency(bool) |
3132
nonUniqueIRVariable
33+
| ir.cpp:2906:11:2906:13 | VariableAddress: temporary object | Variable address instruction 'VariableAddress: temporary object' has no associated variable, in function '$@'. | ir.cpp:2906:7:2906:7 | T StructInitFromTemplate<T>::t | T StructInitFromTemplate<T>::t |
3234
nonBooleanOperand
3335
missingCppType

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,4 +2901,21 @@ struct StructInit {
29012901
int get_val() { return k; }
29022902
};
29032903

2904+
template<typename T>
2905+
struct StructInitFromTemplate {
2906+
T t = T();
2907+
};
2908+
2909+
StructInitFromTemplate<int> StructInitFromTemplateVar;
2910+
2911+
template<class T>
2912+
constexpr T VariableTemplate = T(42);
2913+
2914+
template<class T>
2915+
T VariableTemplateFunc(T x) {
2916+
return VariableTemplate<T> + x;
2917+
}
2918+
2919+
int VariableTemplateFuncUse = VariableTemplateFunc(2.3);
2920+
29042921
// semmle-extractor-options: -std=c++20 --clang

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ missingOperandType
66
duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
9+
| ir.cpp:2906:11:2906:13 | VariableAddress: temporary object | Instruction 'VariableAddress: temporary object' has no successors in function '$@'. | ir.cpp:2906:7:2906:7 | T StructInitFromTemplate<T>::t | T StructInitFromTemplate<T>::t |
910
ambiguousSuccessors
1011
unexplainedLoop
1112
unnecessaryPhiInstruction
@@ -29,5 +30,6 @@ fieldAddressOnNonPointer
2930
thisArgumentIsNonPointer
3031
| ir.cpp:2548:34:2548:34 | Call: call to operator bool | Call instruction 'Call: call to operator bool' has a `this` argument operand that is not an address, in function '$@'. | ir.cpp:2547:6:2547:23 | void this_inconsistency(bool) | void this_inconsistency(bool) |
3132
nonUniqueIRVariable
33+
| ir.cpp:2906:11:2906:13 | VariableAddress: temporary object | Variable address instruction 'VariableAddress: temporary object' has no associated variable, in function '$@'. | ir.cpp:2906:7:2906:7 | T StructInitFromTemplate<T>::t | T StructInitFromTemplate<T>::t |
3234
nonBooleanOperand
3335
missingCppType

0 commit comments

Comments
 (0)