From c87875a09ded4816401247b7051d6d87d5d7662a Mon Sep 17 00:00:00 2001 From: Mohit Mishra Date: Sat, 3 Oct 2026 03:28:16 +0530 Subject: [PATCH 1/2] diagnose an empty diag_suppress pragma without reading past it, fix for [GH #19] --- src/Changes | 15 +++++++ src/error.c | 7 ++- tests/tests/changes/.GH19.rto/default.1.1.txt | 33 ++++++++++++++ tests/tests/changes/GH19.sft.cpp | 43 +++++++++++++++++++ 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 tests/tests/changes/.GH19.rto/default.1.1.txt create mode 100644 tests/tests/changes/GH19.sft.cpp diff --git a/src/Changes b/src/Changes index 6dc5a67ff3..9ae0809f1a 100644 --- a/src/Changes +++ b/src/Changes @@ -11,6 +11,21 @@ example, with --clang_version 230100: #pragma clang diagnostic push was previously recorded as "clangdiagnostic push". That is now fixed. +10/3/26 [GH #19] +Assertion failure on an empty diag_suppress pragma + +A diag_* pragma with no arguments, or with a trailing comma, diagnosed the +missing argument and then read past the end of the directive. That consumed +the following source and could assert in process_immediate_pragmas. For +example: + + #pragma diagnostic push + #pragma diag_suppress + int f() { int a; return a; } + #pragma diagnostic pop + +The missing argument is still diagnosed, and the code after the pragma is +parsed. 10/1/26 [GH #197] diff --git a/src/error.c b/src/error.c index af3f4a5e3e..769021b445 100644 --- a/src/error.c +++ b/src/error.c @@ -8176,8 +8176,11 @@ as _Pragma that are not parsed except during instantiations). err = TRUE; pos_warning(ec_exp_error_argument, &pos_curr_token); } /* if */ - /* Bypass the token just processed. */ - (void)get_token(); + /* Advance past the argument. Do not consume tok_end_of_source here. + Fetching that terminator already popped the pragma token cache, so + another get_token would read the source that follows the pragma and + could queue later pragmas while this one is still being processed. */ + if (curr_token != tok_end_of_source) (void)get_token(); if (curr_token != tok_comma && curr_token != tok_end_of_source) { pos_warning(ec_exp_comma, &pos_curr_token); error_in_pragma = TRUE; diff --git a/tests/tests/changes/.GH19.rto/default.1.1.txt b/tests/tests/changes/.GH19.rto/default.1.1.txt new file mode 100644 index 0000000000..ca8a287d0b --- /dev/null +++ b/tests/tests/changes/.GH19.rto/default.1.1.txt @@ -0,0 +1,33 @@ +fe_only -DTEST_NUMBER=1 Test_name.c +"Test_name.c", line 9: warning: expected an error number or error tag + #pragma diag_suppress + ^ + +"Test_name.c", line 13: warning: variable "a" is used before its value is set + return a; + ^ + +"Test_name.c", line 20: warning: variable "b" is used before its value is set + return b; + ^ + +"Test_name.c", line 23: warning: expected an error number or error tag + #pragma diag_suppress = + ^ + +"Test_name.c", line 27: warning: variable "c" is used before its value is set + return c; + ^ + +"Test_name.c", line 30: warning: expected an error number or error tag + #pragma diag_suppress 123, + ^ + +"Test_name.c", line 34: warning: variable "d" is used before its value is set + return d; + ^ + +"Test_name.c", line 41: warning: variable "e" is used before its value is set + return e; + ^ + diff --git a/tests/tests/changes/GH19.sft.cpp b/tests/tests/changes/GH19.sft.cpp new file mode 100644 index 0000000000..fd29bbb763 --- /dev/null +++ b/tests/tests/changes/GH19.sft.cpp @@ -0,0 +1,43 @@ +//type:fp +//remark:[GH #19] Assertion failure on an empty diag_suppress pragma +// 10/3/26 [GH #19] +// +// An empty #pragma diag_suppress used to read past the directive and assert +// in process_immediate_pragmas. The functions below must still be compiled. + +#pragma diagnostic push +#pragma diag_suppress +int get_free_no_warn() +{ + int a; + return a; +} +#pragma diagnostic pop + +int get_free_warn() +{ + int b; + return b; +} + +#pragma diag_suppress = +int after_bare_equals() +{ + int c; + return c; +} + +#pragma diag_suppress 123, +int after_trailing_comma() +{ + int d; + return d; +} + +#pragma diag_suppress = 123 +int after_valid_pragma() +{ + int e; + return e; +} +#pragma diag_default 123 From f032b04d5354839a0aa102b2c590d07127a86fb5 Mon Sep 17 00:00:00 2001 From: Mohit Mishra Date: Tue, 6 Oct 2026 01:40:39 +0530 Subject: [PATCH 2/2] Place the GH #19 Changes entry under the GH #213 note. [GH #19] --- src/Changes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Changes b/src/Changes index 9ae0809f1a..077ef4ac1a 100644 --- a/src/Changes +++ b/src/Changes @@ -11,6 +11,8 @@ example, with --clang_version 230100: #pragma clang diagnostic push was previously recorded as "clangdiagnostic push". That is now fixed. + + 10/3/26 [GH #19] Assertion failure on an empty diag_suppress pragma