Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6eac51d

Browse files
zlaski-semmlegeoffw0
authored andcommitted
[CPP-418] Address review comments.
1 parent e2d5a82 commit 6eac51d

5 files changed

Lines changed: 101 additions & 96 deletions

File tree

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ class BuiltInType extends Type, @builtintype {
312312
/**
313313
* An erroneous type. This type has no corresponding C/C++ syntax.
314314
*
315-
* ErroneousType is the type of ErrorExpr, which it turn refers to an illegal
315+
* ErroneousType is the type of ErrorExpr, which in turn refers to an illegal
316316
* language construct. In the example below, a temporary (`0`) cannot be bound
317317
* to an lvalue reference (`int &`):
318318
* ```
@@ -1335,7 +1335,6 @@ class FunctionPointerIshType extends DerivedType {
13351335
* int C::* p = &C::m; // pointer to data member m of class C
13361336
* class C *;
13371337
* int val = c.*p; // access data member
1338-
*
13391338
* ```
13401339
*/
13411340
class PointerToMemberType extends Type, @ptrtomember {
@@ -1434,11 +1433,11 @@ class RoutineType extends Type, @routinetype {
14341433
}
14351434

14361435
/**
1437-
* A C++ typename template parameter.
1436+
* A C++ `typename` (or `class`) template parameter.
14381437
*
14391438
* In the example below, `T` is a template parameter:
14401439
* ```
1441-
* template <typename T>
1440+
* template <class T>
14421441
* class C { };
14431442
* ```
14441443
*/
@@ -1458,8 +1457,8 @@ class TemplateParameter extends UserType {
14581457
* In the example below, `T` is a template template parameter (although its name
14591458
* may be omitted):
14601459
* ```
1461-
* template <template <typename T> class H, class S>
1462-
* void f(const H<S> &value) { }
1460+
* template <template <typename T> class Container, class Elem>
1461+
* void foo(const ContainerH<Elem> &value) { }
14631462
* ```
14641463
*/
14651464
class TemplateTemplateParameter extends TemplateParameter {

cpp/ql/src/semmle/code/cpp/exprs/Assignment.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import semmle.code.cpp.exprs.BitwiseOperation
1111
*/
1212
abstract class Assignment extends Operation {
1313
/** Gets the *lvalue* of this assignment. */
14-
Expr get*lvalue*() { this.hasChild(result, 0) }
14+
Expr getLValue() { this.hasChild(result, 0) }
1515

1616
/** Gets the rvalue of this assignment. */
1717
Expr getRValue() { this.hasChild(result, 1) }
@@ -22,7 +22,7 @@ abstract class Assignment extends Operation {
2222
this.getRValue().mayBeGloballyImpure()
2323
or
2424
not exists(VariableAccess va, LocalScopeVariable v |
25-
va = this.get*lvalue*() and
25+
va = this.getLValue() and
2626
v = va.getTarget() and
2727
not va.getConversion+() instanceof ReferenceDereferenceExpr and
2828
not v.isStatic()

cpp/ql/src/semmle/code/cpp/exprs/BuiltInOperations.qll

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,36 @@ class BuiltInNoOp extends BuiltInOperation, @noopexpr {
7878
}
7979

8080
/**
81-
* A C++ `__offsetof` built-in operation (used by some implementations
82-
* of `offsetof` in the presence of user-defined `operator &`).
83-
*
84-
* It computes the offset (in bytes) of data member `m` from the beginning
85-
* of its enclosing `struct`/`class`/`union` `st`.
81+
* DEPRECATED: Use `BuiltInOperationBuiltInOffsetOf` instead.
82+
*/
83+
deprecated class BuiltInOperationOffsetOf = BuiltInOperationBuiltInOffsetOf;
84+
85+
/**
86+
* A C/C++ `__offsetof` built-in operation (used by some implementations
87+
* of `offsetof`). The operation retains its semantics even in the presence
88+
* of an overloaded `operator &`). This is a GNU/Clang extension.
8689
* ```
87-
* #define offsetof(st, m) __offsetof(st, m)
90+
* struct S {
91+
* int a, b;
92+
* };
93+
* int d = __builtin_offsetof(struct S, b); // usually 4
8894
* ```
8995
*/
90-
class BuiltInOperationOffsetOf extends BuiltInOperation, @offsetofexpr {
91-
override string toString() { result = "__offsetof" }
96+
class BuiltInOperationBuiltInOffsetOf extends BuiltInOperation, @offsetofexpr {
97+
override string toString() { result = "__builtin_offsetof" }
9298

93-
override string getCanonicalQLClass() { result = "BuiltInOperationOffsetOf" }
99+
override string getCanonicalQLClass() { result = "BuiltInOperationBuiltInOffsetOf" }
94100
}
95101

96102
/**
97-
* A C/C++ `__INTADDR__` expression, used by EDG to implement `offsetof`
98-
* in the presence of user-defined `operator &`.
99-
*
100-
* It computes the offset (in bytes) of data member `m` from the beginning
101-
* of its enclosing `struct`/`class`/`union` `st`.
103+
* A C/C++ `__INTADDR__` built-in operation (used by some implementations
104+
* of `offsetof`). The operation retains its semantics even in the presence
105+
* of an overloaded `operator &`). This is an EDG extension.
102106
* ```
103-
* #define offsetof(st, m) __INTADDR__(st, m)
107+
* struct S {
108+
* int a, b;
109+
* };
110+
* int d = __INTADDR__(struct S, b); // usually 4
104111
* ```
105112
*/
106113
class BuiltInIntAddr extends BuiltInOperation, @intaddrexpr {
@@ -541,7 +548,7 @@ class BuiltInOperationIsDestructible extends BuiltInOperation, @isdestructibleex
541548
* The `__is_nothrow_destructible` built-in operation (used by some
542549
* implementations of the `<type_traits>` header).
543550
*
544-
* Returns `true` if the type is destructible and whose constructor, and those
551+
* Returns `true` if the type is destructible and whose destructor, and those
545552
* of member data and any super`class`es all have an empty exception
546553
* specification.
547554
* ```
@@ -558,7 +565,7 @@ class BuiltInOperationIsNothrowDestructible extends BuiltInOperation, @isnothrow
558565
* The `__is_trivially_destructible` built-in operation (used by some
559566
* implementations of the `<type_traits>` header).
560567
*
561-
* Returns `true` if the type is destructible and whose constructor, and those
568+
* Returns `true` if the type is destructible and whose destructor, and those
562569
* of member data and any super`class`es are all trivial (compiler-generated).
563570
* ```
564571
* bool v = __is_trivially_destructible(MyType);
@@ -575,8 +582,7 @@ class BuiltInOperationIsTriviallyDestructible extends BuiltInOperation, @istrivi
575582
* implementations of the `<type_traits>` header).
576583
*
577584
* Returns `true` if the assignment operator `C::operator =(const C& c)` is
578-
* trivial (compiler-generated). The * generated code will have resembled a
579-
* `memcpy` operation.
585+
* trivial (compiler-generated).
580586
* ```
581587
* template<typename T>
582588
* struct is_trivially_assignable
@@ -595,7 +601,7 @@ class BuiltInOperationIsTriviallyAssignable extends BuiltInOperation, @istrivial
595601
* implementations of the `<type_traits>` header).
596602
*
597603
* Returns true if there exists a `C::operator =(const C& c) nothrow`
598-
* assignment operator (i.e, with an empty excepion specification).
604+
* assignment operator (i.e, with an empty exception specification).
599605
* ```
600606
* bool v = __is_nothrow_assignable(MyType);
601607
* ```

0 commit comments

Comments
 (0)