Skip to content

Commit 5cf3b8e

Browse files
committed
C++: Add NSDMI tests
1 parent 6a904ed commit 5cf3b8e

File tree

5 files changed

+256
-0
lines changed

5 files changed

+256
-0
lines changed

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

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25642,6 +25642,97 @@ ir.cpp:
2564225642
# 2884| Type = [VoidType] void
2564325643
# 2884| ValueCategory = prvalue
2564425644
# 2886| getStmt(6): [ReturnStmt] return ...
25645+
# 2889| [CopyAssignmentOperator] StructInit& StructInit::operator=(StructInit const&)
25646+
# 2889| <params>:
25647+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
25648+
#-----| Type = [LValueReferenceType] const StructInit &
25649+
# 2889| [MoveAssignmentOperator] StructInit& StructInit::operator=(StructInit&&)
25650+
# 2889| <params>:
25651+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
25652+
#-----| Type = [RValueReferenceType] StructInit &&
25653+
# 2889| [CopyConstructor] void StructInit::StructInit(StructInit const&)
25654+
# 2889| <params>:
25655+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
25656+
#-----| Type = [LValueReferenceType] const StructInit &
25657+
# 2889| [MoveConstructor] void StructInit::StructInit(StructInit&&)
25658+
# 2889| <params>:
25659+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
25660+
#-----| Type = [RValueReferenceType] StructInit &&
25661+
# 2897| [Constructor] void StructInit::StructInit(int)
25662+
# 2897| <params>:
25663+
# 2897| getParameter(0): [Parameter] j
25664+
# 2897| Type = [IntType] int
25665+
# 2897| <initializations>:
25666+
# 2897| getInitializer(0): [ConstructorFieldInit] constructor init of field i
25667+
# 2897| Type = [IntType] int
25668+
# 2897| ValueCategory = prvalue
25669+
# 2897| getInitializer(1): [ConstructorFieldInit] constructor init of field j
25670+
# 2897| Type = [IntType] int
25671+
# 2897| ValueCategory = prvalue
25672+
# 2897| getExpr(): [VariableAccess] j
25673+
# 2897| Type = [IntType] int
25674+
# 2897| ValueCategory = prvalue(load)
25675+
# 2897| getInitializer(2): [ConstructorFieldInit] constructor init of field k
25676+
# 2897| Type = [IntType] int
25677+
# 2897| ValueCategory = prvalue
25678+
# 2897| getInitializer(3): [ConstructorFieldInit] constructor init of field l
25679+
# 2897| Type = [IntType] int
25680+
# 2897| ValueCategory = prvalue
25681+
# 2897| getInitializer(4): [ConstructorFieldInit] constructor init of field m
25682+
# 2897| Type = [IntType] int
25683+
# 2897| ValueCategory = prvalue
25684+
# 2897| getInitializer(5): [ConstructorFieldInit] constructor init of field n
25685+
# 2897| Type = [IntType] int
25686+
# 2897| ValueCategory = prvalue
25687+
# 2897| getExpr(): [FunctionCall] call to get_val
25688+
# 2897| Type = [IntType] int
25689+
# 2897| ValueCategory = prvalue
25690+
# 2897| getQualifier(): [ThisExpr] this
25691+
# 2897| Type = [PointerType] StructInit *
25692+
# 2897| ValueCategory = prvalue(load)
25693+
# 2897| getEntryPoint(): [BlockStmt] { ... }
25694+
# 2897| getStmt(0): [ReturnStmt] return ...
25695+
# 2899| [Constructor] void StructInit::StructInit()
25696+
# 2899| <params>:
25697+
# 2899| <initializations>:
25698+
# 2899| getInitializer(0): [ConstructorFieldInit] constructor init of field i
25699+
# 2899| Type = [IntType] int
25700+
# 2899| ValueCategory = prvalue
25701+
# 2899| getExpr(): [Literal] 41
25702+
# 2899| Type = [IntType] int
25703+
# 2899| Value = [Literal] 41
25704+
# 2899| ValueCategory = prvalue
25705+
# 2899| getInitializer(1): [ConstructorFieldInit] constructor init of field j
25706+
# 2899| Type = [IntType] int
25707+
# 2899| ValueCategory = prvalue
25708+
# 2899| getInitializer(2): [ConstructorFieldInit] constructor init of field k
25709+
# 2899| Type = [IntType] int
25710+
# 2899| ValueCategory = prvalue
25711+
# 2899| getExpr(): [Literal] 41
25712+
# 2899| Type = [IntType] int
25713+
# 2899| Value = [Literal] 41
25714+
# 2899| ValueCategory = prvalue
25715+
# 2899| getInitializer(3): [ConstructorFieldInit] constructor init of field l
25716+
# 2899| Type = [IntType] int
25717+
# 2899| ValueCategory = prvalue
25718+
# 2899| getInitializer(4): [ConstructorFieldInit] constructor init of field m
25719+
# 2899| Type = [IntType] int
25720+
# 2899| ValueCategory = prvalue
25721+
# 2899| getInitializer(5): [ConstructorFieldInit] constructor init of field n
25722+
# 2899| Type = [IntType] int
25723+
# 2899| ValueCategory = prvalue
25724+
# 2899| getEntryPoint(): [BlockStmt] { ... }
25725+
# 2899| getStmt(0): [ReturnStmt] return ...
25726+
# 2901| [MemberFunction] int StructInit::get_val()
25727+
# 2901| <params>:
25728+
# 2901| getEntryPoint(): [BlockStmt] { ... }
25729+
# 2901| getStmt(0): [ReturnStmt] return ...
25730+
# 2901| getExpr(): [ImplicitThisFieldAccess,PointerFieldAccess] k
25731+
# 2901| Type = [IntType] int
25732+
# 2901| ValueCategory = prvalue(load)
25733+
# 2901| getQualifier(): [ThisExpr] this
25734+
# 2901| Type = [PointerType] StructInit *
25735+
# 2901| ValueCategory = prvalue(load)
2564525736
ir23.cpp:
2564625737
# 1| [TopLevelFunction] bool consteval_1()
2564725738
# 1| <params>:

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21066,6 +21066,66 @@ ir.cpp:
2106621066
# 2867| v2867_14(void) = ReturnVoid :
2106721067
#-----| Goto -> Block 1
2106821068

