Skip to content

Commit f5c52ac

Browse files
committed
C++: Fix joins in 'isModifiableAtImpl'.
1 parent 9446249 commit f5c52ac

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,8 @@ private Type getTypeImpl0(Type t, int indirectionIndex) {
997997
*
998998
* If `indirectionIndex` cannot be stripped off `t`, an `UnknownType` is returned.
999999
*/
1000-
bindingset[indirectionIndex]
1000+
bindingset[t, indirectionIndex]
1001+
pragma[inline_late]
10011002
Type getTypeImpl(Type t, int indirectionIndex) {
10021003
result = getTypeImpl0(t, indirectionIndex)
10031004
or

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/SsaInternalsCommon.qll

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,11 @@ class BaseCallVariable extends AbstractBaseSourceVariable, TBaseCallVariable {
418418
}
419419

420420
private module IsModifiableAtImpl {
421+
pragma[nomagic]
422+
private predicate isUnderlyingIndirectionType(Type t) {
423+
t = any(Indirection ind).getUnderlyingType()
424+
}
425+
421426
/**
422427
* Holds if the `indirectionIndex`'th dereference of a value of type
423428
* `cppType` is a type that can be modified (either by modifying the value
@@ -445,10 +450,9 @@ private module IsModifiableAtImpl {
445450
bindingset[cppType, indirectionIndex]
446451
pragma[inline_late]
447452
private predicate impl(CppType cppType, int indirectionIndex) {
448-
exists(Type pointerType, Type base, Type t |
449-
pointerType = t.getUnderlyingType() and
450-
pointerType = any(Indirection ind).getUnderlyingType() and
451-
cppType.hasType(t, _) and
453+
exists(Type pointerType, Type base |
454+
isUnderlyingIndirectionType(pointerType) and
455+
cppType.hasUnderlyingType(pointerType, _) and
452456
base = getTypeImpl(pointerType, indirectionIndex)
453457
|
454458
// The value cannot be modified if it has a const specifier,

cpp/ql/lib/semmle/code/cpp/ir/internal/CppType.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class CppType extends TCppType {
227227
predicate hasType(Type type, boolean isGLValue) { none() }
228228

229229
/**
230-
* Holds if this type represents the C++ type `type`. If `isGLValue` is `true`, then this type
230+
* Holds if this type represents the C++ unspecified type `type`. If `isGLValue` is `true`, then this type
231231
* represents a glvalue of type `type`. Otherwise, it represents a prvalue of type `type`.
232232
*/
233233
final predicate hasUnspecifiedType(Type type, boolean isGLValue) {
@@ -236,6 +236,18 @@ class CppType extends TCppType {
236236
type = specifiedType.getUnspecifiedType()
237237
)
238238
}
239+
240+
/**
241+
* Holds if this type represents the C++ type `type` (after resolving
242+
* typedefs). If `isGLValue` is `true`, then this type represents a glvalue
243+
* of type `type`. Otherwise, it represents a prvalue of type `type`.
244+
*/
245+
final predicate hasUnderlyingType(Type type, boolean isGLValue) {
246+
exists(Type typedefType |
247+
this.hasType(typedefType, isGLValue) and
248+
type = typedefType.getUnderlyingType()
249+
)
250+
}
239251
}
240252

241253
/**

0 commit comments

Comments
 (0)