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"
#include "tests/lib.h"
#include "tests/main.h"
+typedef int (* volatile functionptr)(void);
+
msg ("Congratulations - you have successfully called NULL: %d",
msg ("Congratulations - you have successfully called NULL: %d",
- ((int (*)(void))NULL)());
fail ("should have exited with -1");
}
fail ("should have exited with -1");
}
test_main (void)
{
msg ("Congratulations - you have successfully dereferenced NULL: %d",
test_main (void)
{
msg ("Congratulations - you have successfully dereferenced NULL: %d",
+ *(volatile int *) NULL);
fail ("should have exited with -1");
}
fail ("should have exited with -1");
}
+ *(volatile int *)NULL = 42;
fail ("should have exited with -1");
}
fail ("should have exited with -1");
}
{
consume_some_resources ();
random_init (seed);
{
consume_some_resources ();
random_init (seed);
- int *PHYS_BASE = (int *)0xC0000000;
+ volatile int *PHYS_BASE = (volatile int *)0xC0000000;
switch (random_ulong () % 5)
{
case 0:
switch (random_ulong () % 5)
{
case 0:
+ *(volatile int *) NULL = 42;
+ return *(volatile int *) NULL;
case 2:
return *PHYS_BASE;
case 2:
return *PHYS_BASE;