diff mbox

[i386] : Robustify gcc.target/i386/readeflags-1.c

Message ID CAFULd4bfUZsUOESzPwF2kS8JszLismBhXme2ZX5oQtiNXt_M9w@mail.gmail.com
State New
Headers show

Commit Message

Uros Bizjak July 10, 2015, 3:45 p.m. UTC
Hello!

When using __readeflags, we have to prevent possible flag-clobbering
zero-extensions and make flag-setting operation persistent.

2015-07-10  Uros Bizjak  <ubizjak@gmail.com>

    PR target/66703
    * gcc.target/i386/readeflags-1.c (readeflags_test): Declare with
    __attribute__((noinline, noclone)).  Change "x" to "volatile char"
    type to prevent possible flag-clobbering zero-extensions.
    * gcc.target/i386/pr66703.c: New test.

Tested on x86_64-linux-gnu {,-m32}  and committed to mainline SVN.

Uros.
diff mbox

Patch

Index: gcc.target/i386/readeflags-1.c
===================================================================
--- gcc.target/i386/readeflags-1.c	(revision 225675)
+++ gcc.target/i386/readeflags-1.c	(working copy)
@@ -11,10 +11,11 @@ 
 #define EFLAGS_TYPE unsigned int
 #endif
 
-static EFLAGS_TYPE
+__attribute__((noinline, noclone))
+EFLAGS_TYPE
 readeflags_test (unsigned int a, unsigned int b)
 {
-  unsigned x = (a == b);
+  volatile char x = (a == b);
   return __readeflags ();
 }
 
Index: gcc.target/i386/pr66703.c
===================================================================
--- gcc.target/i386/pr66703.c   (revision 0)
+++ gcc.target/i386/pr66703.c   (working copy)
@@ -0,0 +1,4 @@ 
+/* { dg-do run { target { ia32 } } } */
+/* { dg-options "-O0 -mtune=pentium" } */
+
+#include "readeflags-1.c"