From 59c27a2196873064d37bd56d8ea9bbbc3307c2ef Mon Sep 17 00:00:00 2001 From: Jeroen Ketema Date: Fri, 27 Feb 2026 14:38:46 +0100 Subject: [PATCH] C++: Add NSDMI tests --- .../library-tests/ir/ir/PrintAST.expected | 91 +++++++++++++++++++ .../library-tests/ir/ir/aliased_ir.expected | 60 ++++++++++++ cpp/ql/test/library-tests/ir/ir/ir.cpp | 15 +++ .../ir/ir/raw_consistency.expected | 3 + .../test/library-tests/ir/ir/raw_ir.expected | 87 ++++++++++++++++++ 5 files changed, 256 insertions(+) diff --git a/cpp/ql/test/library-tests/ir/ir/PrintAST.expected b/cpp/ql/test/library-tests/ir/ir/PrintAST.expected index ec5db0c8400..c9c1334a391 100644 --- a/cpp/ql/test/library-tests/ir/ir/PrintAST.expected +++ b/cpp/ql/test/library-tests/ir/ir/PrintAST.expected @@ -25642,6 +25642,97 @@ ir.cpp: # 2884| Type = [VoidType] void # 2884| ValueCategory = prvalue # 2886| getStmt(6): [ReturnStmt] return ... +# 2889| [CopyAssignmentOperator] StructInit& StructInit::operator=(StructInit const&) +# 2889| : +#-----| getParameter(0): [Parameter] (unnamed parameter 0) +#-----| Type = [LValueReferenceType] const StructInit & +# 2889| [MoveAssignmentOperator] StructInit& StructInit::operator=(StructInit&&) +# 2889| : +#-----| getParameter(0): [Parameter] (unnamed parameter 0) +#-----| Type = [RValueReferenceType] StructInit && +# 2889| [CopyConstructor] void StructInit::StructInit(StructInit const&) +# 2889| : +#-----| getParameter(0): [Parameter] (unnamed parameter 0) +#-----| Type = [LValueReferenceType] const StructInit & +# 2889| [MoveConstructor] void StructInit::StructInit(StructInit&&) +# 2889| : +#-----| getParameter(0): [Parameter] (unnamed parameter 0) +#-----| Type = [RValueReferenceType] StructInit && +# 2897| [Constructor] void StructInit::StructInit(int) +# 2897| : +# 2897| getParameter(0): [Parameter] j +# 2897| Type = [IntType] int +# 2897| : +# 2897| getInitializer(0): [ConstructorDefaultFieldInit] constructor init of field i +# 2897| Type = [IntType] int +# 2897| ValueCategory = prvalue +# 2897| getInitializer(1): [ConstructorDirectFieldInit] constructor init of field j +# 2897| Type = [IntType] int +# 2897| ValueCategory = prvalue +# 2897| getExpr(): [VariableAccess] j +# 2897| Type = [IntType] int +# 2897| ValueCategory = prvalue(load) +# 2897| getInitializer(2): [ConstructorDefaultFieldInit] constructor init of field k +# 2897| Type = [IntType] int +# 2897| ValueCategory = prvalue +# 2897| getInitializer(3): [ConstructorDefaultFieldInit] constructor init of field l +# 2897| Type = [IntType] int +# 2897| ValueCategory = prvalue +# 2897| getInitializer(4): [ConstructorDefaultFieldInit] constructor init of field m +# 2897| Type = [IntType] int +# 2897| ValueCategory = prvalue +# 2897| getInitializer(5): [ConstructorDirectFieldInit] constructor init of field n +# 2897| Type = [IntType] int +# 2897| ValueCategory = prvalue +# 2897| getExpr(): [FunctionCall] call to get_val +# 2897| Type = [IntType] int +# 2897| ValueCategory = prvalue +# 2897| getQualifier(): [ThisExpr] this +# 2897| Type = [PointerType] StructInit * +# 2897| ValueCategory = prvalue(load) +# 2897| getEntryPoint(): [BlockStmt] { ... } +# 2897| getStmt(0): [ReturnStmt] return ... +# 2899| [Constructor] void StructInit::StructInit() +# 2899| : +# 2899| : +# 2899| getInitializer(0): [ConstructorDirectFieldInit] constructor init of field i +# 2899| Type = [IntType] int +# 2899| ValueCategory = prvalue +# 2899| getExpr(): [Literal] 41 +# 2899| Type = [IntType] int +# 2899| Value = [Literal] 41 +# 2899| ValueCategory = prvalue +# 2899| getInitializer(1): [ConstructorDefaultFieldInit] constructor init of field j +# 2899| Type = [IntType] int +# 2899| ValueCategory = prvalue +# 2899| getInitializer(2): [ConstructorDirectFieldInit] constructor init of field k +# 2899| Type = [IntType] int +# 2899| ValueCategory = prvalue +# 2899| getExpr(): [Literal] 41 +# 2899| Type = [IntType] int +# 2899| Value = [Literal] 41 +# 2899| ValueCategory = prvalue +# 2899| getInitializer(3): [ConstructorDefaultFieldInit] constructor init of field l +# 2899| Type = [IntType] int +# 2899| ValueCategory = prvalue +# 2899| getInitializer(4): [ConstructorDefaultFieldInit] constructor init of field m +# 2899| Type = [IntType] int +# 2899| ValueCategory = prvalue +# 2899| getInitializer(5): [ConstructorDefaultFieldInit] constructor init of field n +# 2899| Type = [IntType] int +# 2899| ValueCategory = prvalue +# 2899| getEntryPoint(): [BlockStmt] { ... } +# 2899| getStmt(0): [ReturnStmt] return ... +# 2901| [MemberFunction] int StructInit::get_val() +# 2901| : +# 2901| getEntryPoint(): [BlockStmt] { ... } +# 2901| getStmt(0): [ReturnStmt] return ... +# 2901| getExpr(): [ImplicitThisFieldAccess,PointerFieldAccess] k +# 2901| Type = [IntType] int +# 2901| ValueCategory = prvalue(load) +# 2901| getQualifier(): [ThisExpr] this +# 2901| Type = [PointerType] StructInit * +# 2901| ValueCategory = prvalue(load) ir23.cpp: # 1| [TopLevelFunction] bool consteval_1() # 1| : diff --git a/cpp/ql/test/library-tests/ir/ir/aliased_ir.expected b/cpp/ql/test/library-tests/ir/ir/aliased_ir.expected index 369cc9495a2..5d2b92aed73 100644 --- a/cpp/ql/test/library-tests/ir/ir/aliased_ir.expected +++ b/cpp/ql/test/library-tests/ir/ir/aliased_ir.expected @@ -21066,6 +21066,66 @@ ir.cpp: # 2867| v2867_14(void) = ReturnVoid : #-----| Goto -> Block 1 +# 2897| void StructInit::StructInit(int) +# 2897| Block 0 +# 2897| v2897_1(void) = EnterFunction : +# 2897| m2897_2(unknown) = AliasedDefinition : +# 2897| m2897_3(unknown) = InitializeNonLocal : +# 2897| m2897_4(unknown) = Chi : total:m2897_2, partial:m2897_3 +# 2897| r2897_5(glval) = VariableAddress[#this] : +# 2897| m2897_6(glval) = InitializeParameter[#this] : &:r2897_5 +# 2897| r2897_7(glval) = Load[#this] : &:r2897_5, m2897_6 +# 2897| m2897_8(StructInit) = InitializeIndirection[#this] : &:r2897_7 +# 2897| r2897_9(glval) = VariableAddress[j] : +# 2897| m2897_10(int) = InitializeParameter[j] : &:r2897_9 +# 2897| v2897_11(void) = NoOp : +# 2897| v2897_12(void) = ReturnIndirection[#this] : &:r2897_7, m2897_8 +# 2897| v2897_13(void) = ReturnVoid : +# 2897| v2897_14(void) = AliasedUse : m2897_3 +# 2897| v2897_15(void) = ExitFunction : + +# 2899| void StructInit::StructInit() +# 2899| Block 0 +# 2899| v2899_1(void) = EnterFunction : +# 2899| m2899_2(unknown) = AliasedDefinition : +# 2899| m2899_3(unknown) = InitializeNonLocal : +# 2899| m2899_4(unknown) = Chi : total:m2899_2, partial:m2899_3 +# 2899| r2899_5(glval) = VariableAddress[#this] : +# 2899| m2899_6(glval) = InitializeParameter[#this] : &:r2899_5 +# 2899| r2899_7(glval) = Load[#this] : &:r2899_5, m2899_6 +# 2899| m2899_8(StructInit) = InitializeIndirection[#this] : &:r2899_7 +# 2899| r2899_9(glval) = FieldAddress[i] : r2899_7 +# 2899| r2899_10(int) = Constant[41] : +# 2899| m2899_11(int) = Store[?] : &:r2899_9, r2899_10 +# 2899| m2899_12(unknown) = Chi : total:m2899_8, partial:m2899_11 +# 2899| v2899_13(void) = NoOp : +# 2899| v2899_14(void) = ReturnIndirection[#this] : &:r2899_7, m2899_12 +# 2899| v2899_15(void) = ReturnVoid : +# 2899| v2899_16(void) = AliasedUse : m2899_3 +# 2899| v2899_17(void) = ExitFunction : + +# 2901| int StructInit::get_val() +# 2901| Block 0 +# 2901| v2901_1(void) = EnterFunction : +# 2901| m2901_2(unknown) = AliasedDefinition : +# 2901| m2901_3(unknown) = InitializeNonLocal : +# 2901| m2901_4(unknown) = Chi : total:m2901_2, partial:m2901_3 +# 2901| r2901_5(glval) = VariableAddress[#this] : +# 2901| m2901_6(glval) = InitializeParameter[#this] : &:r2901_5 +# 2901| r2901_7(glval) = Load[#this] : &:r2901_5, m2901_6 +# 2901| m2901_8(StructInit) = InitializeIndirection[#this] : &:r2901_7 +# 2901| r2901_9(glval) = VariableAddress[#return] : +# 2901| r2901_10(glval) = VariableAddress[#this] : +# 2901| r2901_11(StructInit *) = Load[#this] : &:r2901_10, m2901_6 +# 2901| r2901_12(glval) = FieldAddress[k] : r2901_11 +# 2901| r2901_13(int) = Load[?] : &:r2901_12, ~m2901_8 +# 2901| m2901_14(int) = Store[#return] : &:r2901_9, r2901_13 +# 2901| v2901_15(void) = ReturnIndirection[#this] : &:r2901_7, m2901_8 +# 2901| r2901_16(glval) = VariableAddress[#return] : +# 2901| v2901_17(void) = ReturnValue : &:r2901_16, m2901_14 +# 2901| v2901_18(void) = AliasedUse : m2901_3 +# 2901| v2901_19(void) = ExitFunction : + ir23.cpp: # 1| bool consteval_1() # 1| Block 0 diff --git a/cpp/ql/test/library-tests/ir/ir/ir.cpp b/cpp/ql/test/library-tests/ir/ir/ir.cpp index 41494ec00b3..ddb1b41fdbc 100644 --- a/cpp/ql/test/library-tests/ir/ir/ir.cpp +++ b/cpp/ql/test/library-tests/ir/ir/ir.cpp @@ -2886,4 +2886,19 @@ namespace { } } +struct StructInit { + int i = 42; + int j = 42; + int k = 42; + int l = k; + int m = get_val(); + int n = 42; + + StructInit(int j) : j(j), n(get_val()) {} + + StructInit() : i(41), k(41) {} + + int get_val() { return k; } +}; + // semmle-extractor-options: -std=c++20 --clang diff --git a/cpp/ql/test/library-tests/ir/ir/raw_consistency.expected b/cpp/ql/test/library-tests/ir/ir/raw_consistency.expected index de43ad9631a..230d0805cd2 100644 --- a/cpp/ql/test/library-tests/ir/ir/raw_consistency.expected +++ b/cpp/ql/test/library-tests/ir/ir/raw_consistency.expected @@ -21,6 +21,9 @@ lostReachability backEdgeCountMismatch useNotDominatedByDefinition | 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() | +| 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) | +| 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) | +| 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() | switchInstructionWithoutDefaultEdge notMarkedAsConflated wronglyMarkedAsConflated 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 03278f9aa72..8d61ec6789b 100644 --- a/cpp/ql/test/library-tests/ir/ir/raw_ir.expected +++ b/cpp/ql/test/library-tests/ir/ir/raw_ir.expected @@ -19200,6 +19200,93 @@ ir.cpp: # 2867| v2867_13(void) = ReturnVoid : #-----| Goto -> Block 1 +# 2897| void StructInit::StructInit(int) +# 2897| Block 0 +# 2897| v2897_1(void) = EnterFunction : +# 2897| mu2897_2(unknown) = AliasedDefinition : +# 2897| mu2897_3(unknown) = InitializeNonLocal : +# 2897| r2897_4(glval) = VariableAddress[#this] : +# 2897| mu2897_5(glval) = InitializeParameter[#this] : &:r2897_4 +# 2897| r2897_6(glval) = Load[#this] : &:r2897_4, ~m? +# 2897| mu2897_7(StructInit) = InitializeIndirection[#this] : &:r2897_6 +# 2897| r2897_8(glval) = VariableAddress[j] : +# 2897| mu2897_9(int) = InitializeParameter[j] : &:r2897_8 +#-----| Goto -> Block 3 + +# 2897| Block 1 +# 2897| r2897_10(glval) = FieldAddress[j] : r2897_6 +# 2897| r2897_11(glval) = VariableAddress[j] : +# 2897| r2897_12(int) = Load[j] : &:r2897_11, ~m? +# 2897| mu2897_13(int) = Store[?] : &:r2897_10, r2897_12 +#-----| Goto -> Block 3 + +# 2897| Block 2 +# 2897| r2897_14(glval) = FieldAddress[n] : r2897_6 +# 2897| r2897_15(glval) = VariableAddress[#this] : +# 2897| r2897_16(StructInit *) = Load[#this] : &:r2897_15, ~m? +# 2897| r2897_17(glval) = FunctionAddress[get_val] : +# 2897| r2897_18(int) = Call[get_val] : func:r2897_17, this:r2897_16 +# 2897| mu2897_19(unknown) = ^CallSideEffect : ~m? +# 2897| v2897_20(void) = ^IndirectReadSideEffect[-1] : &:r2897_16, ~m? +# 2897| mu2897_21(StructInit) = ^IndirectMayWriteSideEffect[-1] : &:r2897_16 +# 2897| mu2897_22(int) = Store[?] : &:r2897_14, r2897_18 +#-----| Goto -> Block 3 + +# 2897| Block 3 +# 2897| v2897_23(void) = NoOp : +# 2897| v2897_24(void) = ReturnIndirection[#this] : &:r2897_6, ~m? +# 2897| v2897_25(void) = ReturnVoid : +# 2897| v2897_26(void) = AliasedUse : ~m? +# 2897| v2897_27(void) = ExitFunction : + +# 2899| void StructInit::StructInit() +# 2899| Block 0 +# 2899| v2899_1(void) = EnterFunction : +# 2899| mu2899_2(unknown) = AliasedDefinition : +# 2899| mu2899_3(unknown) = InitializeNonLocal : +# 2899| r2899_4(glval) = VariableAddress[#this] : +# 2899| mu2899_5(glval) = InitializeParameter[#this] : &:r2899_4 +# 2899| r2899_6(glval) = Load[#this] : &:r2899_4, ~m? +# 2899| mu2899_7(StructInit) = InitializeIndirection[#this] : &:r2899_6 +# 2899| r2899_8(glval) = FieldAddress[i] : r2899_6 +# 2899| r2899_9(int) = Constant[41] : +# 2899| mu2899_10(int) = Store[?] : &:r2899_8, r2899_9 +#-----| Goto -> Block 2 + +# 2899| Block 1 +# 2899| r2899_11(glval) = FieldAddress[k] : r2899_6 +# 2899| r2899_12(int) = Constant[41] : +# 2899| mu2899_13(int) = Store[?] : &:r2899_11, r2899_12 +#-----| Goto -> Block 2 + +# 2899| Block 2 +# 2899| v2899_14(void) = NoOp : +# 2899| v2899_15(void) = ReturnIndirection[#this] : &:r2899_6, ~m? +# 2899| v2899_16(void) = ReturnVoid : +# 2899| v2899_17(void) = AliasedUse : ~m? +# 2899| v2899_18(void) = ExitFunction : + +# 2901| int StructInit::get_val() +# 2901| Block 0 +# 2901| v2901_1(void) = EnterFunction : +# 2901| mu2901_2(unknown) = AliasedDefinition : +# 2901| mu2901_3(unknown) = InitializeNonLocal : +# 2901| r2901_4(glval) = VariableAddress[#this] : +# 2901| mu2901_5(glval) = InitializeParameter[#this] : &:r2901_4 +# 2901| r2901_6(glval) = Load[#this] : &:r2901_4, ~m? +# 2901| mu2901_7(StructInit) = InitializeIndirection[#this] : &:r2901_6 +# 2901| r2901_8(glval) = VariableAddress[#return] : +# 2901| r2901_9(glval) = VariableAddress[#this] : +# 2901| r2901_10(StructInit *) = Load[#this] : &:r2901_9, ~m? +# 2901| r2901_11(glval) = FieldAddress[k] : r2901_10 +# 2901| r2901_12(int) = Load[?] : &:r2901_11, ~m? +# 2901| mu2901_13(int) = Store[#return] : &:r2901_8, r2901_12 +# 2901| v2901_14(void) = ReturnIndirection[#this] : &:r2901_6, ~m? +# 2901| r2901_15(glval) = VariableAddress[#return] : +# 2901| v2901_16(void) = ReturnValue : &:r2901_15, ~m? +# 2901| v2901_17(void) = AliasedUse : ~m? +# 2901| v2901_18(void) = ExitFunction : + ir23.cpp: # 1| bool consteval_1() # 1| Block 0