21069+
# 2897| void StructInit::StructInit(int)
21070+
# 2897| Block 0
21071+
# 2897| v2897_1(void) = EnterFunction :
21072+
# 2897| m2897_2(unknown) = AliasedDefinition :
21073+
# 2897| m2897_3(unknown) = InitializeNonLocal :
21074+
# 2897| m2897_4(unknown) = Chi : total:m2897_2, partial:m2897_3
21075+
# 2897| r2897_5(glval<unknown>) = VariableAddress[#this] :
21076+
# 2897| m2897_6(glval<StructInit>) = InitializeParameter[#this] : &:r2897_5
21077+
# 2897| r2897_7(glval<StructInit>) = Load[#this] : &:r2897_5, m2897_6
21078+
# 2897| m2897_8(StructInit) = InitializeIndirection[#this] : &:r2897_7
21079+
# 2897| r2897_9(glval<int>) = VariableAddress[j] :
21080+
# 2897| m2897_10(int) = InitializeParameter[j] : &:r2897_9
21081+
# 2897| v2897_11(void) = NoOp :
21082+
# 2897| v2897_12(void) = ReturnIndirection[#this] : &:r2897_7, m2897_8
21083+
# 2897| v2897_13(void) = ReturnVoid :
21084+
# 2897| v2897_14(void) = AliasedUse : m2897_3
21085+
# 2897| v2897_15(void) = ExitFunction :
21086+
21087+
# 2899| void StructInit::StructInit()
21088+
# 2899| Block 0
21089+
# 2899| v2899_1(void) = EnterFunction :
21090+
# 2899| m2899_2(unknown) = AliasedDefinition :
21091+
# 2899| m2899_3(unknown) = InitializeNonLocal :
21092+
# 2899| m2899_4(unknown) = Chi : total:m2899_2, partial:m2899_3
21093+
# 2899| r2899_5(glval<unknown>) = VariableAddress[#this] :
21094+
# 2899| m2899_6(glval<StructInit>) = InitializeParameter[#this] : &:r2899_5
21095+
# 2899| r2899_7(glval<StructInit>) = Load[#this] : &:r2899_5, m2899_6
21096+
# 2899| m2899_8(StructInit) = InitializeIndirection[#this] : &:r2899_7
21097+
# 2899| r2899_9(glval<int>) = FieldAddress[i] : r2899_7
21098+
# 2899| r2899_10(int) = Constant[41] :
21099+
# 2899| m2899_11(int) = Store[?] : &:r2899_9, r2899_10
21100+
# 2899| m2899_12(unknown) = Chi : total:m2899_8, partial:m2899_11
21101+
# 2899| v2899_13(void) = NoOp :
21102+
# 2899| v2899_14(void) = ReturnIndirection[#this] : &:r2899_7, m2899_12
21103+
# 2899| v2899_15(void) = ReturnVoid :
21104+
# 2899| v2899_16(void) = AliasedUse : m2899_3
21105+
# 2899| v2899_17(void) = ExitFunction :
21106+
21107+
# 2901| int StructInit::get_val()
21108+
# 2901| Block 0
21109+
# 2901| v2901_1(void) = EnterFunction :
21110+
# 2901| m2901_2(unknown) = AliasedDefinition :
21111+
# 2901| m2901_3(unknown) = InitializeNonLocal :
21112+
# 2901| m2901_4(unknown) = Chi : total:m2901_2, partial:m2901_3
21113+
# 2901| r2901_5(glval<unknown>) = VariableAddress[#this] :
21114+
# 2901| m2901_6(glval<StructInit>) = InitializeParameter[#this] : &:r2901_5
21115+
# 2901| r2901_7(glval<StructInit>) = Load[#this] : &:r2901_5, m2901_6
21116+
# 2901| m2901_8(StructInit) = InitializeIndirection[#this] : &:r2901_7
21117+
# 2901| r2901_9(glval<int>) = VariableAddress[#return] :
21118+
# 2901| r2901_10(glval<unknown>) = VariableAddress[#this] :
21119+
# 2901| r2901_11(StructInit *) = Load[#this] : &:r2901_10, m2901_6
21120+
# 2901| r2901_12(glval<int>) = FieldAddress[k] : r2901_11
21121+
# 2901| r2901_13(int) = Load[?] : &:r2901_12, ~m2901_8
21122+
# 2901| m2901_14(int) = Store[#return] : &:r2901_9, r2901_13
21123+
# 2901| v2901_15(void) = ReturnIndirection[#this] : &:r2901_7, m2901_8
21124+
# 2901| r2901_16(glval<int>) = VariableAddress[#return] :
21125+
# 2901| v2901_17(void) = ReturnValue : &:r2901_16, m2901_14
21126+
# 2901| v2901_18(void) = AliasedUse : m2901_3
21127+
# 2901| v2901_19(void) = ExitFunction :
21128+
2106921129
ir23.cpp:
2107021130
# 1| bool consteval_1()
2107121131
# 1| Block 0

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2886,4 +2886,19 @@ namespace {
28862886
}
28872887
}
28882888

