PR tree-optimization/81303
[official-gcc.git] / gcc / testsuite / gcc.dg / tree-ssa / pr20933.c
blobd32d6003e79c5dc7ea34748bed88ca791ce63621
1 /* { dg-do compile } */
2 /* { dg-options "-O2" } */
4 extern __SIZE_TYPE__ strlen (__const char *__s)
5 __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
6 extern char *strcpy (char *__restrict __dest, __const char *__restrict __src)
7 __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
8 extern char *getenv (__const char *__name) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
9 extern int access (__const char *__name, int __type) __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1)));
10 extern void * xmalloc (__SIZE_TYPE__) __attribute__ ((__malloc__));
12 static __inline__ const char *
13 try (const char *dir, const char *base)
15 if (base != 0)
16 return base;
17 if (dir != 0
18 && access (dir, 4 | 2 | 1) == 0)
19 return dir;
20 return 0;
23 static const char tmp[] = { '/', 't', 'm', 'p', 0 };
24 static const char usrtmp[] =
25 { '/', 'u', 's', 'r', '/', 't', 'm', 'p', 0 };
26 static const char vartmp[] =
27 { '/', 'v', 'a', 'r', '/', 't', 'm', 'p', 0 };
29 static char *memoized_tmpdir;
30 char *
31 choose_tmpdir (void)
33 const char *base = 0;
34 char *tmpdir;
35 unsigned int len;
37 if (memoized_tmpdir)
38 return memoized_tmpdir;
40 base = try (getenv ("TMPDIR"), base);
41 base = try (getenv ("TMP"), base);
42 base = try (getenv ("TEMP"), base);
45 base = try ("/tmp", base);
49 base = try (vartmp, base);
50 base = try (usrtmp, base);
51 base = try (tmp, base);
54 if (base == 0)
55 base = ".";
59 len = strlen (base);
60 tmpdir = xmalloc (len + 2);
61 strcpy (tmpdir, base);
62 /* Alias analysis was associating read-only memory tags to pointers
63 that are not read-only. We would then not issue any V_MAY_DEF in
64 this store. */
65 tmpdir[len] = '/';
66 tmpdir[len+1] = '\0';
68 memoized_tmpdir = tmpdir;
69 return tmpdir;