Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -7679,10 +7679,25 @@ void add_more_info_list(a_diagnostic_ptr dp,
a_diag_list_ptr dlp)
/*
Add the list of "more information" diagnostics specified by dlp to the
primary diagnostic dp.
primary diagnostic dp. An entry whose severity is es_none was suppressed
(by --diag_suppress or a diagnostic pragma for its error number): it is not
added, as a suppressed diagnostic is never displayed. The routines that write
a diagnostic have no severity to give such an entry.
*/
{
dp->more_info = *dlp;
a_diagnostic_ptr mi_dp;
a_diagnostic_ptr next_mi_dp;

clear_diag_list(&dp->more_info);
for (mi_dp = dlp->head; mi_dp != NULL; mi_dp = next_mi_dp) {
next_mi_dp = mi_dp->next;
mi_dp->next = NULL;
if (mi_dp->severity == es_none) {
free_diagnostic(mi_dp);
} else {
append_to_diag_list(&dp->more_info, mi_dp);
} /* if */
} /* for */
/* Clear the entries in the list passed in. */
clear_diag_list(dlp);
} /* add_more_info_list */
Expand Down
19 changes: 19 additions & 0 deletions src/pending_changes/gh-405-diag-suppress-note.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[GH #405]
A suppressed note of a constant-evaluation error no longer stops the front end

When constant evaluation fails, the front end attaches notes to the error
"expression must have a constant value": "shift count is too large" (#63),
"shift count is negative" (#62), "division by zero" (#39) and "integer
operation result is out of range" (#61) among them. A note takes the severity
of its own error number, so when --diag_suppress or a diag_suppress pragma
named the number of the note, the note had a severity that could not be
displayed and the front end stopped with an internal error (in the text
output; the SARIF output listed the suppressed note as a related location):

constexpr int z = 1 << 32;
// --diag_suppress=63: internal error: assertion failed:
// determine_severity_code: bad severity

A suppressed note is now left out of the diagnostic, as a suppressed
diagnostic always is, in the SARIF output too. The error itself is still
reported.
46 changes: 46 additions & 0 deletions tests/tests/changes/.gh-405.rto/default.1.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
fe_only -DTEST_NUMBER=1 --c++20 --diag_suppress=39,62,63 Test_name.c
"Test_name.c", line 26: error: expression must have a constant value
constexpr int shift_too_large = 1 << 32;
^

"Test_name.c", line 27: error: expression must have a constant value
constexpr int shift_negative = 1 << -1;
^

"Test_name.c", line 28: error: expression must have a constant value
constexpr int divide_by_zero = 10 / 0;
^

"Test_name.c", line 30: error: expression must have a constant value
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^

"Test_name.c", line 30: error: expression must have a constant value
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^

"Test_name.c", line 32: error: expression must have a constant value
int array_bound[1 << 32];
^

"Test_name.c", line 34: error: expression must have a constant value
static_assert((1 << 33) == 0);
^

"Test_name.c", line 37: error: expression must have a constant value
S<1 << 34> s;
^

"Test_name.c", line 26: warning: variable "shift_too_large" was declared but never referenced
constexpr int shift_too_large = 1 << 32;
^

"Test_name.c", line 27: warning: variable "shift_negative" was declared but never referenced
constexpr int shift_negative = 1 << -1;
^

"Test_name.c", line 28: warning: variable "divide_by_zero" was declared but never referenced
constexpr int divide_by_zero = 10 / 0;
^

8 errors detected in the compilation of "Test_name.c".
72 changes: 72 additions & 0 deletions tests/tests/changes/.gh-405.rto/default.2.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
fe_only -DTEST_NUMBER=2 --c++20 --diag_suppress=39 Test_name.c
"Test_name.c", line 26: error: expression must have a constant value
constexpr int shift_too_large = 1 << 32;
^
"Test_name.c", line 26: note: shift count is too large
constexpr int shift_too_large = 1 << 32;
^

"Test_name.c", line 27: error: expression must have a constant value
constexpr int shift_negative = 1 << -1;
^
"Test_name.c", line 27: note: shift count is negative
constexpr int shift_negative = 1 << -1;
^

"Test_name.c", line 28: error: expression must have a constant value
constexpr int divide_by_zero = 10 / 0;
^

"Test_name.c", line 30: error: expression must have a constant value
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^
"Test_name.c", line 30: note: shift count is too large
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^

"Test_name.c", line 30: error: expression must have a constant value
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^

"Test_name.c", line 32: error: expression must have a constant value
int array_bound[1 << 32];
^
"Test_name.c", line 32: note: shift count is too large
int array_bound[1 << 32];
^

"Test_name.c", line 34: error: expression must have a constant value
static_assert((1 << 33) == 0);
^
"Test_name.c", line 34: note: shift count is too large
static_assert((1 << 33) == 0);
^

"Test_name.c", line 37: error: expression must have a constant value
S<1 << 34> s;
^
"Test_name.c", line 37: note: shift count is too large
S<1 << 34> s;
^

"Test_name.c", line 42: warning: shift count is too large
return (x << 40) + (x / 0) + (x << -1);
^

"Test_name.c", line 42: warning: shift count is negative
return (x << 40) + (x / 0) + (x << -1);
^

"Test_name.c", line 26: warning: variable "shift_too_large" was declared but never referenced
constexpr int shift_too_large = 1 << 32;
^

"Test_name.c", line 27: warning: variable "shift_negative" was declared but never referenced
constexpr int shift_negative = 1 << -1;
^

"Test_name.c", line 28: warning: variable "divide_by_zero" was declared but never referenced
constexpr int divide_by_zero = 10 / 0;
^

8 errors detected in the compilation of "Test_name.c".
75 changes: 75 additions & 0 deletions tests/tests/changes/.gh-405.rto/default.3.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
fe_only -DTEST_NUMBER=3 --c++20 --diag_suppress=62 Test_name.c
"Test_name.c", line 26: error: expression must have a constant value
constexpr int shift_too_large = 1 << 32;
^
"Test_name.c", line 26: note: shift count is too large
constexpr int shift_too_large = 1 << 32;
^

"Test_name.c", line 27: error: expression must have a constant value
constexpr int shift_negative = 1 << -1;
^

"Test_name.c", line 28: error: expression must have a constant value
constexpr int divide_by_zero = 10 / 0;
^
"Test_name.c", line 28: note: division by zero
constexpr int divide_by_zero = 10 / 0;
^

"Test_name.c", line 30: error: expression must have a constant value
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^
"Test_name.c", line 30: note: shift count is too large
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^

"Test_name.c", line 30: error: expression must have a constant value
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^
"Test_name.c", line 30: note: division by zero
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^

"Test_name.c", line 32: error: expression must have a constant value
int array_bound[1 << 32];
^
"Test_name.c", line 32: note: shift count is too large
int array_bound[1 << 32];
^

"Test_name.c", line 34: error: expression must have a constant value
static_assert((1 << 33) == 0);
^
"Test_name.c", line 34: note: shift count is too large
static_assert((1 << 33) == 0);
^

"Test_name.c", line 37: error: expression must have a constant value
S<1 << 34> s;
^
"Test_name.c", line 37: note: shift count is too large
S<1 << 34> s;
^

"Test_name.c", line 42: warning: shift count is too large
return (x << 40) + (x / 0) + (x << -1);
^

"Test_name.c", line 42: warning: division by zero
return (x << 40) + (x / 0) + (x << -1);
^

"Test_name.c", line 26: warning: variable "shift_too_large" was declared but never referenced
constexpr int shift_too_large = 1 << 32;
^

"Test_name.c", line 27: warning: variable "shift_negative" was declared but never referenced
constexpr int shift_negative = 1 << -1;
^

"Test_name.c", line 28: warning: variable "divide_by_zero" was declared but never referenced
constexpr int divide_by_zero = 10 / 0;
^

8 errors detected in the compilation of "Test_name.c".
63 changes: 63 additions & 0 deletions tests/tests/changes/.gh-405.rto/default.4.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
fe_only -DTEST_NUMBER=4 --c++20 --diag_suppress=63 Test_name.c
"Test_name.c", line 26: error: expression must have a constant value
constexpr int shift_too_large = 1 << 32;
^

"Test_name.c", line 27: error: expression must have a constant value
constexpr int shift_negative = 1 << -1;
^
"Test_name.c", line 27: note: shift count is negative
constexpr int shift_negative = 1 << -1;
^

"Test_name.c", line 28: error: expression must have a constant value
constexpr int divide_by_zero = 10 / 0;
^
"Test_name.c", line 28: note: division by zero
constexpr int divide_by_zero = 10 / 0;
^

"Test_name.c", line 30: error: expression must have a constant value
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^

"Test_name.c", line 30: error: expression must have a constant value
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^
"Test_name.c", line 30: note: division by zero
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^

"Test_name.c", line 32: error: expression must have a constant value
int array_bound[1 << 32];
^

"Test_name.c", line 34: error: expression must have a constant value
static_assert((1 << 33) == 0);
^

"Test_name.c", line 37: error: expression must have a constant value
S<1 << 34> s;
^

"Test_name.c", line 42: warning: division by zero
return (x << 40) + (x / 0) + (x << -1);
^

"Test_name.c", line 42: warning: shift count is negative
return (x << 40) + (x / 0) + (x << -1);
^

"Test_name.c", line 26: warning: variable "shift_too_large" was declared but never referenced
constexpr int shift_too_large = 1 << 32;
^

"Test_name.c", line 27: warning: variable "shift_negative" was declared but never referenced
constexpr int shift_negative = 1 << -1;
^

"Test_name.c", line 28: warning: variable "divide_by_zero" was declared but never referenced
constexpr int divide_by_zero = 10 / 0;
^

8 errors detected in the compilation of "Test_name.c".
82 changes: 82 additions & 0 deletions tests/tests/changes/.gh-405.rto/default.5.1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
fe_only -DTEST_NUMBER=5 --c++20 Test_name.c
"Test_name.c", line 26: error: expression must have a constant value
constexpr int shift_too_large = 1 << 32;
^
"Test_name.c", line 26: note: shift count is too large
constexpr int shift_too_large = 1 << 32;
^

"Test_name.c", line 27: error: expression must have a constant value
constexpr int shift_negative = 1 << -1;
^
"Test_name.c", line 27: note: shift count is negative
constexpr int shift_negative = 1 << -1;
^

"Test_name.c", line 28: error: expression must have a constant value
constexpr int divide_by_zero = 10 / 0;
^
"Test_name.c", line 28: note: division by zero
constexpr int divide_by_zero = 10 / 0;
^

"Test_name.c", line 30: error: expression must have a constant value
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^
"Test_name.c", line 30: note: shift count is too large
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^

"Test_name.c", line 30: error: expression must have a constant value
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^
"Test_name.c", line 30: note: division by zero
enum { E_shift_too_large = 1 << 32, E_divide_by_zero = 10 / 0 };
^

"Test_name.c", line 32: error: expression must have a constant value
int array_bound[1 << 32];
^
"Test_name.c", line 32: note: shift count is too large
int array_bound[1 << 32];
^

"Test_name.c", line 34: error: expression must have a constant value
static_assert((1 << 33) == 0);
^
"Test_name.c", line 34: note: shift count is too large
static_assert((1 << 33) == 0);
^

"Test_name.c", line 37: error: expression must have a constant value
S<1 << 34> s;
^
"Test_name.c", line 37: note: shift count is too large
S<1 << 34> s;
^

"Test_name.c", line 42: warning: shift count is too large
return (x << 40) + (x / 0) + (x << -1);
^

"Test_name.c", line 42: warning: division by zero
return (x << 40) + (x / 0) + (x << -1);
^

"Test_name.c", line 42: warning: shift count is negative
return (x << 40) + (x / 0) + (x << -1);
^

"Test_name.c", line 26: warning: variable "shift_too_large" was declared but never referenced
constexpr int shift_too_large = 1 << 32;
^

"Test_name.c", line 27: warning: variable "shift_negative" was declared but never referenced
constexpr int shift_negative = 1 << -1;
^

"Test_name.c", line 28: warning: variable "divide_by_zero" was declared but never referenced
constexpr int divide_by_zero = 10 / 0;
^

8 errors detected in the compilation of "Test_name.c".
Loading
Loading