Skip to content

Fix performance regression from Compatible.qll #890

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions cpp/common/src/codingstandards/cpp/types/Compatible.qll
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ module TypesCompatibleConfig implements TypeEquivalenceSig {
or
// Enum types are compatible with one of char, int, or signed int, but the implementation
// decides.
[t1, t2] instanceof Enum and
([t1, t2] instanceof CharType or [t1, t2] instanceof IntType)
t1 instanceof Enum and
(t2 instanceof CharType or t2 instanceof IntType)
or
t2 instanceof Enum and
(t1 instanceof CharType or t1 instanceof IntType)
}

bindingset[t1, t2]
Expand All @@ -69,6 +72,7 @@ module TypesCompatibleConfig implements TypeEquivalenceSig {
/**
* Utilize QlBuiltins::InternSets to efficiently compare the sets of specifiers on two types.
*/
bindingset[t1, t2]
private predicate specifiersMatchExactly(Type t1, Type t2) {
t1 = t2
or
Expand Down Expand Up @@ -347,8 +351,15 @@ module FunctionDeclarationTypeEquivalence<TypeEquivalenceSig Config> {
predicate equalParameterTypes(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2) {
f1.getDeclaration() = f2.getDeclaration() and
forall(int i | exists([f1, f2].getParameterDeclarationEntry(i)) |
TypeEquivalence<Config, FunctionSignatureType>::equalTypes(f1.getParameterDeclarationEntry(i)
.getType(), f2.getParameterDeclarationEntry(i).getType())
equalParameterTypesAt(f1, f2, pragma[only_bind_into](i))
)
}

predicate equalParameterTypesAt(FunctionDeclarationEntry f1, FunctionDeclarationEntry f2, int i) {
pragma[only_bind_out](f1.getDeclaration()) = pragma[only_bind_out](f2.getDeclaration()) and
TypeEquivalence<Config, FunctionSignatureType>::equalTypes(
f1.getParameterDeclarationEntry(i).getType(),
f2.getParameterDeclarationEntry(i).getType()
)
}
}
Expand Down
Loading