This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Uninitialized error with GCC mainline


On 2017.03.10 at 18:20 +0000, Joseph Myers wrote:
> On Fri, 10 Mar 2017, Markus Trippelsdorf wrote:
> 
> > > I don't know if it's a remaining case of the same issue, or something 
> > > else, but there are still -Wuninitialized errors building the testsuite 
> > > for x86_64 with GCC mainline.
> > > 
> > > ../sysdeps/x86_64/fpu/test-double-vlen4-wrappers.c: In function 'sincos_vlen4':
> > > ../sysdeps/x86_64/fpu/test-double-vlen4-wrappers.c:34:46: error: 'mr1' is used uninitialized in this function [-Werror=uninitialized]
> > >  VECTOR_WRAPPER_fFF_3 (WRAPPER_NAME (sincos), _ZGVcN4vvv_sincos)
> > 
> > This one looks legitimate. In sysdeps/x86/fpu/test-math-vector-sincos.h
> > it seems that r_loc[], r1_loc[] and  mr, mr1 should be initialized.
> 
> They're supposed to be initialized by INIT_VEC_PTRS_LOOP / by the results 
> being stored by the wrapped vector sincos function (unless there's 
> something wrong with that logic).

This is an aliasing issue and gcc warns with -Wstrict-aliasing=2:

../sysdeps/x86_64/fpu/test-double-vlen4-wrappers.c:144:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
../sysdeps/x86_64/fpu/test-double-vlen4-wrappers.c:149:7: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

-fno-strict-aliasing "fixes" the warning.

extern void _ZGVcN4vvv_sincos(__m256d, __m128i, __m128i, __m128i, __m128i);
void sincos_vlen4(double x, double *r, double *r1) {
  int i;
  double r_loc[4 / 2], r1_loc[4 / 2];
  __m256d mx;
  __m128i mr, mr1;
  do {
    for (i = 0; i < 4; i++) {
      mx[i] = x;
    }
  } while (0);
  do {
    for (i = 0; i < 4 / 2; i++) {
      ((double **)&mr)[i] = &r_loc[i]; //<----------- here
    }
  } while (0);
  do {
    for (i = 0; i < 4 / 2; i++) {
      ((double **)&mr1)[i] = &r1_loc[i]; //<--------- and here
    }
  } while (0);
  _ZGVcN4vvv_sincos(mx, mr, mr, mr1, mr1);
  do {
    for (i = 1; i < 4 / 2; i++) {
      if ((double)r_loc[0] != (double)r_loc[i]) {
        r_loc[0] = (double)r_loc[0] + 0.1;
        break;
      }
    }
  } while (0);
  do {
    for (i = 1; i < 4 / 2; i++) {
      if ((double)r1_loc[0] != (double)r1_loc[i]) {
        r1_loc[0] = (double)r1_loc[0] + 0.1;
        break;
      }
    }
  } while (0);
  *r = r_loc[0];
  *r1 = r1_loc[0];
  return;
}

-- 
Markus


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]