2889+
struct StructInit {
2890+
int i = 42;
2891+
int j = 42;
2892+
int k = 42;
2893+
int l = k;
2894+
int m = get_val();
2895+
int n = 42;
2896+
2897+
StructInit(int j) : j(j), n(get_val()) {}
2898+
2899+
StructInit() : i(41), k(41) {}
2900+
2901+
int get_val() { return k; }
2902+
};
2903+
28892904
// semmle-extractor-options: -std=c++20 --clang

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ lostReachability
2121
backEdgeCountMismatch
2222
useNotDominatedByDefinition
2323
| ir.cpp:1537:8:1537:8 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:1537:8:1537:8 | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() | void StructuredBindingDataMemberStruct::StructuredBindingDataMemberStruct() |
24+
| ir.cpp:2897:5:2897:14 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:2897:5:2897:14 | void StructInit::StructInit(int) | void StructInit::StructInit(int) |
25+
| ir.cpp:2897:5:2897:14 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:2897:5:2897:14 | void StructInit::StructInit(int) | void StructInit::StructInit(int) |
26+
| ir.cpp:2899:5:2899:14 | Unary | Operand 'Unary' is not dominated by its definition in function '$@'. | ir.cpp:2899:5:2899:14 | void StructInit::StructInit() | void StructInit::StructInit() |
2427
switchInstructionWithoutDefaultEdge
2528
notMarkedAsConflated
2629
wronglyMarkedAsConflated

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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19200,6 +19200,93 @@ ir.cpp:
1920019200
# 2867| v2867_13(void) = ReturnVoid :
1920119201
#-----| Goto -> Block 1
1920219202

