Skip to content

Commit 0ce0861

Browse files
committed
C++: Respond to review comments.
1 parent d20a0c9 commit 0ce0861

File tree

5 files changed

+32
-77
lines changed

5 files changed

+32
-77
lines changed

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

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,14 @@ class FunctionCall extends Call, @funbindexpr {
300300
}
301301
}
302302

303+
/** A _user-defined_ unary `operator*` function. */
304+
class OverloadedPointerDereferenceFunction extends Function {
305+
OverloadedPointerDereferenceFunction() {
306+
this.hasName("operator*") and
307+
this.getEffectiveNumberOfParameters() = 1
308+
}
309+
}
310+
303311
/**
304312
* An instance of a _user-defined_ unary `operator*` applied to its argument.
305313
* ```
@@ -309,8 +317,7 @@ class FunctionCall extends Call, @funbindexpr {
309317
*/
310318
class OverloadedPointerDereferenceExpr extends FunctionCall {
311319
OverloadedPointerDereferenceExpr() {
312-
getTarget().hasName("operator*") and
313-
getTarget().getEffectiveNumberOfParameters() = 1
320+
this.getTarget() instanceof OverloadedPointerDereferenceFunction
314321
}
315322

316323
override string getAPrimaryQlClass() { result = "OverloadedPointerDereferenceExpr" }
@@ -350,53 +357,6 @@ class OverloadedPointerDereferenceExpr extends FunctionCall {
350357
}
351358
}
352359

353-
/**
354-
* An instance of a call to a _user-defined_ `operator->`.
355-
* ```
356-
* struct T2 { T1 b; };
357-
* struct T3 { T2* operator->(); };
358-
* T3 a;
359-
* T1 x = a->b;
360-
* ```
361-
*/
362-
class OverloadedArrowExpr extends FunctionCall {
363-
OverloadedArrowExpr() { getTarget().hasName("operator->") }
364-
365-
override string getAPrimaryQlClass() { result = "OverloadedArrowExpr" }
366-
367-
/** Gets the expression this `operator->` applies to. */
368-
Expr getExpr() { result = this.getQualifier() }
369-
370-
/** Gets the field accessed by this call to `operator->`, if any. */
371-
FieldAccess getFieldAccess() { result.getQualifier() = this }
372-
373-
override predicate mayBeImpure() {
374-
FunctionCall.super.mayBeImpure() and
375-
(
376-
this.getExpr().mayBeImpure()
377-
or
378-
not exists(Class declaring |
379-
this.getTarget().getDeclaringType().isConstructedFrom*(declaring)
380-
|
381-
declaring.getNamespace() instanceof StdNamespace
382-
)
383-
)
384-
}
385-
386-
override predicate mayBeGloballyImpure() {
387-
FunctionCall.super.mayBeGloballyImpure() and
388-
(
389-
this.getExpr().mayBeGloballyImpure()
390-
or
391-
not exists(Class declaring |
392-
this.getTarget().getDeclaringType().isConstructedFrom*(declaring)
393-
|
394-
declaring.getNamespace() instanceof StdNamespace
395-
)
396-
)
397-
}
398-
}
399-
400360
/**
401361
* An instance of a _user-defined_ binary `operator[]` applied to its arguments.
402362
* ```

cpp/ql/src/semmle/code/cpp/models/Models.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ private import implementations.Recv
3333
private import implementations.Accept
3434
private import implementations.Poll
3535
private import implementations.Select
36-
private import implementations.PointerWrapper

cpp/ql/src/semmle/code/cpp/models/implementations/PointerWrapper.qll

Lines changed: 0 additions & 26 deletions
This file was deleted.

cpp/ql/src/semmle/code/cpp/models/implementations/SmartPointer.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import semmle.code.cpp.models.interfaces.Taint
2+
import semmle.code.cpp.models.interfaces.PointerWrapper
23

34
/**
45
* The `std::shared_ptr` and `std::unique_ptr` template classes.
56
*/
6-
private class UniqueOrSharedPtr extends Class {
7+
private class UniqueOrSharedPtr extends Class, PointerWrapper {
78
UniqueOrSharedPtr() { this.hasQualifiedName(["std", "bsl"], ["shared_ptr", "unique_ptr"]) }
9+
10+
override MemberFunction getADereferenceFunction() {
11+
result.(OverloadedPointerDereferenceFunction).getDeclaringType() = this
12+
}
13+
14+
override MemberFunction getAnUnwrapperFunction() {
15+
result.getDeclaringType() = this and
16+
result.hasName(["operator->", "get"])
17+
}
818
}
919

1020
/**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/** Provides classes for modeling pointer wrapper types and expressions. */
2+
3+
private import cpp
4+
5+
/** A class that wraps a pointer type. For example, `std::unique_ptr` and `std::shared_ptr`. */
6+
abstract class PointerWrapper extends Class {
7+
/** Gets a member fucntion of this class that dereferences wrapped pointer, if any. */
8+
abstract MemberFunction getADereferenceFunction();
9+
10+
/** Gets a member fucntion of this class that returns the wrapped pointer, if any. */
11+
abstract MemberFunction getAnUnwrapperFunction();
12+
}

0 commit comments

Comments
 (0)