From: Pablo de Oliveira Date: Mon, 17 Mar 2014 18:13:22 +0000 (+0100) Subject: Fix userprog tests for clang X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c203f0f1d43526aaa9be904f851a9aa185809dff;p=pintos-anon Fix userprog tests for clang 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. --- diff --git a/src/tests/userprog/bad-jump.c b/src/tests/userprog/bad-jump.c index 51b7c9f..a915c39 100644 --- a/src/tests/userprog/bad-jump.c +++ b/src/tests/userprog/bad-jump.c @@ -4,10 +4,13 @@ #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"); } diff --git a/src/tests/userprog/bad-read.c b/src/tests/userprog/bad-read.c index 904c278..d821a9a 100644 --- a/src/tests/userprog/bad-read.c +++ b/src/tests/userprog/bad-read.c @@ -8,6 +8,6 @@ void test_main (void) { msg ("Congratulations - you have successfully dereferenced NULL: %d", - *(int *)NULL); + *(volatile int *) NULL); fail ("should have exited with -1"); } diff --git a/src/tests/userprog/bad-write.c b/src/tests/userprog/bad-write.c index 000c26b..9082c9b 100644 --- a/src/tests/userprog/bad-write.c +++ b/src/tests/userprog/bad-write.c @@ -7,6 +7,6 @@ void test_main (void) { - *(int *)NULL = 42; + *(volatile int *)NULL = 42; fail ("should have exited with -1"); } diff --git a/src/tests/userprog/no-vm/multi-oom.c b/src/tests/userprog/no-vm/multi-oom.c index 6a4472d..cd2c939 100644 --- a/src/tests/userprog/no-vm/multi-oom.c +++ b/src/tests/userprog/no-vm/multi-oom.c @@ -67,15 +67,15 @@ consume_some_resources_and_die (int 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: - *(int *) NULL = 42; + *(volatile int *) NULL = 42; case 1: - return *(int *) NULL; + return *(volatile int *) NULL; case 2: return *PHYS_BASE;