Skip to content

Commit 0a7ed15

Browse files
committed
C++: Add test that show that PrintAST is broekn for OverloadedArrayExpr
1 parent 066db76 commit 0a7ed15

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24086,6 +24086,38 @@ ir.cpp:
2408624086
# 2717| ValueCategory = prvalue
2408724087
# 2717| getThen(): [BlockStmt] { ... }
2408824088
# 2718| getStmt(16): [ReturnStmt] return ...
24089+
# 2720| [CopyAssignmentOperator] WithBracketOperator& WithBracketOperator::operator=(WithBracketOperator const&)
24090+
# 2720| <params>:
24091+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
24092+
#-----| Type = [LValueReferenceType] const WithBracketOperator &
24093+
# 2720| [MoveAssignmentOperator] WithBracketOperator& WithBracketOperator::operator=(WithBracketOperator&&)
24094+
# 2720| <params>:
24095+
#-----| getParameter(0): [Parameter] (unnamed parameter 0)
24096+
#-----| Type = [RValueReferenceType] WithBracketOperator &&
24097+
# 2721| [ConstMemberFunction] char const& WithBracketOperator::operator[](int) const
24098+
# 2721| <params>:
24099+
# 2721| getParameter(0): [Parameter] pos
24100+
# 2721| Type = [IntType] int
24101+
# 2724| [TopLevelFunction] char UseBracketOperator(WithBracketOperator const, int)
24102+
# 2724| <params>:
24103+
# 2724| getParameter(0): [Parameter] line
24104+
# 2724| Type = [SpecifiedType] const WithBracketOperator
24105+
# 2724| getParameter(1): [Parameter] indent
24106+
# 2724| Type = [IntType] int
24107+
# 2724| getEntryPoint(): [BlockStmt] { ... }
24108+
# 2725| getStmt(0): [ReturnStmt] return ...
24109+
# 2725| getExpr(): [OverloadedArrayExpr] call to operator[]
24110+
# 2725| Type = [LValueReferenceType] const char &
24111+
# 2725| ValueCategory = prvalue
24112+
# 2725| getArrayBase(): [VariableAccess] line
24113+
# 2725| Type = [SpecifiedType] const WithBracketOperator
24114+
# 2725| ValueCategory = lvalue
24115+
# 2725| : [VariableAccess] indent
24116+
# 2725| Type = [IntType] int
24117+
# 2725| ValueCategory = prvalue(load)
24118+
# 2725| getExpr().getFullyConverted(): [ReferenceDereferenceExpr] (reference dereference)
24119+
# 2725| Type = [PlainCharType] char
24120+
# 2725| ValueCategory = prvalue(load)
2408924121
many-defs-per-use.cpp:
2409024122
# 34| [TopLevelFunction] void many_defs_per_use()
2409124123
# 34| <params>:

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19713,6 +19713,33 @@ ir.cpp:
1971319713
# 2698| v2698_10(void) = AliasedUse : m2698_3
1971419714
# 2698| v2698_11(void) = ExitFunction :
1971519715

