[PATCH] sanity-tests: Be even more aggressive in avoiding optimization

Aaron Faanes dafrito at gmail.com
Sun Sep 15 10:52:41 PDT 2013


clang optimizes the malloc away even when assert() is called. Printing
the memory address should be side-effecty enough to avoid this
optimization.
---
 tests/sanity-test.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tests/sanity-test.c b/tests/sanity-test.c
index 46f4f85..0df2e98 100644
--- a/tests/sanity-test.c
+++ b/tests/sanity-test.c
@@ -25,6 +25,7 @@
 #include <sys/types.h>
 #include <signal.h>
 #include <unistd.h>
+#include <stdio.h>
 
 #include "test-runner.h"
 #include "wayland-util.h"
@@ -75,6 +76,7 @@ FAIL_TEST(sanity_malloc_direct)
 	p = malloc(10);	/* memory leak */
 	assert(p);	/* assert that we got memory, also prevents
 			 * the malloc from getting optimized away. */
+	printf("Avoiding optimization %p\n", p);
 	free(NULL);	/* NULL must not be counted */
 }
 
-- 
1.8.3.1



More information about the wayland-devel mailing list