Skip to content

Commit f6623bd

Browse files
committed
Add pre processor function for parsing of diagnostic pragmas
1 parent f350930 commit f6623bd

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

‎src/il_def.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6619,6 +6619,7 @@ enum a_gcc_pragma_kind : a_byte {
66196619
gcc_pk_push_options, /* #pragma GCC push_options */
66206620
gcc_pk_pop_options, /* #pragma GCC pop_options */
66216621
gcc_pk_reset_options, /* #pragma GCC reset_options */
6622+
gcc_pk_diagnostic, /* #pragma GCC diagnostic ... */
66226623
gcc_pk_last
66236624
};
66246625

‎src/preproc.c‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4258,6 +4258,57 @@ kind indicates which of the above is being processed.
42584258
} /* process_gnu_options_pragma */
42594259

42604260

4261+
static a_boolean process_gnu_diagnostic_pragma(a_pending_pragma_ptr ppp)
4262+
/*
4263+
Handle
4264+
#pragma GCC diagnostic push
4265+
#pragma GCC diagnostic pop
4266+
#pragma GCC diagnostic kind "option"
4267+
4268+
kind is recognized for: "error", "warning", "ignored", "fatal" (clang only),
4269+
or "ignored_attributes" (for GCC 13 and later).
4270+
4271+
"option" after kind is: an unchecked plain char string literal of type
4272+
4273+
These pragmas control the warnings issued by the GCC or clang in the backend.
4274+
Here, they are only accepted, and do not affect the diagnostics issued by the
4275+
front end. To match the behavior of GCC, any text following the pragma is
4276+
ignored. Return FALSE if the pragma is not a form recognized by the compiler
4277+
being emulated.
4278+
*/
4279+
{
4280+
a_boolean recognized = FALSE;
4281+
4282+
/* Skip the "diagnostic" identifier. */
4283+
(void)get_token();
4284+
if (curr_token == tok_identifier) {
4285+
a_const_char *str = locator_for_curr_id.symbol_header->identifier;
4286+
if (gnu_version >= 40600 &&
4287+
(strcmp(str, "push") == 0 || strcmp(str, "pop") == 0)) {
4288+
recognized = TRUE;
4289+
} else if (strcmp(str, "error") == 0 ||
4290+
strcmp(str, "warning") == 0 ||
4291+
strcmp(str, "ignored") == 0 ||
4292+
(clang_mode && strcmp(str, "fatal") == 0) ||
4293+
(gnu_version >= 130000 &&
4294+
strcmp(str, "ignored_attributes") == 0)) {
4295+
recognized = TRUE;
4296+
(void)get_token();
4297+
if (curr_token != tok_string_literal ||
4298+
!is_normal_character_kind(const_for_curr_token.character_kind)) {
4299+
/* The option (or attribute list) is missing. Only a string literal
4300+
of plain char type is accepted. */
4301+
pos_warning(ec_exp_string_literal, &error_position);
4302+
} /* if */
4303+
} /* if */
4304+
} /* if */
4305+
if (recognized) {
4306+
ppp->variant.gcc.kind = (a_gcc_pragma_kind)gcc_pk_diagnostic;
4307+
} /* if */
4308+
return recognized;
4309+
} /* process_gnu_diagnostic_pragma */
4310+
4311+
42614312
void gcc_pragma(a_pending_pragma_ptr ppp)
42624313
/*
42634314
Process a "#pragma GCC ..." construct.
@@ -4289,6 +4340,9 @@ Process a "#pragma GCC ..." construct.
42894340
process_gnu_options_pragma(ppp, (a_gcc_pragma_kind)gcc_pk_pop_options);
42904341
} else if (gnu_version >= 40400 && strcmp(str, "reset_options") == 0) {
42914342
process_gnu_options_pragma(ppp, (a_gcc_pragma_kind)gcc_pk_reset_options);
4343+
} else if (strcmp(str, "diagnostic") == 0) {
4344+
ignore_in_back_end = FALSE;
4345+
recognized = process_gnu_diagnostic_pragma(ppp);
42924346
#if GNU_VECTOR_TYPES_ALLOWED && BUILTIN_FUNCTIONS_ENABLED
42934347
} else if (target_is_arm_based() && target_is_64_bits() &&
42944348
strcmp(str, "aarch64") == 0) {

0 commit comments

Comments
 (0)