(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.target/
cris/
torture/
sync-mis-op-s-1.c
       1  /* { dg-do run { target { ! *-*-* } } } */
       2  /* { dg-additional-sources "../sync-1.c" } */
       3  /* { dg-options "-Dop -Dtype=short -mno-unaligned-atomic-may-use-library" } */
       4  
       5  /* Make sure we get a SIGTRAP or equivalent when passing unaligned
       6     but otherwise valid pointers to the atomic builtins.  */
       7  
       8  #include <signal.h>
       9  #include <stdlib.h>
      10  
      11  #ifndef type
      12  #error type not defined
      13  #endif
      14  
      15  #ifndef op
      16  #define op 0
      17  #endif
      18  
      19  #ifndef xchg
      20  #define xchg 0
      21  #endif
      22  
      23  #if op
      24  int sfa (type *p, type *q, int a);
      25  #endif
      26  
      27  #if xchg
      28  void acen (type *ptr, type *val, type *ret);
      29  #endif
      30  
      31  #ifndef misalignment
      32  #define misalignment 1
      33  #endif
      34  
      35  volatile int trap_expected = 0;
      36  
      37  struct { char x[misalignment]; type i; } s __attribute__ ((__aligned__ (4)))
      38    = { {0}, (type) 0xdeadbeef };
      39  type x = 2;
      40  type ret = 42;
      41  
      42  #ifdef TRAP_USING_ABORT
      43  #define SYMSTR(x) STR1(__USER_LABEL_PREFIX__, x)
      44  #define STR1(x,y) STR2(x, y)
      45  #define STR2(x,y) #x #y
      46  /* LTO requires marking seemingly-unused-but-used global functions.  */
      47  void my_abort (void) __asm__ (SYMSTR (abort)) __attribute__ ((__used__));
      48  void my_abort (void)
      49  #else
      50  #error "can't catch break 8"
      51  #endif
      52  {
      53    if (1
      54  #ifndef TRAP_USING_ABORT
      55        && signum == SIGTRAP
      56  #endif
      57        && trap_expected
      58        && s.i == (type) 0xdeadbeef
      59        && x == 2 && ret == 42)
      60      exit (0);
      61  
      62  #ifdef TRAP_USING_ABORT
      63    /* We might be able to trust the exit-value getting through, but add
      64       a NULL-dereference SEGV just in case.  Make sure gcc doesn't
      65       understand the NULL.  */
      66    *({ int *p; asm ("" : "=rm" (p) : "0" (0)); p; }) = 0xdead;
      67    exit (2);
      68  #else
      69    abort ();
      70  #endif
      71  }
      72  
      73  int main(void)
      74  {
      75    type ret;
      76  
      77  #ifndef mis_ok
      78    trap_expected = 1;
      79  #endif
      80  
      81  #if op
      82    sfa (&s.i, &s.i, 42);
      83  
      84    /* We should have fallen into the trap now.  But don't call abort
      85       yet: if the trap is implemented as a call to abort, we have to
      86       tell the difference.  Set a global variable *and* make sure the
      87       setting isn't eliminated by optimizers: another call to sfa
      88       should do it.  */
      89    trap_expected = 0;
      90  
      91  #ifdef mis_ok
      92    /* We're missing a sequence point, but we shouldn't have the initial
      93       value.  */
      94    if (s.i == (type) 0xdeadbeef)
      95      abort ();
      96    exit (0);
      97  #endif
      98  
      99    sfa (&x, &x, 1);
     100  #else
     101    acen (&s.i, &x, &ret);
     102  
     103  #ifdef mis_ok
     104    if (s.i != 2 || x != 2 || ret != (type) 0xdeadbeef)
     105      abort ();
     106    exit (0);
     107  #endif
     108  
     109    trap_expected = 0;
     110  
     111    acen (&x, &x, &ret);
     112  #endif
     113  
     114    abort ();
     115  }