19203+
# 2897| void StructInit::StructInit(int)
19204+
# 2897| Block 0
19205+
# 2897| v2897_1(void) = EnterFunction :
19206+
# 2897| mu2897_2(unknown) = AliasedDefinition :
19207+
# 2897| mu2897_3(unknown) = InitializeNonLocal :
19208+
# 2897| r2897_4(glval<unknown>) = VariableAddress[#this] :
19209+
# 2897| mu2897_5(glval<StructInit>) = InitializeParameter[#this] : &:r2897_4
19210+
# 2897| r2897_6(glval<StructInit>) = Load[#this] : &:r2897_4, ~m?
19211+
# 2897| mu2897_7(StructInit) = InitializeIndirection[#this] : &:r2897_6
19212+
# 2897| r2897_8(glval<int>) = VariableAddress[j] :
19213+
# 2897| mu2897_9(int) = InitializeParameter[j] : &:r2897_8
19214+
#-----| Goto -> Block 3
19215+
19216+
# 2897| Block 1
19217+
# 2897| r2897_10(glval<int>) = FieldAddress[j] : r2897_6
19218+
# 2897| r2897_11(glval<int>) = VariableAddress[j] :
19219+
# 2897| r2897_12(int) = Load[j] : &:r2897_11, ~m?
19220+
# 2897| mu2897_13(int) = Store[?] : &:r2897_10, r2897_12
19221+
#-----| Goto -> Block 3
19222+
19223+
# 2897| Block 2
19224+
# 2897| r2897_14(glval<int>) = FieldAddress[n] : r2897_6
19225+
# 2897| r2897_15(glval<unknown>) = VariableAddress[#this] :
19226+
# 2897| r2897_16(StructInit *) = Load[#this] : &:r2897_15, ~m?
19227+
# 2897| r2897_17(glval<unknown>) = FunctionAddress[get_val] :
19228+
# 2897| r2897_18(int) = Call[get_val] : func:r2897_17, this:r2897_16
19229+
# 2897| mu2897_19(unknown) = ^CallSideEffect : ~m?
19230+
# 2897| v2897_20(void) = ^IndirectReadSideEffect[-1] : &:r2897_16, ~m?
19231+
# 2897| mu2897_21(StructInit) = ^IndirectMayWriteSideEffect[-1] : &:r2897_16
19232+
# 2897| mu2897_22(int) = Store[?] : &:r2897_14, r2897_18
19233+
#-----| Goto -> Block 3
19234+
19235+
# 2897| Block 3
19236+
# 2897| v2897_23(void) = NoOp :
19237+
# 2897| v2897_24(void) = ReturnIndirection[#this] : &:r2897_6, ~m?
19238+
# 2897| v2897_25(void) = ReturnVoid :
19239+
# 2897| v2897_26(void) = AliasedUse : ~m?
19240+
# 2897| v2897_27(void) = ExitFunction :
19241+
19242+
# 2899| void StructInit::StructInit()
19243+
# 2899| Block 0
19244+
# 2899| v2899_1(void) = EnterFunction :
19245+
# 2899| mu2899_2(unknown) = AliasedDefinition :
19246+
# 2899| mu2899_3(unknown) = InitializeNonLocal :
19247+
# 2899| r2899_4(glval<unknown>) = VariableAddress[#this] :
19248+
# 2899| mu2899_5(glval<StructInit>) = InitializeParameter[#this] : &:r2899_4
19249+
# 2899| r2899_6(glval<StructInit>) = Load[#this] : &:r2899_4, ~m?
19250+
# 2899| mu2899_7(StructInit) = InitializeIndirection[#this] : &:r2899_6
19251+
# 2899| r2899_8(glval<int>) = FieldAddress[i] : r2899_6
19252+
# 2899| r2899_9(int) = Constant[41] :
19253+
# 2899| mu2899_10(int) = Store[?] : &:r2899_8, r2899_9
19254+
#-----| Goto -> Block 2
19255+
19256+
# 2899| Block 1
19257+
# 2899| r2899_11(glval<int>) = FieldAddress[k] : r2899_6
19258+
# 2899| r2899_12(int) = Constant[41] :
19259+
# 2899| mu2899_13(int) = Store[?] : &:r2899_11, r2899_12
19260+
#-----| Goto -> Block 2
19261+
19262+
# 2899| Block 2
19263+
# 2899| v2899_14(void) = NoOp :
19264+
# 2899| v2899_15(void) = ReturnIndirection[#this] : &:r2899_6, ~m?
19265+
# 2899| v2899_16(void) = ReturnVoid :
19266+
# 2899| v2899_17(void) = AliasedUse : ~m?
19267+
# 2899| v2899_18(void) = ExitFunction :
19268+
19269+
# 2901| int StructInit::get_val()
19270+
# 2901| Block 0
19271+
# 2901| v2901_1(void) = EnterFunction :
19272+
# 2901| mu2901_2(unknown) = AliasedDefinition :
19273+
# 2901| mu2901_3(unknown) = InitializeNonLocal :
19274+
# 2901| r2901_4(glval<unknown>) = VariableAddress[#this] :
19275+
# 2901| mu2901_5(glval<StructInit>) = InitializeParameter[#this] : &:r2901_4
19276+
# 2901| r2901_6(glval<StructInit>) = Load[#this] : &:r2901_4, ~m?
19277+
# 2901| mu2901_7(StructInit) = InitializeIndirection[#this] : &:r2901_6
19278+
# 2901| r2901_8(glval<int>) = VariableAddress[#return] :
19279+
# 2901| r2901_9(glval<unknown>) = VariableAddress[#this] :
19280+
# 2901| r2901_10(StructInit *) = Load[#this] : &:r2901_9, ~m?
19281+
# 2901| r2901_11(glval<int>) = FieldAddress[k] : r2901_10
19282+
# 2901| r2901_12(int) = Load[?] : &:r2901_11, ~m?
19283+
# 2901| mu2901_13(int) = Store[#return] : &:r2901_8, r2901_12
19284+
# 2901| v2901_14(void) = ReturnIndirection[#this] : &:r2901_6, ~m?
19285+
# 2901| r2901_15(glval<int>) = VariableAddress[#return] :
19286+
# 2901| v2901_16(void) = ReturnValue : &:r2901_15, ~m?
19287+
# 2901| v2901_17(void) = AliasedUse : ~m?
19288+
# 2901| v2901_18(void) = ExitFunction :
19289+
1920319290
ir23.cpp:
1920419291
# 1| bool consteval_1()
1920519292
# 1| Block 0

0 commit comments

Comments
 (0)