Mercurial > hg > CbC > CbC_gcc
view gcc/testsuite/gcc.dg/atomic-compare-exchange-2.c @ 144:8f4e72ab4e11
fix segmentation fault caused by nothing next cur_op to end
author | Takahiro SHIMIZU <anatofuz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 23 Dec 2018 21:23:56 +0900 |
parents | 04ced10e8804 |
children |
line wrap: on
line source
/* Test __atomic routines for existence and proper execution on 2 byte values with each valid memory model. */ /* { dg-do run } */ /* { dg-require-effective-target sync_char_short } */ /* Test the execution of the __atomic_compare_exchange_n builtin for a short. */ extern void abort(void); short v = 0; short expected = 0; short max = ~0; short desired = ~0; short zero = 0; #define STRONG 0 #define WEAK 1 int main () { if (!__atomic_compare_exchange_n (&v, &expected, max, STRONG , __ATOMIC_RELAXED, __ATOMIC_RELAXED)) abort (); if (expected != 0) abort (); if (__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) abort (); if (expected != max) abort (); if (!__atomic_compare_exchange_n (&v, &expected, 0, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE)) abort (); if (expected != max) abort (); if (v != 0) abort (); if (__atomic_compare_exchange_n (&v, &expected, desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) abort (); if (expected != 0) abort (); if (!__atomic_compare_exchange_n (&v, &expected, desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) abort (); if (expected != 0) abort (); if (v != max) abort (); /* Now test the generic version. */ v = 0; if (!__atomic_compare_exchange (&v, &expected, &max, STRONG, __ATOMIC_RELAXED, __ATOMIC_RELAXED)) abort (); if (expected != 0) abort (); if (__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_ACQUIRE, __ATOMIC_RELAXED)) abort (); if (expected != max) abort (); if (!__atomic_compare_exchange (&v, &expected, &zero, STRONG , __ATOMIC_RELEASE, __ATOMIC_ACQUIRE)) abort (); if (expected != max) abort (); if (v != 0) abort (); if (__atomic_compare_exchange (&v, &expected, &desired, WEAK, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) abort (); if (expected != 0) abort (); if (!__atomic_compare_exchange (&v, &expected, &desired, STRONG , __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)) abort (); if (expected != 0) abort (); if (v != max) abort (); return 0; }