C PATCH to add __atomic_fetch_* optimization for _Atomics (PR c/68908)

Joseph Myers joseph@codesourcery.com
Fri Dec 18 21:10:00 GMT 2015


On Fri, 18 Dec 2015, Marek Polacek wrote:

> +	  tree sz = TYPE_SIZE_UNIT (TREE_TYPE (lhs_type));
> +	  rhs = fold_build2_loc (loc, MULT_EXPR, rhs_type, rhs,
> +				 convert (rhs_type, sz));

Converting the size to rhs_type seems wrong, as does multiplying in 
rhs_type.  In a test like

struct s { char a[256]; } *_Atomic p;
char c;
void f (void) { p += c; }

rhs_type is char and the conversion of the size to char will result in 0.  
(Of course this needs expanding to produce an executable test that fails 
with the present patch.)  Instead, both size and rhs should be converted 
to ptrdiff_t and the multiplication done in ptrdiff_t.

-- 
Joseph S. Myers
joseph@codesourcery.com



More information about the Gcc-patches mailing list