CPP: Calls to weak functions should be considered impure.

This commit is contained in:
Geoffrey White
2019-06-24 22:03:57 +01:00
parent aee2af7ca1
commit 9a0645ac0b
3 changed files with 5 additions and 4 deletions

View File

@@ -275,12 +275,14 @@ class FunctionCall extends Call, @funbindexpr {
override predicate mayBeImpure() {
this.getChild(_).mayBeImpure() or
this.getTarget().mayHaveSideEffects() or
isVirtual()
isVirtual() or
getTarget().getAnAttribute().getName() = "weak"
}
override predicate mayBeGloballyImpure() {
this.getChild(_).mayBeGloballyImpure() or
this.getTarget().mayHaveSideEffects() or
isVirtual()
isVirtual() or
getTarget().getAnAttribute().getName() = "weak"
}
}

View File

@@ -34,4 +34,3 @@
| volatile.c:16:5:16:7 | * ... | This expression has no effect. | volatile.c:16:5:16:7 | * ... | |
| volatile.c:20:5:20:13 | * ... | This expression has no effect. | volatile.c:20:5:20:13 | * ... | |
| 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 |
| 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 |

View File

@@ -16,5 +16,5 @@ int __attribute__((__weak__)) myWeakNothingFunction()
void testWeak() {
myNothingFunction(); // BAD
myWeakNothingFunction(); // GOOD [FALSE POSITIVE]
myWeakNothingFunction(); // GOOD
}