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
1 change: 1 addition & 0 deletions src/il_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -6619,6 +6619,7 @@ enum a_gcc_pragma_kind : a_byte {
gcc_pk_push_options, /* #pragma GCC push_options */
gcc_pk_pop_options, /* #pragma GCC pop_options */
gcc_pk_reset_options, /* #pragma GCC reset_options */
gcc_pk_diagnostic, /* #pragma GCC diagnostic ... */
gcc_pk_last
};

Expand Down
21 changes: 21 additions & 0 deletions src/pending_changes/gh-182-gcc-diagnostic-pragmas.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//allowed_words: Wunused
[GH #182]
"GCC diagnostic" pragmas

The "GCC diagnostic" pragmas were not recognized, so in GNU modes each one
was given an "unrecognized GCC pragma" warning. For example, with --g++:

#pragma GCC diagnostic push // Previously warned about.
#pragma GCC diagnostic ignored "-Wunused-parameter"
int f(int unused) { return 0; }
#pragma GCC diagnostic pop

This is now fixed. The "error", "warning", and "ignored" forms, the "push"
and "pop" forms (when emulating clang or GCC 4.6 or later), the
"ignored_attributes" form (when emulating GCC 12 or later), and the "fatal"
form (when emulating clang) are accepted without a warning, to match the
behavior of those compilers. A missing or malformed option string is still
diagnosed. The pragmas have no effect on the front end's own diagnostics.
They are still passed through to the code generated by the C++-generating
back end, but they are now omitted from the code generated by the
C-generating back end, which cannot place them at their source positions.
44 changes: 44 additions & 0 deletions src/preproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4287,6 +4287,48 @@ kind indicates which of the above is being processed.
} /* process_gnu_options_pragma */


static a_boolean process_gnu_diagnostic_pragma(a_pending_pragma_ptr ppp)
/*
Handle "#pragma GCC diagnostic push/pop" (GCC 4.6 and later, and clang) and
"#pragma GCC diagnostic kind "option"", where kind is "error", "warning",
"ignored", "fatal" (clang only), or "ignored_attributes" (GCC 12 and later).
The pragmas are only accepted: they do not affect the front end's own
diagnostics, and (as in GCC) trailing text is ignored. Return FALSE if the
form is not recognized by the compiler being emulated.
*/
{
a_boolean recognized = FALSE;

/* Skip the "diagnostic" identifier. */
(void)get_token();
if (curr_token == tok_identifier) {
a_const_char *str = locator_for_curr_id.symbol_header->identifier;
if ((clang_mode || gnu_version >= 40600) &&
(strcmp(str, "push") == 0 || strcmp(str, "pop") == 0)) {
recognized = TRUE;
} else if (strcmp(str, "error") == 0 ||
strcmp(str, "warning") == 0 ||
strcmp(str, "ignored") == 0 ||
(clang_mode && strcmp(str, "fatal") == 0) ||
(gnu_version >= 120000 &&
strcmp(str, "ignored_attributes") == 0)) {
recognized = TRUE;
(void)get_token();
if (curr_token != tok_string_literal ||
!is_normal_character_kind(const_for_curr_token.character_kind)) {
/* The option (or attribute list) is missing. Only a string literal
of plain char type is accepted. */
pos_warning(ec_exp_string_literal, &error_position);
} /* if */
} /* if */
} /* if */
if (recognized) {
ppp->variant.gcc.kind = (a_gcc_pragma_kind)gcc_pk_diagnostic;
} /* if */
return recognized;
} /* process_gnu_diagnostic_pragma */


