summaryrefslogtreecommitdiff
path: root/lib/igt_core.h
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu.vizoso@collabora.com>2016-04-15 14:00:04 +0200
committerDaniel Vetter <daniel.vetter@ffwll.ch>2016-04-20 14:54:46 +0200
commit3450cba30efb554db9de080735fc6a74acca5d4c (patch)
tree082f50bd8eaab4ebfdfc2405e2dc17be451b3a7d /lib/igt_core.h
parentbe354f444e03edb7b73c8393762e90fc503d03b6 (diff)
lib: Declare loop variable as volatile before setjmp
The variable used as loop counter in the igt_fixture macro had unspecified value from the setjmp(3) man page quoted below. Because of that, in certain circumstances and with -O2 and -Os, the initialization of that variable would be eliminated and the compiler would complain of uninitialized usage. Below can be found a snippet that reproduces the problem with GCC 5.3.1 and 4.9.3 and the errors as printed by 5.3.1. "The compiler may optimize variables into registers, and longjmp() may restore the values of other registers in addition to the stack pointer and program counter. Consequently, the values of automatic variables are unspecified after a call to longjmp() if they meet all the following criteria: · they are local to the function that made the corresponding setjmp(3) call; · their values are changed between the calls to setjmp(3) and longjmp(); and · they are not declared as volatile." static void test(void) { igt_subtest_group { igt_fixture { } igt_subtest("foo") { } igt_fixture { } } } In file included from lib/intel_batchbuffer.h:8:0, from lib/drmtest.h:39, from lib/igt.h:27, from tests/kms_addfb_basic.c:28: tests/kms_addfb_basic.c: In function 'tiling_tests.isra.0': lib/igt_core.h:110:43: warning: '__tmpint245' is used uninitialized in this function [-Wuninitialized] #define igt_fixture for (int igt_tokencat(__tmpint,__LINE__) = 0; \ ^ lib/igt_core.h:110:43: note: '__tmpint245' was declared here #define igt_fixture for (int igt_tokencat(__tmpint,__LINE__) = 0; \ ^ lib/igt_core.h:148:31: note: in definition of macro '__igt_tokencat2' #define __igt_tokencat2(x, y) x ## y ^ lib/igt_core.h:110:30: note: in expansion of macro 'igt_tokencat' #define igt_fixture for (int igt_tokencat(__tmpint,__LINE__) = 0; \ ^ tests/kms_addfb_basic.c:245:3: note: in expansion of macro 'igt_fixture' igt_fixture { Signed-off-by: Tomeu Vizoso <tomeu.vizoso@collabora.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'lib/igt_core.h')
-rw-r--r--lib/igt_core.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/igt_core.h b/lib/igt_core.h
index b3fa7356..1b62371a 100644
--- a/lib/igt_core.h
+++ b/lib/igt_core.h
@@ -107,7 +107,7 @@ void __igt_fixture_end(void) __attribute__((noreturn));
* enumeration (e.g. when enumerating on systems without an intel gpu) such
* blocks should be annotated with igt_fixture.
*/
-#define igt_fixture for (int igt_tokencat(__tmpint,__LINE__) = 0; \
+#define igt_fixture for (volatile int igt_tokencat(__tmpint,__LINE__) = 0; \
igt_tokencat(__tmpint,__LINE__) < 1 && \
__igt_fixture() && \
(sigsetjmp(igt_subtest_jmpbuf, 1) == 0); \