## Mercurial > hg > CbC > GCC_original

### annotate gcc/testsuite/gcc.dg/Warray-bounds-61.c @ 19:2b5abeee2509 default tip

Find changesets by keywords (author, files, the commit message), revision
number or hash, or revset expression.

update gcc11

author | anatofuz |
---|---|

date | Mon, 25 May 2020 07:50:57 +0900 |

parents | |

children |

rev | line source |
---|---|

19 | 1 /* PR middle-end/94940 - spurious -Warray-bounds for a zero length array |

2 member of union | |

3 { dg-do compile } | |

4 { dg-options "-O2 -Wall" } */ | |

5 | |

6 extern int n; | |

7 | |

8 extern union Ua3_a0 { | |

9 int a3[3]; | |

10 int a2[2]; // can only alias a3[0 - 2] | |

11 int a1[1]; // can alias all of the union | |

12 int a0[0]; // ditto | |

13 } ua3_a0; | |

14 | |

15 void test_ua3_ua0_a0 (int i) | |

16 { | |

17 ua3_a0.a0[0] = 0; // { dg-bogus "\\\[-Warray-bounds" } | |

18 ua3_a0.a0[1] = 0; // { dg-bogus "\\\[-Warray-bounds" } | |

19 ua3_a0.a0[2] = 0; // { dg-bogus "\\\[-Warray-bounds" } | |

20 ua3_a0.a0[3] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

21 ua3_a0.a0[4] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

22 ua3_a0.a0[i] = 0; // { dg-bogus "\\\[-Warray-bounds" } | |

23 | |

24 if (i < __LINE__) | |

25 i = 5; | |

26 ua3_a0.a0[i] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

27 | |

28 if (i > -1) | |

29 i = -1; | |

30 ua3_a0.a0[i] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

31 } | |

32 | |

33 void test_ua3_ua0_a1 (int i) | |

34 { | |

35 /* Abusing one-element array members the same way as those of | |

36 length zero is discouraged but so far acceted without warnings. | |

37 This should change at some point. */ | |

38 | |

39 ua3_a0.a1[0] = 0; | |

40 ua3_a0.a1[1] = 0; | |

41 ua3_a0.a1[2] = 0; | |

42 ua3_a0.a1[3] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

43 ua3_a0.a1[i] = 0; | |

44 | |

45 if (i > -1) | |

46 i = -1; | |

47 ua3_a0.a1[i] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

48 | |

49 if (i < 7) | |

50 i = 7; | |

51 ua3_a0.a1[i] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

52 } | |

53 | |

54 void test_ua3_ua0_a2 (int i) | |

55 { | |

56 ua3_a0.a2[0] = 0; | |

57 ua3_a0.a2[1] = 0; | |

58 ua3_a0.a2[2] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

59 ua3_a0.a2[i] = 0; | |

60 | |

61 if (i < __LINE__) | |

62 i = __LINE__; | |

63 ua3_a0.a2[i] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

64 | |

65 if (i > -1) | |

66 i = -1; | |

67 ua3_a0.a2[i] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

68 } | |

69 | |

70 | |

71 extern union Ua2_a3 { | |

72 int a2[2]; // can only alias a3[0 - 1] | |

73 int a3[3]; | |

74 } ua2_a3; | |

75 | |

76 void test_ua2_ua3 (int i) | |

77 { | |

78 ua2_a3.a2[0] = 0; // { dg-bogus "\\\[-Warray-bounds" } | |

79 ua2_a3.a2[1] = 0; // { dg-bogus "\\\[-Warray-bounds" } | |

80 ua2_a3.a2[2] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

81 ua2_a3.a2[i] = 0; | |

82 | |

83 if (i < __LINE__) | |

84 i = __LINE__; | |

85 ua2_a3.a2[i] = 0; // { dg-warning "\\\[-Warray-bounds" } | |

86 } | |

87 | |

88 | |

89 extern struct SUa2_a0 { | |

90 union Ua2_a0 { | |

91 int a2[2]; | |

92 int a0[0]; | |

93 } u; | |

94 } sua2_a0; | |

95 | |

