Skip to content

Commit d7d1554

Browse files
authored
Merge pull request #21465 from owen-mc/go/small-tweaks
Go: improve detection of type expressions when database is missing some type information
2 parents 0bb6ff5 + a16c438 commit d7d1554

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

go/ql/lib/semmle/go/Expr.qll

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ class ConversionExpr extends CallOrConversionExpr {
829829
/**
830830
* A function call expression.
831831
*
832-
* On snapshots with incomplete type information, type conversions may be misclassified
832+
* On databases with incomplete type information, type conversions may be misclassified
833833
* as function call expressions.
834834
*
835835
* Examples:
@@ -2096,7 +2096,7 @@ class LabelName extends Name {
20962096
* Holds if `e` is a type expression, as determined by a bottom-up syntactic
20972097
* analysis starting with `TypeName`s.
20982098
*
2099-
* On a snapshot with full type information, this predicate covers all type
2099+
* On a database with full type information, this predicate covers all type
21002100
* expressions. However, if type information is missing then not all type names
21012101
* may be identified as such, so not all type expressions can be determined by
21022102
* a bottom-up analysis. In such cases, `isTypeExprTopDown` below is useful.
@@ -2134,11 +2134,12 @@ private predicate isTypeExprBottomUp(Expr e) {
21342134
* Holds if `e` must be a type expression because it either occurs in a syntactic
21352135
* position where a type is expected, or it is part of a larger type expression.
21362136
*
2137-
* This predicate is only needed on snapshots for which type information is
2138-
* incomplete. It is an underapproximation; in cases where it is syntactically ambiguous
2139-
* whether an expression refers to a type or a value, we conservatively assume that
2140-
* it may be the latter and so this predicate does not consider the expression to be
2141-
* a type expression.
2137+
* This predicate is only needed on databases for which type information is
2138+
* incomplete - for example, when some dependencies could not be reached during
2139+
* extraction. It is an underapproximation; in cases where it is syntactically
2140+
* ambiguous whether an expression refers to a type or a value, we conservatively
2141+
* assume that it may be the latter and so this predicate does not consider the
2142+
* expression to be a type expression.
21422143
*/
21432144
pragma[nomagic]
21442145
private predicate isTypeExprTopDown(Expr e) {
@@ -2148,20 +2149,12 @@ private predicate isTypeExprTopDown(Expr e) {
21482149
or
21492150
e = any(ArrayTypeExpr ae).getElement()
21502151
or
2151-
e = any(FieldDecl f).getTypeExpr()
2152-
or
2153-
e = any(ParameterDecl pd).getTypeExpr()
2152+
e = any(FieldBase fb).getTypeExpr()
21542153
or
21552154
e = any(TypeParamDecl tpd).getTypeConstraintExpr()
21562155
or
21572156
e = any(TypeParamDecl tpd).getNameExpr(_)
21582157
or
2159-
e = any(ReceiverDecl rd).getTypeExpr()
2160-
or
2161-
e = any(ResultVariableDecl rvd).getTypeExpr()
2162-
or
2163-
e = any(MethodSpec md).getTypeExpr()
2164-
or
21652158
e = any(MapTypeExpr mt).getKeyTypeExpr()
21662159
or
21672160
e = any(MapTypeExpr mt).getValueTypeExpr()

go/ql/lib/semmle/go/controlflow/IR.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ module IR {
294294
/**
295295
* An IR instruction that reads the value of a field.
296296
*
297-
* On snapshots with incomplete type information, method expressions may sometimes be
297+
* On databases with incomplete type information, method expressions may sometimes be
298298
* misclassified as field reads.
299299
*/
300300
class FieldReadInstruction extends ComponentReadInstruction {

go/ql/src/filters/ClassifyFiles.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Classify files
3-
* @description This query produces a list of all files in a snapshot that are classified as
3+
* @description This query produces a list of all files in a database that are classified as
44
* generated code, test code or vendored-in library code.
55
* @kind file-classifier
66
* @id go/file-classifier

0 commit comments

Comments
 (0)