Recent clang version, detect attemps to dereference or call NULL, and
eliminate the code.
../../tests/userprog/bad-read.c:11:9: warning: indirection of
non-volatile null pointer will be deleted, not trap [-Wnull-dereference]
*(int *) NULL);
^~~~~~~~~~~~~
This patchs adds the volatile modifier as necessary.
It allows to use clang to compile the tests.
#include "tests/lib.h"
#include "tests/main.h"
+typedef int (* volatile functionptr)(void);
+
void
test_main (void)
{
+ functionptr fp = NULL;
msg ("Congratulations - you have successfully called NULL: %d",
- ((int (*)(void))NULL)());
+ fp());
fail ("should have exited with -1");
}
test_main (void)
{
msg ("Congratulations - you have successfully dereferenced NULL: %d",
- *(int *)NULL);
+ *(volatile int *) NULL);
fail ("should have exited with -1");
}
void
test_main (void)
{
- *(int *)NULL = 42;
+ *(volatile int *)NULL = 42;
fail ("should have exited with -1");
}
{
consume_some_resources ();
random_init (seed);
- int *PHYS_BASE = (int *)0xC0000000;
+ volatile int *PHYS_BASE = (volatile int *)0xC0000000;
switch (random_ulong () % 5)
{
case 0:
- *(int *) NULL = 42;
+ *(volatile int *) NULL = 42;
case 1:
- return *(int *) NULL;
+ return *(volatile int *) NULL;
case 2:
return *PHYS_BASE;