From: bdemsky Date: Mon, 22 Jun 2015 18:47:36 +0000 (-0700) Subject: bug fix for atomic adds/subtracts on pointers X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7c510878f9679da10de79c289df402356b092396;p=c11tester.git bug fix for atomic adds/subtracts on pointers --- diff --git a/include/impatomic.h b/include/impatomic.h index 1b9ce6be..b4273eee 100644 --- a/include/impatomic.h +++ b/include/impatomic.h @@ -2330,23 +2330,28 @@ inline bool atomic_compare_exchange_strong inline void* atomic_fetch_add_explicit ( volatile atomic_address* __a__, ptrdiff_t __m__, memory_order __x__ ) { - void* volatile* __p__ = &((__a__)->__f__); - void* __r__ = (void *) model_rmwr_action((void *)__p__, __x__); - model_rmw_action((void *)__p__, __x__, (uint64_t) ((char*)(*__p__) + __m__)); - return __r__; } + volatile __typeof__((__a__)->__f__)* __p__ = & ((__a__)->__f__); + __typeof__((__a__)->__f__) __old__=(__typeof__((__a__)->__f__)) model_rmwr_action((void *)__p__, __x__); + __typeof__((__a__)->__f__) __copy__= __old__; + __copy__ = (void *) (((char *)__copy__) + __m__); + model_rmw_action((void *)__p__, __x__, (uint64_t) __copy__); + return __old__; +} -inline void* atomic_fetch_add + inline void* atomic_fetch_add ( volatile atomic_address* __a__, ptrdiff_t __m__ ) { return atomic_fetch_add_explicit( __a__, __m__, memory_order_seq_cst ); } inline void* atomic_fetch_sub_explicit ( volatile atomic_address* __a__, ptrdiff_t __m__, memory_order __x__ ) -{ - void* volatile* __p__ = &((__a__)->__f__); - void* __r__ = (void *) model_rmwr_action((void *)__p__, __x__); - model_rmw_action((void *)__p__, __x__, (uint64_t)((char*)(*__p__) - __m__)); - return __r__; } +{ volatile __typeof__((__a__)->__f__)* __p__ = & ((__a__)->__f__); + __typeof__((__a__)->__f__) __old__=(__typeof__((__a__)->__f__)) model_rmwr_action((void *)__p__, __x__); + __typeof__((__a__)->__f__) __copy__= __old__; + __copy__ = (void *) (((char *)__copy__) - __m__); + model_rmw_action((void *)__p__, __x__, (uint64_t) __copy__); + return __old__; +} inline void* atomic_fetch_sub ( volatile atomic_address* __a__, ptrdiff_t __m__ )