Skip to content

Commit 20aaa93

Browse files
committed
Fix coderrabbit suggestions []
1 parent 2ffc173 commit 20aaa93

4 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎src/pending_changes/gh-182-gcc-diagnostic-pragmas.txt‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ was given an "unrecognized GCC pragma" warning. For example, with --g++:
1111
#pragma GCC diagnostic pop
1212

1313
This is now fixed. The "error", "warning", and "ignored" forms, the "push"
14-
and "pop" forms (when emulating GCC 4.6 or later), the "ignored_attributes"
15-
form (when emulating GCC 12 or later), and the "fatal" form (when emulating
16-
clang) are accepted without a warning, to match the behavior of those
17-
compilers. A missing or malformed option string is still diagnosed. The
18-
pragmas have no effect on the front end's own diagnostics.
14+
and "pop" forms (when emulating clang or GCC 4.6 or later), the
15+
"ignored_attributes" form (when emulating GCC 12 or later), and the "fatal"
16+
form (when emulating clang) are accepted without a warning, to match the
17+
behavior of those compilers. A missing or malformed option string is still
18+
diagnosed. The pragmas have no effect on the front end's own diagnostics.
19+
They are still passed through to the code generated by the C++-generating
20+
back end, but they are now omitted from the code generated by the
21+
C-generating back end, which cannot place them at their source positions.

‎src/preproc.c‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4289,7 +4289,7 @@ kind indicates which of the above is being processed.
42894289

42904290
static a_boolean process_gnu_diagnostic_pragma(a_pending_pragma_ptr ppp)
42914291
/*
4292-
Handle "#pragma GCC diagnostic push/pop" (GCC 4.6 and later) and
4292+
Handle "#pragma GCC diagnostic push/pop" (GCC 4.6 and later, and clang) and
42934293
"#pragma GCC diagnostic kind "option"", where kind is "error", "warning",
42944294
"ignored", "fatal" (clang only), or "ignored_attributes" (GCC 12 and later).
42954295
The pragmas are only accepted: they do not affect the front end's own
@@ -4303,7 +4303,7 @@ form is not recognized by the compiler being emulated.
43034303
(void)get_token();
43044304
if (curr_token == tok_identifier) {
43054305
a_const_char *str = locator_for_curr_id.symbol_header->identifier;
4306-
if (gnu_version >= 40600 &&
4306+
if ((clang_mode || gnu_version >= 40600) &&
43074307
(strcmp(str, "push") == 0 || strcmp(str, "pop") == 0)) {
43084308
recognized = TRUE;
43094309
} else if (strcmp(str, "error") == 0 ||
@@ -4361,7 +4361,6 @@ Process a "#pragma GCC ..." construct.
43614361
} else if (gnu_version >= 40400 && strcmp(str, "reset_options") == 0) {
43624362
process_gnu_options_pragma(ppp, (a_gcc_pragma_kind)gcc_pk_reset_options);
43634363
} else if (strcmp(str, "diagnostic") == 0) {
4364-
ignore_in_back_end = FALSE;
43654364
recognized = process_gnu_diagnostic_pragma(ppp);
43664365
#if GNU_VECTOR_TYPES_ALLOWED && BUILTIN_FUNCTIONS_ENABLED
43674366
} else if (target_is_arm_based() && target_is_64_bits() &&
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fe_only -DTEST_NUMBER=6 --diag_error=unrecognized_gcc_pragma --diag_error=exp_string_literal --clang --gnu_version=40500 Test_name.c

‎tests/tests/regressions/gh-182b.sft.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//type:fp
22
//remark:[GH #182] Version-specific "GCC diagnostic" pragmas
3-
//options:--g++ --gnu_version=150000:--g++ --gnu_version=120000:--g++ --gnu_version=110000:--g++ --gnu_version=40500:--clang
3+
//options:--g++ --gnu_version=150000:--g++ --gnu_version=120000:--g++ --gnu_version=110000:--g++ --gnu_version=40500:--clang:--clang --gnu_version=40500
44
//options_all:--diag_error=unrecognized_gcc_pragma --diag_error=exp_string_literal
55
#pragma GCC diagnostic warning "-Wshadow"
66
#pragma GCC diagnostic error "-Wreturn-type"
77
#if defined(__clang__) || __GNUC__ > 4 || __GNUC_MINOR__ >= 6
8-
#pragma GCC diagnostic push // GCC 4.6 and later
8+
#pragma GCC diagnostic push // GCC 4.6 and later, and clang
99
#pragma GCC diagnostic pop extra text // Trailing text is ignored.
1010
#endif
1111
#if !defined(__clang__) && __GNUC__ >= 12

0 commit comments

Comments
 (0)