Skip to content

Commit b0a7f20

Browse files
authored
Merge pull request #1343 from rdmarsh2/rdmarsh/cpp/getUnspecifiedType
C++: add getUnspecifiedType() for exprs and decls
2 parents 85f275c + b4ef532 commit b0a7f20

File tree

67 files changed

+218
-189
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+218
-189
lines changed

change-notes/1.21/analysis-cpp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,4 @@
3636
- The taint tracking library now includes taint-specific edges for functions modeled in `semmle.code.cpp.models.interfaces.DataFlow`.
3737
- The taint tracking library adds flow through library functions that are modeled in `semmle.code.cpp.models.interfaces.Taint`. Queries can add subclasses of `TaintFunction` to specify additional flow.
3838
- There is a new `FoldExpr` class, representing C++17 fold expressions.
39+
- The member predicates `DeclarationEntry.getUnspecifiedType`, `Expr.getUnspecifiedType`, and `Variable.getUnspecifiedType` have been added. These should be preferred over the existing `getUnderlyingType` predicates.

cpp/ql/src/Best Practices/Exceptions/CatchingByValue.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
import cpp
1414

1515
from CatchBlock cb, Class caughtType
16-
where caughtType = cb.getParameter().getType().getUnderlyingType().getUnspecifiedType()
16+
where caughtType = cb.getParameter().getUnspecifiedType()
1717
select cb,
1818
"This should catch a " + caughtType.getName() + " by (const) reference rather than by value."

cpp/ql/src/Best Practices/Unused Entities/UnusedLocals.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class TemplateDependentType extends Type {
4040
* A variable whose declaration has, or may have, side effects.
4141
*/
4242
predicate declarationHasSideEffects(Variable v) {
43-
exists(Class c | c = v.getType().getUnderlyingType().getUnspecifiedType() |
43+
exists(Class c | c = v.getUnspecifiedType() |
4444
c.hasConstructor() or
4545
c.hasDestructor()
4646
)

cpp/ql/src/Best Practices/Unused Entities/UnusedStaticVariables.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import cpp
1515

1616
predicate declarationHasSideEffects(Variable v) {
17-
exists(Class c | c = v.getType().getUnderlyingType().getUnspecifiedType() |
17+
exists(Class c | c = v.getUnspecifiedType() |
1818
c.hasConstructor() or c.hasDestructor()
1919
)
2020
}

cpp/ql/src/Likely Bugs/AmbiguouslySignedBitField.ql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
import cpp
1818

1919
from BitField bf
20-
where not bf.getType().getUnspecifiedType().(IntegralType).isExplicitlySigned()
21-
and not bf.getType().getUnspecifiedType().(IntegralType).isExplicitlyUnsigned()
22-
and not bf.getType().getUnspecifiedType() instanceof Enum
23-
and not bf.getType().getUnspecifiedType() instanceof BoolType
20+
where not bf.getUnspecifiedType().(IntegralType).isExplicitlySigned()
21+
and not bf.getUnspecifiedType().(IntegralType).isExplicitlyUnsigned()
22+
and not bf.getUnspecifiedType() instanceof Enum
23+
and not bf.getUnspecifiedType() instanceof BoolType
2424
// At least for C programs on Windows, BOOL is a common typedef for a type
2525
// representing BoolType.
2626
and not bf.getType().hasName("BOOL")

cpp/ql/src/Likely Bugs/Arithmetic/BadCheckOdd.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import cpp
1515
from EqualityOperation t, RemExpr lhs, Literal rhs
1616
where t.getLeftOperand() = lhs and
1717
t.getRightOperand() = rhs and
18-
lhs.getLeftOperand().getType().getUnspecifiedType().(IntegralType).isSigned() and
18+
lhs.getLeftOperand().getUnspecifiedType().(IntegralType).isSigned() and
1919
lhs.getRightOperand().getValue() = "2" and
2020
rhs.getValue() = "1"
2121
select t, "Possibly invalid test for oddness. This will fail for negative numbers."

cpp/ql/src/Likely Bugs/Arithmetic/PointlessSelfComparison.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ predicate pointlessSelfComparison(ComparisonOperation cmp) {
4545
predicate nanTest(EqualityOperation cmp) {
4646
pointlessSelfComparison(cmp) and
4747
exists (Type t
48-
| t = cmp.getLeftOperand().getType().getUnspecifiedType()
48+
| t = cmp.getLeftOperand().getUnspecifiedType()
4949
| t instanceof FloatingPointType or
5050
t instanceof TemplateParameter)
5151
}

cpp/ql/src/Likely Bugs/Conversion/CastArrayPointerArithmetic.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,5 @@ predicate introducesNewField(Class derived, Class base) {
5555

5656
from DataFlow::PathNode source, DataFlow::PathNode sink, CastToPointerArithFlow cfg
5757
where cfg.hasFlowPath(source, sink)
58-
and source.getNode().asExpr().getFullyConverted().getType().getUnspecifiedType() = sink.getNode().asExpr().getFullyConverted().getType().getUnspecifiedType()
58+
and source.getNode().asExpr().getFullyConverted().getUnspecifiedType() = sink.getNode().asExpr().getFullyConverted().getUnspecifiedType()
5959
select sink, source, sink, "Pointer arithmetic here may be done with the wrong type because of the cast $@.", source, "here"

cpp/ql/src/Likely Bugs/Format/NonConstantFormat.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ predicate gettextFunction(Function f, int arg) {
4848

4949
predicate stringArray(Variable arr, AggregateLiteral init) {
5050
arr.getInitializer().getExpr() = init and
51-
stringType(arr.getType().getUnspecifiedType().(ArrayType).getBaseType(), _)
51+
stringType(arr.getUnspecifiedType().(ArrayType).getBaseType(), _)
5252
// Ideally, this predicate should also check that no item of `arr` is ever
5353
// reassigned, but such an analysis could get fairly complicated. Instead, we
5454
// just hope that nobody would initialize an array of constants and then

cpp/ql/src/Likely Bugs/Memory Management/AllocaInLoop.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class LoopWithAlloca extends Stmt {
7575
conditionRequires(eq, truth) and
7676
eq.getAnOperand().getValue().toInt() = 1 and
7777
e = eq.getAnOperand() and
78-
e.getType().getUnspecifiedType() instanceof BoolType and
78+
e.getUnspecifiedType() instanceof BoolType and
7979
not exists(e.getValue())
8080
)
8181
or
@@ -84,7 +84,7 @@ class LoopWithAlloca extends Stmt {
8484
conditionRequires(eq, truth.booleanNot()) and
8585
eq.getAnOperand().getValue().toInt() = 1 and
8686
e = eq.getAnOperand() and
87-
e.getType().getUnspecifiedType() instanceof BoolType and
87+
e.getUnspecifiedType() instanceof BoolType and
8888
not exists(e.getValue())
8989
)
9090
or

0 commit comments

Comments
 (0)