19716+
# 2724| char UseBracketOperator(WithBracketOperator const, int)
19717+
# 2724| Block 0
19718+
# 2724| v2724_1(void) = EnterFunction :
19719+
# 2724| m2724_2(unknown) = AliasedDefinition :
19720+
# 2724| m2724_3(unknown) = InitializeNonLocal :
19721+
# 2724| m2724_4(unknown) = Chi : total:m2724_2, partial:m2724_3
19722+
# 2724| r2724_5(glval<WithBracketOperator>) = VariableAddress[line] :
19723+
# 2724| m2724_6(WithBracketOperator) = InitializeParameter[line] : &:r2724_5
19724+
# 2724| m2724_7(unknown) = Chi : total:m2724_4, partial:m2724_6
19725+
# 2724| r2724_8(glval<int>) = VariableAddress[indent] :
19726+
# 2724| m2724_9(int) = InitializeParameter[indent] : &:r2724_8
19727+
# 2725| r2725_1(glval<char>) = VariableAddress[#return] :
19728+
# 2725| r2725_2(glval<WithBracketOperator>) = VariableAddress[line] :
19729+
# 2725| r2725_3(glval<unknown>) = FunctionAddress[operator[]] :
19730+
# 2725| r2725_4(glval<int>) = VariableAddress[indent] :
19731+
# 2725| r2725_5(int) = Load[indent] : &:r2725_4, m2724_9
19732+
# 2725| r2725_6(char &) = Call[operator[]] : func:r2725_3, this:r2725_2, 0:r2725_5
19733+
# 2725| m2725_7(unknown) = ^CallSideEffect : ~m2724_7
19734+
# 2725| m2725_8(unknown) = Chi : total:m2724_7, partial:m2725_7
19735+
# 2725| v2725_9(void) = ^IndirectReadSideEffect[-1] : &:r2725_2, ~m2725_8
19736+
# 2725| r2725_10(char) = Load[?] : &:r2725_6, ~m2725_8
19737+
# 2725| m2725_11(char) = Store[#return] : &:r2725_1, r2725_10
19738+
# 2724| r2724_10(glval<char>) = VariableAddress[#return] :
19739+
# 2724| v2724_11(void) = ReturnValue : &:r2724_10, m2725_11
19740+
# 2724| v2724_12(void) = AliasedUse : ~m2725_8
19741+
# 2724| v2724_13(void) = ExitFunction :
19742+
1971619743
many-defs-per-use.cpp:
1971719744
# 34| void many_defs_per_use()
1971819745
# 34| Block 0

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,4 +2717,12 @@ void branch_on_integral_in_cpp(int x1, int x2) {
27172717
if(!x_1_and_2) {}
27182718
}
27192719

2720+
struct WithBracketOperator {
2721+
const char& operator[](int pos) const;
2722+
};
2723+
2724+
char UseBracketOperator(const WithBracketOperator line, int indent) {
2725+
return line[indent];
2726+
}
2727+
27202728
// semmle-extractor-options: -std=c++20 --clang

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18031,6 +18031,30 @@ ir.cpp:
1803118031
# 2698| v2698_9(void) = AliasedUse : ~m?
1803218032
# 2698| v2698_10(void) = ExitFunction :
1803318033

18034+
# 2724| char UseBracketOperator(WithBracketOperator const, int)
18035+
# 2724| Block 0
18036+
# 2724| v2724_1(void) = EnterFunction :
18037+
# 2724| mu2724_2(unknown) = AliasedDefinition :
18038+
# 2724| mu2724_3(unknown) = InitializeNonLocal :
18039+
# 2724| r2724_4(glval<WithBracketOperator>) = VariableAddress[line] :
18040+
# 2724| mu2724_5(WithBracketOperator) = InitializeParameter[line] : &:r2724_4
18041+
# 2724| r2724_6(glval<int>) = VariableAddress[indent] :
18042+
# 2724| mu2724_7(int) = InitializeParameter[indent] : &:r2724_6
18043+
# 2725| r2725_1(glval<char>) = VariableAddress[#return] :
18044+
# 2725| r2725_2(glval<WithBracketOperator>) = VariableAddress[line] :
18045+
# 2725| r2725_3(glval<unknown>) = FunctionAddress[operator[]] :
18046+
# 2725| r2725_4(glval<int>) = VariableAddress[indent] :
18047+
# 2725| r2725_5(int) = Load[indent] : &:r2725_4, ~m?
18048+
# 2725| r2725_6(char &) = Call[operator[]] : func:r2725_3, this:r2725_2, 0:r2725_5
18049+
# 2725| mu2725_7(unknown) = ^CallSideEffect : ~m?
18050+
# 2725| v2725_8(void) = ^IndirectReadSideEffect[-1] : &:r2725_2, ~m?
18051+
# 2725| r2725_9(char) = Load[?] : &:r2725_6, ~m?
18052+
# 2725| mu2725_10(char) = Store[#return] : &:r2725_1, r2725_9
18053+
# 2724| r2724_8(glval<char>) = VariableAddress[#return] :
18054+
# 2724| v2724_9(void) = ReturnValue : &:r2724_8, ~m?
18055+
# 2724| v2724_10(void) = AliasedUse : ~m?
18056+
# 2724| v2724_11(void) = ExitFunction :
18057+
1803418058
many-defs-per-use.cpp:
1803518059
# 34| void many_defs_per_use()
1803618060
# 34| Block 0

0 commit comments

Comments
 (0)