CPP: Add a test of ExprHasNoEffect.ql with a call to a 'weak' function.

This commit is contained in:
Geoffrey White
2019-06-24 18:28:15 +01:00
parent cb43d27344
commit aee2af7ca1
2 changed files with 22 additions and 0 deletions

View File

@@ -33,3 +33,5 @@
| volatile.c:12:5:12:9 | access to array | This expression has no effect. | volatile.c:12:5:12:9 | access to array | |
| 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

@@ -0,0 +1,20 @@
int myNothingFunction()
{
// does nothing
return 0;
}
int __attribute__((__weak__)) myWeakNothingFunction()
{
// does nothing, but we could be overridden at the linker stage with a non-weak definition
// from elsewhere in the program.
return 0;
}
void testWeak() {
myNothingFunction(); // BAD
myWeakNothingFunction(); // GOOD [FALSE POSITIVE]
}