96 void test_sua2_sua0 (int i) | |

97 { | |

98 n += sua2_a0.u.a0[0]; | |

99 n += sua2_a0.u.a0[1]; | |

100 n += sua2_a0.u.a0[2]; // { dg-warning "\\\[-Warray-bounds" } | |

101 n += sua2_a0.u.a0[i]; | |

102 | |

103 if (i < __LINE__) | |

104 i = __LINE__; | |

105 n += sua2_a0.u.a0[i]; // { dg-warning "\\\[-Warray-bounds" } | |

106 } | |

107 | |

108 void test_sua2_sua0_ptr (int i) | |

109 { | |

110 union Ua2_a0 *p = &sua2_a0.u; | |

111 | |

112 n += p->a0[0]; | |

113 n += p->a0[1]; | |

114 n += p->a0[2]; // { dg-warning "\\\[-Warray-bounds" } | |

115 n += p->a0[i]; | |

116 } | |

117 | |

118 | |

119 extern struct SUSa3_a0 { | |

120 union USa3_a0 { | |

121 struct { | |

122 int a3[3]; | |

123 } s; | |

124 int a2[2]; // can alias s.a3[0 - 2] | |

125 int a1[1]; // can alias s.a3[0 - 2] | |

126 int a0[0]; // can alias s.a3[0] | |

127 } u; | |

128 } susa3_ua0; | |

129 | |

130 void test_susa3_sua0 (int i, int j) | |

131 { | |

132 n += susa3_ua0.u.a0[0]; | |

133 n += susa3_ua0.u.a0[1]; | |

134 n += susa3_ua0.u.a0[2]; | |

135 n += susa3_ua0.u.a0[3]; // { dg-warning "\\\[-Warray-bounds" } | |

136 } | |

137 | |

138 void test_susa3_sua0_ptr (int i, int j) | |

139 { | |

140 union USa3_a0 *p = &susa3_ua0.u; | |

141 n += p->a0[0]; | |

142 n += p->a0[1]; | |

143 n += p->a0[2]; | |

144 n += p->a0[3]; // { dg-warning "\\\[-Warray-bounds" } | |

145 } | |

146 | |

147 void test_susa3_sua1 (int i) | |

148 { | |

149 n += susa3_ua0.u.a1[0]; | |

150 n += susa3_ua0.u.a1[1]; | |

151 n += susa3_ua0.u.a1[2]; | |

152 n += susa3_ua0.u.a1[3]; // { dg-warning "\\\[-Warray-bounds" } | |

153 | |

154 if (i < __LINE__) | |

155 i = __LINE__; | |

156 n += susa3_ua0.u.a1[i]; // { dg-warning "\\\[-Warray-bounds" } | |

157 } | |

158 | |

159 void test_susa3_sua2 (void) | |

160 { | |

161 n += susa3_ua0.u.a2[0]; | |

162 n += susa3_ua0.u.a2[1]; | |

163 n += susa3_ua0.u.a2[2]; // { dg-warning "\\\[-Warray-bounds" } | |

164 n += susa3_ua0.u.a2[3]; // { dg-warning "\\\[-Warray-bounds" } | |

165 } | |

166 | |

167 | |

168 extern struct { | |

169 union { | |

170 struct { | |

171 int a3[3]; | |

172 } s1; | |

173 struct { | |

174 int a0[0]; | |

175 } s2; | |

176 } u; | |

177 } susa3_usa0; | |

178 | |

179 void test_susi3_susi0 (int i) | |

180 { | |

181 n += susa3_usa0.u.s2.a0[0]; | |

182 n += susa3_usa0.u.s2.a0[1]; | |

183 n += susa3_usa0.u.s2.a0[2]; | |

184 n += susa3_usa0.u.s2.a0[3]; // { dg-warning "\\\[-Warray-bounds" } | |

185 n += susa3_usa0.u.s2.a0[i]; | |

186 | |

187 if (i < __LINE__) | |

188 i = __LINE__; | |

189 n += susa3_usa0.u.s2.a0[i]; // { dg-warning "\\\[-Warray-bounds" } | |

190 } |