Skip to content

Commit a4ca101

Browse files
committed
C++: Add some bindingset annotations.
1 parent 4f8f78b commit a4ca101

1 file changed

Lines changed: 19 additions & 14 deletions

File tree

‎cpp/ql/lib/semmle/code/cpp/dataflow/ExternalFlow.qll‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ module ConstructorForwarding {
12201220
(t1.isVolatile() implies t2.isVolatile())
12211221
}
12221222

1223+
bindingset[arg]
12231224
private predicate baseTypeCompatible(Type arg, Type param) {
12241225
param.stripTopLevelSpecifiers() = arg.stripTopLevelSpecifiers().(Class).getABaseClass+() and
12251226
preservesQualifiers(arg, param)
@@ -1229,6 +1230,7 @@ module ConstructorForwarding {
12291230

12301231
private predicate routineType(Type t) { t.stripTopLevelSpecifiers() instanceof RoutineType }
12311232

1233+
bindingset[arg]
12321234
private predicate pointerConversion(Cpp::PointerType arg, Cpp::PointerType param) {
12331235
exists(Type argBase, Type paramBase |
12341236
argBase = arg.getBaseType() and
@@ -1256,6 +1258,7 @@ module ConstructorForwarding {
12561258
t instanceof RoutineType
12571259
}
12581260

1261+
bindingset[t, category]
12591262
private predicate referenceAcceptsCategory(Cpp::ReferenceType t, ValueCategory category) {
12601263
if t instanceof Cpp::LValueReferenceType
12611264
then
@@ -1291,6 +1294,7 @@ module ConstructorForwarding {
12911294
reference instanceof Cpp::RValueReferenceType and result = XValue()
12921295
}
12931296

1297+
bindingset[t]
12941298
private Type getValueType(Type t, ValueCategory category) {
12951299
result = t.(FunctionReferenceType).getBaseType().getUnderlyingType() and
12961300
category = LValue()
@@ -1304,13 +1308,23 @@ module ConstructorForwarding {
13041308
category = PRValue()
13051309
}
13061310

1307-
bindingset[arg, param]
1308-
pragma[inline_late]
1311+
bindingset[arg]
13091312
private predicate qualificationCompatible(Type arg, Type param) {
13101313
arg.stripTopLevelSpecifiers() = param.stripTopLevelSpecifiers() and
13111314
preservesQualifiers(arg, param)
13121315
}
13131316

1317+
bindingset[argType, category]
1318+
private predicate matchesParameter(Type argType, ValueCategory category, Type paramType) {
1319+
exists(Type base | base = paramType.(Cpp::ReferenceType).getBaseType() |
1320+
qualificationCompatible(argType, base) and
1321+
referenceAcceptsCategory(paramType, category)
1322+
)
1323+
or
1324+
not paramType instanceof Cpp::ReferenceType and
1325+
argType.stripTopLevelSpecifiers() = paramType.stripTopLevelSpecifiers()
1326+
}
1327+
13141328
private Cpp::PointerType pointerType(Type base) {
13151329
result.getBaseType() = base.getUnderlyingType()
13161330
}
@@ -1398,7 +1412,8 @@ module ConstructorForwarding {
13981412
private predicate convertingConstructorStep(TypeState argState, TypeState paramState) {
13991413
exists(ConvertingConstructor constructor |
14001414
argState.hasNotUsedConversion() and
1401-
argState.matchesParameter(constructor.getUnderlyingFromType()) and
1415+
matchesParameter(argState.getType(), argState.getCategory(),
1416+
constructor.getUnderlyingFromType()) and
14021417
paramState = MkTypeState(constructor.getDeclaringType(), PRValue(), true, Initial())
14031418
)
14041419
}
@@ -1472,19 +1487,9 @@ module ConstructorForwarding {
14721487
)
14731488
}
14741489

1475-
predicate matchesParameter(Type paramType) {
1476-
exists(Type base | base = paramType.(Cpp::ReferenceType).getBaseType() |
1477-
qualificationCompatible(this.getType(), base) and
1478-
referenceAcceptsCategory(paramType, this.getCategory())
1479-
)
1480-
or
1481-
not paramType instanceof Cpp::ReferenceType and
1482-
this.getType().stripTopLevelSpecifiers() = paramType.stripTopLevelSpecifiers()
1483-
}
1484-
14851490
predicate isSink(Type paramType, Cpp::Constructor constructor) {
14861491
paramType = getConstructorParameterType(constructor, _) and
1487-
this.matchesParameter(paramType)
1492+
matchesParameter(this.getType(), this.getCategory(), paramType)
14881493
}
14891494
}
14901495

0 commit comments

Comments
 (0)