1/* { dg-do compile } */
2/* { dg-options "-O2" } */
3/* { dg-require-effective-target tls_native } */
4
5struct A
6{
7  int a1;
8  int a2;
9};
10
11extern __thread const unsigned char *tcc1, **tcc2;
12
13extern inline const unsigned char ** __attribute__ ((const))
14foo (void)
15{
16  const unsigned char **a = &tcc1;
17  if (*a == 0)
18    *a = *tcc2 + 128;
19  return a;
20}
21
22extern inline int
23bar (const struct A *x)
24{
25  int a;
26
27  if (x->a2 & 8)
28    return 0;
29  a = x->a1;
30  return a > 0 && ((*foo ())[a] & 64);
31}
32
33int
34baz (const struct A *x, char *y)
35{
36  const struct A *a;
37
38  for (a = x; !!a->a1; a++)
39    if (! (x->a2 & 8))
40      if (bar (a))
41	{
42	  *y++ = a->a1;
43	  if (x->a1)
44	    *y++ = ':';
45	  *y = '\0';
46	}
47  return 0;
48}
49
50/* Verify tcc1 and tcc2 variables show up only in the TLS access sequences.  */
51/* { dg-final { scan-assembler "tcc1@" { target i?86-*-* x86_64-*-* } } } */
52/* { dg-final { scan-assembler "tcc2@" { target i?86-*-* x86_64-*-* } } } */
53/* { dg-final { scan-assembler-not "tcc1\[^@\]" { target i?86-*-* x86_64-*-* } } } */
54/* { dg-final { scan-assembler-not "tcc2\[^@\]" { target i?86-*-* x86_64-*-* } } } */
55