Skip to content

Commit dc73b29

Browse files
mborlanddaveedvdv-nvidia
authored andcommitted
Leave a suppressed note out of its error [GH #405]
1 parent 85e38dc commit dc73b29

13 files changed

Lines changed: 438 additions & 2 deletions

‎src/error.c‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7679,10 +7679,25 @@ void add_more_info_list(a_diagnostic_ptr dp,
76797679
a_diag_list_ptr dlp)
76807680
/*
76817681
Add the list of "more information" diagnostics specified by dlp to the
7682-
primary diagnostic dp.
7682+
primary diagnostic dp. An entry whose severity is es_none was suppressed
7683+
(by --diag_suppress or a diagnostic pragma for its error number): it is not
7684+
added, as a suppressed diagnostic is never displayed. The routines that write
7685+
a diagnostic have no severity to give such an entry.
76837686
*/
76847687
{
7685-
dp->more_info = *dlp;
7688+
a_diagnostic_ptr mi_dp;
7689+
a_diagnostic_ptr next_mi_dp;
7690+
7691+
clear_diag_list(&dp->more_info);
7692+
for (mi_dp = dlp->head; mi_dp != NULL; mi_dp = next_mi_dp) {
7693+
next_mi_dp = mi_dp->next;
7694+
mi_dp->next = NULL;
7695+
if (mi_dp->severity == es_none) {
7696+
free_diagnostic(mi_dp);
7697+
} else {
7698+
append_to_diag_list(&dp->more_info, mi_dp);
7699+
} /* if */
7700+
} /* for */
76867701
/* Clear the entries in the list passed in. */
76877702
clear_diag_list(dlp);
76887703
} /* add_more_info_list */
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[GH #405]
2+
A suppressed note of a constant-evaluation error no longer stops the front end
3+
4+
When constant evaluation fails, the front end attaches notes to the error
5+
"expression must have a constant value": "shift count is too large" (#63),
6+
"shift count is negative" (#62), "division by zero" (#39) and "integer
7+
operation result is out of range" (#61) among them. A note takes the severity
8+
of its own error number, so when --diag_suppress or a diag_suppress pragma
9+
named the number of the note, the note had a severity that could not be
10+
displayed and the front end stopped with an internal error (in the text
11+
output; the SARIF output listed the suppressed note as a related location):
12+
13+
constexpr int z = 1 << 32;
14+
// --diag_suppress=63: internal error: assertion failed:
15+
// determine_severity_code: bad severity
16+
17+
A suppressed note is now left out of the diagnostic, as a suppressed
18+
diagnostic always is, in the SARIF output too. The error itself is still
19+
reported.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
fe_only -DTEST_NUMBER=1 --c++20 --diag_suppress=39,62,63 Test_name.c
2+
"Test_name.c", line 27: error: expression must have a constant value
3+
constexpr int shift_too_large = 1 << 32;
4+
^
5+
6+
"Test_name.c", line 28: error: expression must have a constant value
7+
constexpr int shift_negative = 1 << -1;
8+
^
9+
10+
"Test_name.c", line 29: error: expression must have a constant value
11+
constexpr int divide_by_zero = 10 / 0;
12+
^
13+
14+
"Test_name.c", line 31: error: expression must have a constant value
15+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
16+
^
17+
18+
"Test_name.c", line 31: error: expression must have a constant value
19+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
20+
^
21+
22+
"Test_name.c", line 33: error: expression must have a constant value
23+
int array_bound[1 << 32];
24+
^
25+
26+
"Test_name.c", line 35: error: expression must have a constant value
27+
static_assert((1 << 33) == 0);
28+
^
29+
30+
"Test_name.c", line 38: error: expression must have a constant value
31+
S<1 << 34> s;
32+
^
33+
34+
"Test_name.c", line 27: warning: variable "shift_too_large" was declared but never referenced
35+
constexpr int shift_too_large = 1 << 32;
36+
^
37+
38+
"Test_name.c", line 28: warning: variable "shift_negative" was declared but never referenced
39+
constexpr int shift_negative = 1 << -1;
40+
^
41+
42+
"Test_name.c", line 29: warning: variable "divide_by_zero" was declared but never referenced
43+
constexpr int divide_by_zero = 10 / 0;
44+
^
45+
46+
8 errors detected in the compilation of "Test_name.c".
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Matches for "\A(?![\s\S]*internal error)":
2+
<-----------------------------------------------------------------------------
3+
4+
----------------------------------------------------------------------------->
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
fe_only -DTEST_NUMBER=2 --c++20 --diag_suppress=39 Test_name.c
2+
"Test_name.c", line 27: error: expression must have a constant value
3+
constexpr int shift_too_large = 1 << 32;
4+
^
5+
"Test_name.c", line 27: note: shift count is too large
6+
constexpr int shift_too_large = 1 << 32;
7+
^
8+
9+
"Test_name.c", line 28: error: expression must have a constant value
10+
constexpr int shift_negative = 1 << -1;
11+
^
12+
"Test_name.c", line 28: note: shift count is negative
13+
constexpr int shift_negative = 1 << -1;
14+
^
15+
16+
"Test_name.c", line 29: error: expression must have a constant value
17+
constexpr int divide_by_zero = 10 / 0;
18+
^
19+
20+
"Test_name.c", line 31: error: expression must have a constant value
21+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
22+
^
23+
"Test_name.c", line 31: note: shift count is too large
24+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
25+
^
26+
27+
"Test_name.c", line 31: error: expression must have a constant value
28+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
29+
^
30+
31+
"Test_name.c", line 33: error: expression must have a constant value
32+
int array_bound[1 << 32];
33+
^
34+
"Test_name.c", line 33: note: shift count is too large
35+
int array_bound[1 << 32];
36+
^
37+
38+
"Test_name.c", line 35: error: expression must have a constant value
39+
static_assert((1 << 33) == 0);
40+
^
41+
"Test_name.c", line 35: note: shift count is too large
42+
static_assert((1 << 33) == 0);
43+
^
44+
45+
"Test_name.c", line 38: error: expression must have a constant value
46+
S<1 << 34> s;
47+
^
48+
"Test_name.c", line 38: note: shift count is too large
49+
S<1 << 34> s;
50+
^
51+
52+
"Test_name.c", line 43: warning: shift count is too large
53+
return (x << 40) + (x / 0) + (x << -1);
54+
^
55+
56+
"Test_name.c", line 43: warning: shift count is negative
57+
return (x << 40) + (x / 0) + (x << -1);
58+
^
59+
60+
"Test_name.c", line 27: warning: variable "shift_too_large" was declared but never referenced
61+
constexpr int shift_too_large = 1 << 32;
62+
^
63+
64+
"Test_name.c", line 28: warning: variable "shift_negative" was declared but never referenced
65+
constexpr int shift_negative = 1 << -1;
66+
^
67+
68+
"Test_name.c", line 29: warning: variable "divide_by_zero" was declared but never referenced
69+
constexpr int divide_by_zero = 10 / 0;
70+
^
71+
72+
8 errors detected in the compilation of "Test_name.c".
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Matches for "\A(?![\s\S]*internal error)":
2+
<-----------------------------------------------------------------------------
3+
4+
----------------------------------------------------------------------------->
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
fe_only -DTEST_NUMBER=3 --c++20 --diag_suppress=62 Test_name.c
2+
"Test_name.c", line 27: error: expression must have a constant value
3+
constexpr int shift_too_large = 1 << 32;
4+
^
5+
"Test_name.c", line 27: note: shift count is too large
6+
constexpr int shift_too_large = 1 << 32;
7+
^
8+
9+
"Test_name.c", line 28: error: expression must have a constant value
10+
constexpr int shift_negative = 1 << -1;
11+
^
12+
13+
"Test_name.c", line 29: error: expression must have a constant value
14+
constexpr int divide_by_zero = 10 / 0;
15+
^
16+
"Test_name.c", line 29: note: division by zero
17+
constexpr int divide_by_zero = 10 / 0;
18+
^
19+
20+
"Test_name.c", line 31: error: expression must have a constant value
21+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
22+
^
23+
"Test_name.c", line 31: note: shift count is too large
24+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
25+
^
26+
27+
"Test_name.c", line 31: error: expression must have a constant value
28+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
29+
^
30+
"Test_name.c", line 31: note: division by zero
31+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
32+
^
33+
34+
"Test_name.c", line 33: error: expression must have a constant value
35+
int array_bound[1 << 32];
36+
^
37+
"Test_name.c", line 33: note: shift count is too large
38+
int array_bound[1 << 32];
39+
^
40+
41+
"Test_name.c", line 35: error: expression must have a constant value
42+
static_assert((1 << 33) == 0);
43+
^
44+
"Test_name.c", line 35: note: shift count is too large
45+
static_assert((1 << 33) == 0);
46+
^
47+
48+
"Test_name.c", line 38: error: expression must have a constant value
49+
S<1 << 34> s;
50+
^
51+
"Test_name.c", line 38: note: shift count is too large
52+
S<1 << 34> s;
53+
^
54+
55+
"Test_name.c", line 43: warning: shift count is too large
56+
return (x << 40) + (x / 0) + (x << -1);
57+
^
58+
59+
"Test_name.c", line 43: warning: division by zero
60+
return (x << 40) + (x / 0) + (x << -1);
61+
^
62+
63+
"Test_name.c", line 27: warning: variable "shift_too_large" was declared but never referenced
64+
constexpr int shift_too_large = 1 << 32;
65+
^
66+
67+
"Test_name.c", line 28: warning: variable "shift_negative" was declared but never referenced
68+
constexpr int shift_negative = 1 << -1;
69+
^
70+
71+
"Test_name.c", line 29: warning: variable "divide_by_zero" was declared but never referenced
72+
constexpr int divide_by_zero = 10 / 0;
73+
^
74+
75+
8 errors detected in the compilation of "Test_name.c".
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Matches for "\A(?![\s\S]*internal error)":
2+
<-----------------------------------------------------------------------------
3+
4+
----------------------------------------------------------------------------->
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
fe_only -DTEST_NUMBER=4 --c++20 --diag_suppress=63 Test_name.c
2+
"Test_name.c", line 27: error: expression must have a constant value
3+
constexpr int shift_too_large = 1 << 32;
4+
^
5+
6+
"Test_name.c", line 28: error: expression must have a constant value
7+
constexpr int shift_negative = 1 << -1;
8+
^
9+
"Test_name.c", line 28: note: shift count is negative
10+
constexpr int shift_negative = 1 << -1;
11+
^
12+
13+
"Test_name.c", line 29: error: expression must have a constant value
14+
constexpr int divide_by_zero = 10 / 0;
15+
^
16+
"Test_name.c", line 29: note: division by zero
17+
constexpr int divide_by_zero = 10 / 0;
18+
^
19+
20+
"Test_name.c", line 31: error: expression must have a constant value
21+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
22+
^
23+
24+
"Test_name.c", line 31: error: expression must have a constant value
25+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
26+
^
27+
"Test_name.c", line 31: note: division by zero
28+
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
29+
^
30+
31+
"Test_name.c", line 33: error: expression must have a constant value
32+
int array_bound[1 << 32];
33+
^
34+
35+
"Test_name.c", line 35: error: expression must have a constant value
36+
static_assert((1 << 33) == 0);
37+
^
38+
39+
"Test_name.c", line 38: error: expression must have a constant value
40+
S<1 << 34> s;
41+
^
42+
43+
"Test_name.c", line 43: warning: division by zero
44+
return (x << 40) + (x / 0) + (x << -1);
45+
^
46+
47+
"Test_name.c", line 43: warning: shift count is negative
48+
return (x << 40) + (x / 0) + (x << -1);
49+
^
50+
51+
"Test_name.c", line 27: warning: variable "shift_too_large" was declared but never referenced
52+
constexpr int shift_too_large = 1 << 32;
53+
^
54+
55+
"Test_name.c", line 28: warning: variable "shift_negative" was declared but never referenced
56+
constexpr int shift_negative = 1 << -1;
57+
^
58+
59+
"Test_name.c", line 29: warning: variable "divide_by_zero" was declared but never referenced
60+
constexpr int divide_by_zero = 10 / 0;
61+
^
62+
63+
8 errors detected in the compilation of "Test_name.c".
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Matches for "\A(?![\s\S]*internal error)":
2+
<-----------------------------------------------------------------------------
3+
4+
----------------------------------------------------------------------------->

0 commit comments

Comments
 (0)