File: strlenopt-57.c

package info (click to toggle)
gcc-riscv64-unknown-elf 8.3.0.2019.08%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 680,956 kB
  • sloc: ansic: 3,237,715; cpp: 896,882; ada: 772,854; f90: 144,254; asm: 68,788; makefile: 67,456; sh: 29,743; exp: 28,045; objc: 15,273; fortran: 11,885; python: 7,369; pascal: 5,375; awk: 3,725; perl: 2,872; yacc: 316; xml: 311; ml: 285; lex: 198; haskell: 122
file content (49 lines) | stat: -rw-r--r-- 1,292 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* PR tree-optimization/86914 - wrong code with strlen() of poor-man's
   flexible array member plus offset
   { dg-do compile }
   { dg-options "-O2 -Wall -fdump-tree-optimized" } */

#include "strlenopt.h"

struct A0 { char i, a[0]; };
struct A1 { char i, a[1]; };
struct A9 { char i, a[9]; };
struct Ax { char i, a[]; };

extern int a[];

extern struct A0 a0;
extern struct A1 a1;
extern struct A9 a9;
extern struct Ax ax;

void test_var_flexarray_cst_off (void)
{
  /* Use arbitrary constants greater than 16 in case GCC ever starts
     unrolling strlen() calls with small array arguments.  */
  a[0] = 17 < strlen (a0.a + 1);
  a[1] = 19 < strlen (a1.a + 1);
  a[2] = 23 < strlen (a9.a + 9);
  a[3] = 29 < strlen (ax.a + 3);
}

void test_ptr_flexarray_cst_off (struct A0 *p0, struct A1 *p1,
				 struct A9 *p9, struct Ax *px)
{
  a[0] = 17 < strlen (p0->a + 1);
  a[1] = 19 < strlen (p1->a + 1);
  a[2] = 23 < strlen (p9->a + 9);
  a[3] = 29 < strlen (px->a + 3);
}

void test_ptr_flexarray_var_off (struct A0 *p0, struct A1 *p1,
				 struct A9 *p9, struct Ax *px,
				 int i)
{
  a[0] = 17 < strlen (p0->a + i);
  a[1] = 19 < strlen (p1->a + i);
  a[2] = 23 < strlen (p9->a + i);
  a[3] = 29 < strlen (px->a + i);
}

/* { dg-final { scan-tree-dump-times "strlen" 12 "optimized" } } */