Skip to content

Commit 73d9cc2

Browse files
authored
Merge pull request #2309 from geoffw0/cpp418
CPP: QLDoc enhancements
2 parents 74b464d + f2b7af7 commit 73d9cc2

File tree

16 files changed

+1455
-248
lines changed

16 files changed

+1455
-248
lines changed

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

Lines changed: 286 additions & 60 deletions
Large diffs are not rendered by default.

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import semmle.code.cpp.Type
22
private import semmle.code.cpp.internal.ResolveClass
33

44
/**
5-
* A C/C++ typedef type. See 4.9.1.
6-
*
7-
* Represents either of the following typedef styles:
8-
*
9-
* * CTypedefType: typedef <type> <name>;
10-
* * UsingAliasTypedefType: using <name> = <type>;
5+
* A C/C++ typedef type. See 4.9.1. For example the types declared on each line of the following code:
6+
* ```
7+
* typedef int my_int;
8+
* using my_int2 = int;
9+
* ```
1110
*/
1211
class TypedefType extends UserType {
1312
TypedefType() {
@@ -48,7 +47,10 @@ class TypedefType extends UserType {
4847
}
4948

5049
/**
51-
* A traditional C/C++ typedef type. See 4.9.1.
50+
* A traditional C/C++ typedef type. See 4.9.1. For example the type declared in the following code:
51+
* ```
52+
* typedef int my_int;
53+
* ```
5254
*/
5355
class CTypedefType extends TypedefType {
5456
CTypedefType() { usertypes(underlyingElement(this), _, 5) }
@@ -61,7 +63,10 @@ class CTypedefType extends TypedefType {
6163
}
6264

6365
/**
64-
* A using alias C++ typedef type.
66+
* A using alias C++ typedef type. For example the type declared in the following code:
67+
* ```
68+
* using my_int2 = int;
69+
* ```
6570
*/
6671
class UsingAliasTypedefType extends TypedefType {
6772
UsingAliasTypedefType() { usertypes(underlyingElement(this), _, 14) }
@@ -74,7 +79,11 @@ class UsingAliasTypedefType extends TypedefType {
7479
}
7580

7681
/**
77-
* A C++ typedef type that is directly enclosed by a function.
82+
* A C++ `typedef` type that is directly enclosed by a function. For example the type declared inside the function `foo` in
83+
* the following code:
84+
* ```
85+
* int foo(void) { typedef int local; }
86+
* ```
7887
*/
7988
class LocalTypedefType extends TypedefType {
8089
LocalTypedefType() { isLocal() }
@@ -83,7 +92,11 @@ class LocalTypedefType extends TypedefType {
8392
}
8493

8594
/**
86-
* A C++ typedef type that is directly enclosed by a class, struct or union.
95+
* A C++ `typedef` type that is directly enclosed by a `class`, `struct` or `union`. For example the type declared inside
96+
* the class `C` in the following code:
97+
* ```
98+
* class C { typedef int nested; };
99+
* ```
87100
*/
88101
class NestedTypedefType extends TypedefType {
89102
NestedTypedefType() { this.isMember() }

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import semmle.code.cpp.Function
55
private import semmle.code.cpp.internal.ResolveClass
66

77
/**
8-
* A C/C++ user-defined type. Examples include `Class`, `Struct`, `Union`,
9-
* `Enum`, and `TypedefType`.
8+
* A C/C++ user-defined type. Examples include `class`, `struct`, `union`,
9+
* `enum` and `typedef` types.
10+
* ```
11+
* enum e1 { val1, val2 } b;
12+
* enum class e2: short { val3, val4 } c;
13+
* typedef int my_int;
14+
* class C { int a, b; };
15+
* ```
1016
*/
1117
class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @usertype {
1218
/**
@@ -88,6 +94,10 @@ class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @
8894

8995
/**
9096
* A particular definition or forward declaration of a C/C++ user-defined type.
97+
* ```
98+
* class C;
99+
* typedef int ti;
100+
* ```
91101
*/
92102
class TypeDeclarationEntry extends DeclarationEntry, @type_decl {
93103
override UserType getDeclaration() { result = getType() }

cpp/ql/src/semmle/code/cpp/commons/Buffer.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ predicate memberMayBeVarSize(Class c, MemberVariable v) {
4444
aoe.getAddressable() = v
4545
)
4646
or
47-
exists(BuiltInOperationOffsetOf oo |
47+
exists(BuiltInOperationBuiltInOffsetOf oo |
4848
// `offsetof(c, v)` using a builtin
4949
oo.getAChild().(VariableAccess).getTarget() = v
5050
)

cpp/ql/src/semmle/code/cpp/controlflow/internal/CFG.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private predicate excludeNodeAndNodesBelow(Expr e) {
132132
* control flow in them.
133133
*/
134134
private predicate excludeNodesStrictlyBelow(Node n) {
135-
n instanceof BuiltInOperationOffsetOf
135+
n instanceof BuiltInOperationBuiltInOffsetOf
136136
or
137137
n instanceof BuiltInIntAddr
138138
or

0 commit comments

Comments
 (0)