Skip to content

Commit 9a0645a

Browse files
committed
CPP: Calls to weak functions should be considered impure.
1 parent aee2af7 commit 9a0645a

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

cpp/ql/src/semmle/code/cpp/exprs/Call.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,14 @@ class FunctionCall extends Call, @funbindexpr {
275275
override predicate mayBeImpure() {
276276
this.getChild(_).mayBeImpure() or
277277
this.getTarget().mayHaveSideEffects() or
278-
isVirtual()
278+
isVirtual() or
279+
getTarget().getAnAttribute().getName() = "weak"
279280
}
280281
override predicate mayBeGloballyImpure() {
281282
this.getChild(_).mayBeGloballyImpure() or
282283
this.getTarget().mayHaveSideEffects() or
283-
isVirtual()
284+
isVirtual() or
285+
getTarget().getAnAttribute().getName() = "weak"
284286
}
285287
}
286288

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/ExprHasNoEffect.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,3 @@
3434
| volatile.c:16:5:16:7 | * ... | This expression has no effect. | volatile.c:16:5:16:7 | * ... | |
3535
| volatile.c:20:5:20:13 | * ... | This expression has no effect. | volatile.c:20:5:20:13 | * ... | |
3636
| weak.c:18:2:18:18 | call to myNothingFunction | This expression has no effect (because $@ has no external side effects). | weak.c:2:5:2:21 | myNothingFunction | myNothingFunction |
37-
| weak.c:19:2:19:22 | call to myWeakNothingFunction | This expression has no effect (because $@ has no external side effects). | weak.c:9:31:9:51 | myWeakNothingFunction | myWeakNothingFunction |

cpp/ql/test/query-tests/Likely Bugs/Likely Typos/ExprHasNoEffect/weak.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ int __attribute__((__weak__)) myWeakNothingFunction()
1616

1717
void testWeak() {
1818
myNothingFunction(); // BAD
19-
myWeakNothingFunction(); // GOOD [FALSE POSITIVE]
19+
myWeakNothingFunction(); // GOOD
2020
}

0 commit comments

Comments
 (0)