Skip to content

Commit 9267425

Browse files
committed
[CPP-340] Eliminate superfluous print-outs of NestedStruct,
`NestedUnion` and `MemberFunction`
1 parent f098279 commit 9267425

File tree

6 files changed

+281
-83
lines changed

6 files changed

+281
-83
lines changed

cpp/ql/src/semmle/code/cpp/Class.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,8 @@ class NestedClass extends Class {
839839
this.isMember()
840840
}
841841

842-
override string getCanonicalQLClass() { result = "NestedClass" }
842+
override string getCanonicalQLClass()
843+
{ not this instanceof NestedStruct and result = "NestedClass" }
843844

844845
/** Holds if this member is private. */
845846
predicate isPrivate() { this.hasSpecifier("private") }

cpp/ql/src/semmle/code/cpp/Function.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,8 @@ class MemberFunction extends Function {
722722
this.isMember()
723723
}
724724

725-
override string getCanonicalQLClass() { result = "MemberFunction" }
725+
override string getCanonicalQLClass()
726+
{ not this instanceof Operator and result = "MemberFunction" }
726727

727728
/**
728729
* Gets the number of parameters of this function, including any implicit

cpp/ql/src/semmle/code/cpp/Struct.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ class NestedStruct extends Struct {
3434
this.isMember()
3535
}
3636

37-
override string getCanonicalQLClass() { result = "NestedStruct" }
37+
override string getCanonicalQLClass()
38+
{ not this instanceof NestedUnion and result = "NestedStruct" }
3839

3940
/** Holds if this member is private. */
4041
predicate isPrivate() { this.hasSpecifier("private") }

cpp/ql/test/examples/expressions/PrintAST.expected

