File: Wmisleading-indentation-3.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A8-2019-q3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 571,828 kB
  • sloc: ansic: 2,937,651; cpp: 881,644; ada: 597,189; makefile: 65,528; asm: 56,499; xml: 46,621; exp: 24,747; sh: 19,684; python: 7,256; pascal: 4,370; awk: 3,497; perl: 2,695; yacc: 316; ml: 285; f90: 234; lex: 198; objc: 194; haskell: 119
file content (82 lines) | stat: -rw-r--r-- 2,301 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* Verify -Wmisleading-indentation with source-printing.
   This is a subset of Wmisleading-indentation.c.  */

/* { dg-options "-Wmisleading-indentation -fdiagnostics-show-caret" } */
/* { dg-do compile } */

extern int foo (int);
extern int bar (int, int);
extern int flagA;
extern int flagB;
extern int flagC;
extern int flagD;

void
fn_5 (double *a, double *b, double *sum, double *prod)
{
  int i = 0;
  for (i = 0; i < 10; i++) /* { dg-warning "3: this 'for' clause does not guard..." } */
    sum[i] = a[i] * b[i];
    prod[i] = a[i] * b[i]; /* { dg-message "5: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'" } */
/* { dg-begin-multiline-output "" }
   for (i = 0; i < 10; i++)
   ^~~
   { dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
     prod[i] = a[i] * b[i];
     ^~~~
   { dg-end-multiline-output "" } */
}

/* Based on CVE-2014-1266 aka "goto fail" */
int fn_6 (int a, int b, int c)
{
	int err;

	/* ... */
	if ((err = foo (a)) != 0)
		goto fail;
	if ((err = foo (b)) != 0) /* { dg-message "2: this 'if' clause does not guard..." } */
		goto fail;
		goto fail; /* { dg-message "3: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'" } */
	if ((err = foo (c)) != 0)
		goto fail;
	/* ... */

/* { dg-begin-multiline-output "" }
  if ((err = foo (b)) != 0)
  ^~
   { dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
   goto fail;
   ^~~~
   { dg-end-multiline-output "" } */

fail:
	return err;
}

#define FOR_EACH(VAR, START, STOP) \
  for ((VAR) = (START); (VAR) < (STOP); (VAR++)) /* { dg-warning "3: this 'for' clause does not guard..." } */

void fn_14 (void)
{
  int i;
  FOR_EACH (i, 0, 10) /* { dg-message "in expansion of macro .FOR_EACH." } */
    foo (i);
    bar (i, i); /* { dg-message "5: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'" } */

/* { dg-begin-multiline-output "" }
   for ((VAR) = (START); (VAR) < (STOP); (VAR++))
   ^~~
   { dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
   FOR_EACH (i, 0, 10)
   ^~~~~~~~
   { dg-end-multiline-output "" } */
/* { dg-begin-multiline-output "" }
     bar (i, i);
     ^~~
   { dg-end-multiline-output "" } */
}
#undef FOR_EACH