void gcc_pragma(a_pending_pragma_ptr ppp)
/*
Process a "#pragma GCC ..." construct.
Expand Down Expand Up @@ -4318,6 +4360,8 @@ Process a "#pragma GCC ..." construct.
process_gnu_options_pragma(ppp, (a_gcc_pragma_kind)gcc_pk_pop_options);
} else if (gnu_version >= 40400 && strcmp(str, "reset_options") == 0) {
process_gnu_options_pragma(ppp, (a_gcc_pragma_kind)gcc_pk_reset_options);
} else if (strcmp(str, "diagnostic") == 0) {
recognized = process_gnu_diagnostic_pragma(ppp);
#if GNU_VECTOR_TYPES_ALLOWED && BUILTIN_FUNCTIONS_ENABLED
} else if (target_is_arm_based() && target_is_64_bits() &&
strcmp(str, "aarch64") == 0) {
Expand Down
8 changes: 0 additions & 8 deletions tests/tests/changes/.EDGcpfe16990.rto/default.1.1.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
fe_only -DTEST_NUMBER=1 --g++ Test_name.c
"Test_name.c", line 13: warning: unrecognized GCC pragma
_Pragma ("GCC diagnostic push")
^

"Test_name.c", line 14: warning: unrecognized GCC pragma
_Pragma ("GCC diagnostic pop")
^

Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,3 @@ fe_only -DTEST_NUMBER=1 --clang -e 200 --no_wrap_diagnostics --clang_version 999
#pragma clang diagnostic pop
^

"Test_name.c", line 5: warning: unrecognized GCC pragma
#pragma GCC diagnostic warning "-Wall"
^

"Test_name.c", line 7: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wall"
^

"Test_name.c", line 9: warning: unrecognized GCC pragma
#pragma GCC diagnostic error "-Wall"
^

"Test_name.c", line 11: warning: unrecognized GCC pragma
#pragma GCC diagnostic fatal "-Wall"
^

"Test_name.c", line 13: warning: unrecognized GCC pragma
#pragma GCC diagnostic push
^

"Test_name.c", line 15: warning: unrecognized GCC pragma
#pragma GCC diagnostic pop
^

Original file line number Diff line number Diff line change
@@ -1,25 +1 @@
fe_only -DTEST_NUMBER=1 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c Test_name.c
"Test_name.c", line 5: warning: unrecognized GCC pragma
#pragma GCC diagnostic warning "-Wall"
^

"Test_name.c", line 7: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wall"
^

"Test_name.c", line 9: warning: unrecognized GCC pragma
#pragma GCC diagnostic error "-Wall"
^

"Test_name.c", line 11: warning: unrecognized GCC pragma
#pragma GCC diagnostic fatal "-Wall"
^

"Test_name.c", line 13: warning: unrecognized GCC pragma
#pragma GCC diagnostic push
^

"Test_name.c", line 15: warning: unrecognized GCC pragma
#pragma GCC diagnostic pop
^

Original file line number Diff line number Diff line change
@@ -1,25 +1 @@
fe_only -DTEST_NUMBER=1 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c Test_name.c
"Test_name.c", line 5: warning: unrecognized GCC pragma
#pragma GCC diagnostic warning "-Wall"
^

"Test_name.c", line 7: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wall"
^

"Test_name.c", line 9: warning: unrecognized GCC pragma
#pragma GCC diagnostic error "-Wall"
^

"Test_name.c", line 11: warning: unrecognized GCC pragma
#pragma GCC diagnostic fatal "-Wall"
^

"Test_name.c", line 13: warning: unrecognized GCC pragma
#pragma GCC diagnostic push
^

"Test_name.c", line 15: warning: unrecognized GCC pragma
#pragma GCC diagnostic pop
^

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ fe_only -DTEST_NUMBER=2 --clang -e 200 --no_wrap_diagnostics --clang_version 999
int_val = __INT_MAX__, // INT_MAX
^

"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

1 error detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ fe_only -DTEST_NUMBER=4 --clang -e 200 --no_wrap_diagnostics --clang_version 999
int_val = __INT_MAX__, // INT_MAX
^

"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

1 error detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ fe_only -DTEST_NUMBER=5 --clang -e 200 --no_wrap_diagnostics --clang_version 999
int_val = __INT_MAX__, // INT_MAX
^

"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

1 error detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ fe_only -DTEST_NUMBER=6 --clang -e 200 --no_wrap_diagnostics --clang_version 999
int_val = __INT_MAX__, // INT_MAX
^

"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

1 error detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ fe_only -DTEST_NUMBER=7 --clang -e 200 --no_wrap_diagnostics --clang_version 999
int_val = __INT_MAX__, // INT_MAX
^

"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

1 error detected in the compilation of "Test_name.c".
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fe_only -DTEST_NUMBER=2 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c11 Test_name.c
"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fe_only -DTEST_NUMBER=4 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c11 Test_name.c
"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fe_only -DTEST_NUMBER=5 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c11 Test_name.c
"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fe_only -DTEST_NUMBER=6 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c11 Test_name.c
"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fe_only -DTEST_NUMBER=7 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c11 Test_name.c
"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fe_only -DTEST_NUMBER=2 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c11 Test_name.c
"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fe_only -DTEST_NUMBER=4 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c11 Test_name.c
"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fe_only -DTEST_NUMBER=5 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c11 Test_name.c
"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fe_only -DTEST_NUMBER=6 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c11 Test_name.c
"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fe_only -DTEST_NUMBER=7 --clang -e 200 --no_wrap_diagnostics --clang_version 999999 --c11 Test_name.c
"Test_name.c", line 222: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wformat"
^

Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,6 @@ fe_only -DTEST_NUMBER=1 --clang -e 200 --no_wrap_diagnostics --clang_version 999
void blapp() { } // both-error {{conflicting types for 'blapp'}} \
^

"Test_name.c", line 68: warning: unrecognized GCC pragma
#pragma GCC diagnostic push
^

"Test_name.c", line 69: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wdeprecated-non-prototype"
^

"Test_name.c", line 71: warning: unrecognized GCC pragma
#pragma GCC diagnostic pop
^

"Test_name.c", line 75: warning: unrecognized GCC pragma
#pragma GCC diagnostic push
^

"Test_name.c", line 76: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wstrict-prototypes"
^

"Test_name.c", line 78: warning: unrecognized GCC pragma
#pragma GCC diagnostic pop
^

"Test_name.c", line 97: warning: variable "f" is used before its value is set
f(); // OK
^
Expand Down
12 changes: 0 additions & 12 deletions tests/tests/imported/gnu/c/.Wattribute-alias.rto/default.1.1.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
fe_only -DTEST_NUMBER=1 --gnu_version=999999 -e 200 --no_wrap --no_wrap_diagnostics --gcc Test_name.c
"Test_name.c", line 19: warning: unrecognized GCC pragma
#pragma GCC diagnostic push "-Wattribute-alias"
^

"Test_name.c", line 20: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wattribute-alias"
^

"Test_name.c", line 23: warning: unrecognized GCC pragma
#pragma GCC diagnostic pop "-Wattribute-alias"
^

"Test_name.c", line 54: warning: unknown attribute "leaf"
ATTR (pure, leaf) F* resolve_to_const (void)
^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
fe_only -DTEST_NUMBER=1 --gnu_version=999999 -e 200 --no_wrap --no_wrap_diagnostics --gcc Test_name.c
"Test_name.c", line 19: warning: unrecognized GCC pragma
#pragma GCC diagnostic push "-Wattribute-alias"
^

"Test_name.c", line 20: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wattribute-alias"
^

"Test_name.c", line 23: warning: unrecognized GCC pragma
#pragma GCC diagnostic pop "-Wattribute-alias"
^

Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
fe_only -DTEST_NUMBER=1 --gnu_version=999999 -e 200 --no_wrap --no_wrap_diagnostics --gcc Test_name.c
"Test_name.c", line 19: warning: unrecognized GCC pragma
#pragma GCC diagnostic push "-Wattribute-alias"
^

"Test_name.c", line 20: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wattribute-alias"
^

"Test_name.c", line 23: warning: unrecognized GCC pragma
#pragma GCC diagnostic pop "-Wattribute-alias"
^

Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
fe_only -DTEST_NUMBER=1 --gnu_version=999999 -e 200 --no_wrap --no_wrap_diagnostics --gcc Test_name.c
"Test_name.c", line 26: warning: unrecognized GCC pragma
#pragma GCC diagnostic warning "-Wextra"
^

Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
fe_only -DTEST_NUMBER=1 --gnu_version=999999 -e 200 --no_wrap --no_wrap_diagnostics --gcc Test_name.c
"Test_name.c", line 7: warning: unrecognized GCC pragma
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
^

"Test_name.c", line 11: warning: function "sscanf" declared implicitly
sscanf (str, "%d", &i);
^
Expand Down
4 changes: 0 additions & 4 deletions tests/tests/imported/gnu/c/.Werror-1.rto/default.1.1.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
fe_only -DTEST_NUMBER=1 --gnu_version=999999 -e 200 --no_wrap --no_wrap_diagnostics --gcc Test_name.c
"Test_name.c", line 12: warning: unrecognized GCC pragma
#pragma GCC diagnostic error "-Waddress"
^

"Test_name.c", line 15: warning: unknown attribute "dj"
void __attribute__((dj)) bar() { } /* { dg-error ".* attribute directive ignored" } */
^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
fe_only -DTEST_NUMBER=1 --gnu_version=999999 -e 200 --no_wrap --no_wrap_diagnostics --gcc Test_name.c
"Test_name.c", line 12: warning: unrecognized GCC pragma
#pragma GCC diagnostic error "-Waddress"
^

"Test_name.c", line 22: warning: controlling expression is constant
if (&i) /* { dg-error "7:.* will always evaluate as 'true'" } */
^
Expand Down
Loading
Loading