Lines changed: 185 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#-----| [CopyAssignmentOperator,MemberFunction] __va_list_tag& __va_list_tag::operator=(__va_list_tag const&)
1+
#-----| [CopyAssignmentOperator] __va_list_tag& __va_list_tag::operator=(__va_list_tag const&)
22
#-----| params:
33
#-----| 0: [Parameter] p#0
44
#-----| Type = [LValueReferenceType] const __va_list_tag &
5-
#-----| [MemberFunction,MoveAssignmentOperator] __va_list_tag& __va_list_tag::operator=(__va_list_tag&&)
5+
#-----| [MoveAssignmentOperator] __va_list_tag& __va_list_tag::operator=(__va_list_tag&&)
66
#-----| params:
77
#-----| 0: [Parameter] p#0
88
#-----| Type = [RValueReferenceType] __va_list_tag &&
@@ -112,11 +112,11 @@ ConditionDecl.cpp:
112112
# 3| 1: [Block] { ... }
113113
# 5| 2: [ReturnStmt] return ...
114114
ConstructorCall.cpp:
115-
# 1| [CopyAssignmentOperator,MemberFunction] C& C::operator=(C const&)
115+
# 1| [CopyAssignmentOperator] C& C::operator=(C const&)
116116
# 1| params:
117117
#-----| 0: [Parameter] p#0
118118
#-----| Type = [LValueReferenceType] const C &
119-
# 1| [MemberFunction,MoveAssignmentOperator] C& C::operator=(C&&)
119+
# 1| [MoveAssignmentOperator] C& C::operator=(C&&)
120120
# 1| params:
121121
#-----| 0: [Parameter] p#0
122122
#-----| Type = [RValueReferenceType] C &&
@@ -135,11 +135,11 @@ ConstructorCall.cpp:
135135
# 3| initializations:
136136
# 3| body: [Block] { ... }
137137
# 4| 0: [ReturnStmt] return ...
138-
# 7| [CopyAssignmentOperator,MemberFunction] D& D::operator=(D const&)
138+
# 7| [CopyAssignmentOperator] D& D::operator=(D const&)
139139
# 7| params:
140140
#-----| 0: [Parameter] p#0
141141
#-----| Type = [LValueReferenceType] const D &
142-
# 7| [MemberFunction,MoveAssignmentOperator] D& D::operator=(D&&)
142+
# 7| [MoveAssignmentOperator] D& D::operator=(D&&)
143143
# 7| params:
144144
#-----| 0: [Parameter] p#0
145145
#-----| Type = [RValueReferenceType] D &&
@@ -156,11 +156,11 @@ ConstructorCall.cpp:
156156
# 9| initializations:
157157
# 9| body: [Block] { ... }
158158
# 10| 0: [ReturnStmt] return ...
159-
# 13| [CopyAssignmentOperator,MemberFunction] E& E::operator=(E const&)
159+
# 13| [CopyAssignmentOperator] E& E::operator=(E const&)
160160
# 13| params:
161161
#-----| 0: [Parameter] p#0
162162
#-----| Type = [LValueReferenceType] const E &
163-
# 13| [MemberFunction,MoveAssignmentOperator] E& E::operator=(E&&)
163+
# 13| [MoveAssignmentOperator] E& E::operator=(E&&)
164164
# 13| params:
165165
#-----| 0: [Parameter] p#0
166166
#-----| Type = [RValueReferenceType] E &&
@@ -381,7 +381,7 @@ DestructorCall.cpp:
381381
# 13| ValueCategory = prvalue(load)
382382
# 14| 2: [ReturnStmt] return ...
383383
DynamicCast.cpp:
384-
# 1| [CopyAssignmentOperator,MemberFunction] Base& Base::operator=(Base const&)
384+
# 1| [CopyAssignmentOperator] Base& Base::operator=(Base const&)
385385
# 1| params:
386386
#-----| 0: [Parameter] p#0
387387
#-----| Type = [LValueReferenceType] const Base &
@@ -396,7 +396,7 @@ DynamicCast.cpp:
396396
#-----| 0: [ThisExpr] this
397397
#-----| Type = [PointerType] Base *
398398
#-----| ValueCategory = prvalue(load)
399-
# 1| [MemberFunction,MoveAssignmentOperator] Base& Base::operator=(Base&&)
399+
# 1| [MoveAssignmentOperator] Base& Base::operator=(Base&&)
400400
# 1| params:
401401
#-----| 0: [Parameter] p#0
402402
#-----| Type = [RValueReferenceType] Base &&
@@ -414,7 +414,7 @@ DynamicCast.cpp:
414414
# 2| params:
415415
# 2| body: [Block] { ... }
416416
# 2| 0: [ReturnStmt] return ...
417-
# 4| [CopyAssignmentOperator,MemberFunction] Derived& Derived::operator=(Derived const&)
417+
# 4| [CopyAssignmentOperator] Derived& Derived::operator=(Derived const&)
418418
# 4| params:
419419
#-----| 0: [Parameter] p#0
420420
#-----| Type = [LValueReferenceType] const Derived &
@@ -462,7 +462,7 @@ DynamicCast.cpp:
462462
#-----| 0: [ThisExpr] this
463463
#-----| Type = [PointerType] Derived *
464464
#-----| ValueCategory = prvalue(load)
465-
# 4| [MemberFunction,MoveAssignmentOperator] Derived& Derived::operator=(Derived&&)
465+
# 4| [MoveAssignmentOperator] Derived& Derived::operator=(Derived&&)
466466
# 4| params:
467467
#-----| 0: [Parameter] p#0
468468
#-----| Type = [RValueReferenceType] Derived &&
@@ -686,11 +686,11 @@ StatementExpr.c:
686686
# 2| ValueCategory = prvalue
687687
# 3| 1: [ReturnStmt] return ...
688688
StaticMemberAccess.cpp:
689-
# 1| [CopyAssignmentOperator,MemberFunction] X& X::operator=(X const&)
689+
# 1| [CopyAssignmentOperator] X& X::operator=(X const&)
690690
# 1| params:
691691
#-----| 0: [Parameter] p#0
692692
#-----| Type = [LValueReferenceType] const X &
693-
# 1| [MemberFunction,MoveAssignmentOperator] X& X::operator=(X&&)
693+
# 1| [MoveAssignmentOperator] X& X::operator=(X&&)
694694
# 1| params:
695695
#-----| 0: [Parameter] p#0
696696
#-----| Type = [RValueReferenceType] X &&
@@ -745,11 +745,11 @@ Subscript.c:
745745
# 2| ValueCategory = prvalue
746746
# 3| 1: [ReturnStmt] return ...
747747
Throw.cpp:
748-
# 2| [CopyAssignmentOperator,MemberFunction] F& F::operator=(F const&)
748+
# 2| [CopyAssignmentOperator] F& F::operator=(F const&)
749749
# 2| params:
750750
#-----| 0: [Parameter] p#0
751751
#-----| Type = [LValueReferenceType] const F &
752-
# 2| [MemberFunction,MoveAssignmentOperator] F& F::operator=(F&&)
752+
# 2| [MoveAssignmentOperator] F& F::operator=(F&&)
753753
# 2| params:
754754
#-----| 0: [Parameter] p#0
755755
#-----| Type = [RValueReferenceType] F &&
@@ -806,11 +806,11 @@ Throw.cpp:
806806
# 13| Type = [VoidType] void
807807
# 13| ValueCategory = prvalue
808808
Typeid.cpp:
809-
# 4| [CopyAssignmentOperator,MemberFunction] std::type_info& std::type_info::operator=(std::type_info const&)
809+
# 4| [CopyAssignmentOperator] std::type_info& std::type_info::operator=(std::type_info const&)
810810
# 4| params:
811811
#-----| 0: [Parameter] p#0
812812
#-----| Type = [LValueReferenceType] const type_info &
813-
# 4| [MemberFunction,MoveAssignmentOperator] std::type_info& std::type_info::operator=(std::type_info&&)
813+
# 4| [MoveAssignmentOperator] std::type_info& std::type_info::operator=(std::type_info&&)
814814
# 4| params:
815815
#-----| 0: [Parameter] p#0
816816
#-----| Type = [RValueReferenceType] type_info &&
@@ -942,3 +942,170 @@ Varargs.c:
942942
# 11| Type = [TypedefType] va_list
943943
# 11| ValueCategory = lvalue
944944
# 12| 3: [ReturnStmt] return ...
945+
union_etc.cpp:
946+
# 2| [CopyAssignmentOperator] S& S::operator=(S const&)
947+
# 2| params:
948+
#-----| 0: [Parameter] p#0
949+
#-----| Type = [LValueReferenceType] const S &
950+
# 2| [MoveAssignmentOperator] S& S::operator=(S&&)
951+
# 2| params:
952+
#-----| 0: [Parameter] p#0
953+
#-----| Type = [RValueReferenceType] S &&
954+
# 3| [CopyAssignmentOperator] S::U& S::U::operator=(S::U const public&)
955+
# 3| params:
956+
#-----| 0: [Parameter] p#0
957+
#-----| Type = [LValueReferenceType] const U &
958+
# 3| [MoveAssignmentOperator] S::U& S::U::operator=(S::U&&)
959+
# 3| params:
960+
#-----| 0: [Parameter] p#0
961+
#-----| Type = [RValueReferenceType] U &&
962+
# 4| [CopyAssignmentOperator] S::C& S::C::operator=(S::C const public&)
963+
# 4| params:
964+
#-----| 0: [Parameter] p#0
965+
#-----| Type = [LValueReferenceType] const C &
966+
# 4| [MoveAssignmentOperator] S::C& S::C::operator=(S::C&&)
967+
# 4| params:
968+
#-----| 0: [Parameter] p#0
969+
#-----| Type = [RValueReferenceType] C &&
970+
# 8| [CopyAssignmentOperator] C& C::operator=(C const&)
971+
# 8| params:
972+
#-----| 0: [Parameter] p#0
973+
#-----| Type = [LValueReferenceType] const C &
974+
# 8| [MoveAssignmentOperator] C& C::operator=(C&&)
975+
# 8| params:
976+
#-----| 0: [Parameter] p#0
977+
#-----| Type = [RValueReferenceType] C &&
978+
# 10| [CopyAssignmentOperator] C::S& C::S::operator=(C::S const public&)
979+
# 10| params:
980+
#-----| 0: [Parameter] p#0
981+
#-----| Type = [LValueReferenceType] const S &
982+
# 10| [MoveAssignmentOperator] C::S& C::S::operator=(C::S&&)
983+
# 10| params:
984+
#-----| 0: [Parameter] p#0
985+
#-----| Type = [RValueReferenceType] S &&
986+
# 11| [CopyAssignmentOperator] C::U& C::U::operator=(C::U const public&)
987+
# 11| params:
988+
#-----| 0: [Parameter] p#0
989+
#-----| Type = [LValueReferenceType] const U &
990+
# 11| [MoveAssignmentOperator] C::U& C::U::operator=(C::U&&)
991+
# 11| params:
992+
#-----| 0: [Parameter] p#0
993+
#-----| Type = [RValueReferenceType] U &&
994+
# 15| [CopyAssignmentOperator] U& U::operator=(U const&)
995+
# 15| params:
996+
#-----| 0: [Parameter] p#0
997+
#-----| Type = [LValueReferenceType] const U &
998+
# 15| [MoveAssignmentOperator] U& U::operator=(U&&)
999+
# 15| params:
1000+
#-----| 0: [Parameter] p#0
1001+
#-----| Type = [RValueReferenceType] U &&
1002+
# 16| [CopyAssignmentOperator] U::S& U::S::operator=(U::S const public&)
1003+
# 16| params:
1004+
#-----| 0: [Parameter] p#0
1005+
#-----| Type = [LValueReferenceType] const S &
1006+
# 16| [MoveAssignmentOperator] U::S& U::S::operator=(U::S&&)
1007+
# 16| params:
1008+
#-----| 0: [Parameter] p#0
1009+
#-----| Type = [RValueReferenceType] S &&
1010+
# 17| [CopyAssignmentOperator] U::C& U::C::operator=(U::C const public&)
1011+
# 17| params:
1012+
#-----| 0: [Parameter] p#0
1013+
#-----| Type = [LValueReferenceType] const C &
1014+
# 17| [MoveAssignmentOperator] U::C& U::C::operator=(U::C&&)
1015+
# 17| params:
1016+
#-----| 0: [Parameter] p#0
1017+
#-----| Type = [RValueReferenceType] C &&
1018+
# 21| [TopLevelFunction] int foo()
1019+
# 21| params:
1020+
# 21| body: [Block] { ... }
1021+
# 22| 0: [DeclStmt] declaration
1022+
# 22| 0: [VariableDeclarationEntry] definition of s
1023+
# 22| Type = [Struct] S
1024+
# 23| 1: [DeclStmt] declaration
1025+
# 23| 0: [VariableDeclarationEntry] definition of c
1026+
# 23| Type = [Class] C
1027+
# 24| 2: [DeclStmt] declaration
1028+
# 24| 0: [VariableDeclarationEntry] definition of u
1029+
# 24| Type = [Union] U
1030+
# 25| 3: [ExprStmt] ExprStmt
1031+
# 25| 0: [AssignExpr] ... = ...
1032+
# 25| Type = [IntType] int
1033+
# 25| ValueCategory = lvalue
1034+
# 25| 0: [FieldAccess] a
1035+
# 25| Type = [IntType] int
1036+
# 25| ValueCategory = lvalue
1037+
# 25| -1: [FieldAccess] u
1038+
# 25| Type = [NestedUnion] U
1039+
# 25| ValueCategory = lvalue
1040+
# 25| -1: [VariableAccess] s
1041+
# 25| Type = [Struct] S
1042+
# 25| ValueCategory = lvalue
1043+
# 25| 1: [AssignExpr] ... = ...
1044+
# 25| Type = [IntType] int
1045+
# 25| ValueCategory = prvalue
1046+
# 25| 0: [FieldAccess] e
1047+
# 25| Type = [IntType] int
1048+
# 25| ValueCategory = lvalue
1049+
# 25| -1: [FieldAccess] s
1050+
# 25| Type = [NestedStruct] S
1051+
# 25| ValueCategory = lvalue
1052+
# 25| -1: [VariableAccess] c
1053+
# 25| Type = [Class] C
1054+
# 25| ValueCategory = lvalue
1055+
# 25| 1: [AssignExpr] ... = ...
1056+
# 25| Type = [IntType] int
1057+
# 25| ValueCategory = prvalue
1058+
# 25| 0: [FieldAccess] i
1059+
# 25| Type = [IntType] int
1060+
# 25| ValueCategory = lvalue
1061+
# 25| -1: [FieldAccess] c
1062+
# 25| Type = [NestedClass] C
1063+
# 25| ValueCategory = lvalue
1064+
# 25| -1: [VariableAccess] u
1065+
# 25| Type = [Union] U
1066+
# 25| ValueCategory = lvalue
1067+
# 25| 1: [Literal] 43
1068+
# 25| Type = [IntType] int
1069+
# 25| Value = [Literal] 43
1070+
# 25| ValueCategory = prvalue
1071+
# 26| 4: [ExprStmt] ExprStmt
1072+
# 26| 0: [AssignAddExpr] ... += ...
1073+
# 26| Type = [IntType] int
1074+
# 26| ValueCategory = lvalue
1075+
# 26| 0: [FieldAccess] b
1076+
# 26| Type = [IntType] int
1077+
# 26| ValueCategory = lvalue
1078+
# 26| -1: [FieldAccess] u
1079+
# 26| Type = [NestedUnion] U
1080+
# 26| ValueCategory = lvalue
1081+
# 26| -1: [VariableAccess] s
1082+
# 26| Type = [Struct] S
1083+
# 26| ValueCategory = lvalue
1084+
# 26| 1: [ParenthesisExpr] (...)
1085+
# 26| Type = [IntType] int
1086+
# 26| ValueCategory = prvalue
1087+
# 26| expr: [AddExpr] ... + ...
1088+
# 26| Type = [IntType] int
1089+
# 26| ValueCategory = prvalue
1090+
# 26| 0: [FieldAccess] i
1091+
# 26| Type = [IntType] int
1092+
# 26| ValueCategory = prvalue(load)
1093+
# 26| -1: [FieldAccess] c
1094+
# 26| Type = [NestedClass] C
1095+
# 26| ValueCategory = lvalue
1096+
# 26| -1: [VariableAccess] u
1097+
# 26| Type = [Union] U
1098+
# 26| ValueCategory = lvalue
1099+
# 26| 1: [FieldAccess] j
1100+
# 26| Type = [IntType] int
1101+
# 26| ValueCategory = prvalue(load)
1102+
# 26| -1: [VariableAccess] u
1103+
# 26| Type = [Union] U
1104+
# 26| ValueCategory = lvalue
1105+
# 27| 5: [ReturnStmt] return ...
1106+
# 27| 0: [FieldAccess] g
1107+
# 27| Type = [IntType] int
1108+
# 27| ValueCategory = prvalue(load)
1109+
# 27| -1: [VariableAccess] c
1110+
# 27| Type = [Class] C
1111+
# 27| ValueCategory = lvalue
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
struct S {
3+
union U { int a, b; } u;
4+
class C { public: int b, c; } c;
5+
int x, d;
6+
} s;
7+
8+
class C {
9+
public:
10+
struct S { int d, e; } s;
11+
union U { int e, f; } u;
12+
int f, g;
13+
} c;
14+
15+
union U {
16+
struct S { int g, h; } s;
17+
class C { public: int h, i; } c;
18+
int i, j;
19+
} u;
20+
21+
int foo(void) {
22+
S s;
23+
C c;
24+
U u;
25+
s.u.a = c.s.e = u.c.i = 43;
26+
s.u.b += (u.c.i + u.j);
27+
return c.g;
28+
}

0 commit comments

Comments
 (0)