Skip to content

Commit 6f1ae1e

Browse files
phdJeff Law
authored andcommitted
Do not warn about unused macros while processing #pragma GCC optimize
libcpp PR c++/91318 * include/cpplib.h: Added cpp_define_unused(), cpp_define_formatted_unused() * directives.c: Likewise. gcc/c-family PR c++/91318 * c-cppbuiltin.c: c_cpp_builtins_optimize_pragma(): use cpp_define_unused()
1 parent e7e0eee commit 6f1ae1e

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

gcc/c-family/c-cppbuiltin.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -581,41 +581,41 @@ c_cpp_builtins_optimize_pragma (cpp_reader *pfile, tree prev_tree,
581581
/* Other target-independent built-ins determined by command-line
582582
options. */
583583
if (!prev->x_optimize_size && cur->x_optimize_size)
584-
cpp_define (pfile, "__OPTIMIZE_SIZE__");
584+
cpp_define_unused (pfile, "__OPTIMIZE_SIZE__");
585585
else if (prev->x_optimize_size && !cur->x_optimize_size)
586586
cpp_undef (pfile, "__OPTIMIZE_SIZE__");
587587

588588
if (!prev->x_optimize && cur->x_optimize)
589-
cpp_define (pfile, "__OPTIMIZE__");
589+
cpp_define_unused (pfile, "__OPTIMIZE__");
590590
else if (prev->x_optimize && !cur->x_optimize)
591591
cpp_undef (pfile, "__OPTIMIZE__");
592592

593593
prev_fast_math = fast_math_flags_struct_set_p (prev);
594594
cur_fast_math = fast_math_flags_struct_set_p (cur);
595595
if (!prev_fast_math && cur_fast_math)
596-
cpp_define (pfile, "__FAST_MATH__");
596+
cpp_define_unused (pfile, "__FAST_MATH__");
597597
else if (prev_fast_math && !cur_fast_math)
598598
cpp_undef (pfile, "__FAST_MATH__");
599599

600600
if (!prev->x_flag_signaling_nans && cur->x_flag_signaling_nans)
601-
cpp_define (pfile, "__SUPPORT_SNAN__");
601+
cpp_define_unused (pfile, "__SUPPORT_SNAN__");
602602
else if (prev->x_flag_signaling_nans && !cur->x_flag_signaling_nans)
603603
cpp_undef (pfile, "__SUPPORT_SNAN__");
604604

605605
if (!prev->x_flag_errno_math && cur->x_flag_errno_math)
606606
cpp_undef (pfile, "__NO_MATH_ERRNO__");
607607
else if (prev->x_flag_errno_math && !cur->x_flag_errno_math)
608-
cpp_define (pfile, "__NO_MATH_ERRNO__");
608+
cpp_define_unused (pfile, "__NO_MATH_ERRNO__");
609609

610610
if (!prev->x_flag_finite_math_only && cur->x_flag_finite_math_only)
611611
{
612612
cpp_undef (pfile, "__FINITE_MATH_ONLY__");
613-
cpp_define (pfile, "__FINITE_MATH_ONLY__=1");
613+
cpp_define_unused (pfile, "__FINITE_MATH_ONLY__=1");
614614
}
615615
else if (prev->x_flag_finite_math_only && !cur->x_flag_finite_math_only)
616616
{
617617
cpp_undef (pfile, "__FINITE_MATH_ONLY__");
618-
cpp_define (pfile, "__FINITE_MATH_ONLY__=0");
618+
cpp_define_unused (pfile, "__FINITE_MATH_ONLY__=0");
619619
}
620620
}
621621

libcpp/directives.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,6 +2412,15 @@ cpp_define (cpp_reader *pfile, const char *str)
24122412
run_directive (pfile, T_DEFINE, buf, count);
24132413
}
24142414

2415+
/* Like cpp_define, but does not warn about unused macro. */
2416+
void
2417+
cpp_define_unused (cpp_reader *pfile, const char *str)
2418+
{
2419+
unsigned char warn_unused_macros = CPP_OPTION (pfile, warn_unused_macros);
2420+
CPP_OPTION (pfile, warn_unused_macros) = 0;
2421+
cpp_define (pfile, str);
2422+
CPP_OPTION (pfile, warn_unused_macros) = warn_unused_macros;
2423+
}
24152424

24162425
/* Use to build macros to be run through cpp_define() as
24172426
described above.
@@ -2431,6 +2440,20 @@ cpp_define_formatted (cpp_reader *pfile, const char *fmt, ...)
24312440
free (ptr);
24322441
}
24332442

2443+
/* Like cpp_define_formatted, but does not warn about unused macro. */
2444+
void
2445+
cpp_define_formatted_unused (cpp_reader *pfile, const char *fmt, ...)
2446+
{
2447+
char *ptr;
2448+
2449+
va_list ap;
2450+
va_start (ap, fmt);
2451+
ptr = xvasprintf (fmt, ap);
2452+
va_end (ap);
2453+
2454+
cpp_define_unused (pfile, ptr);
2455+
free (ptr);
2456+
}
24342457

24352458
/* Slight variant of the above for use by initialize_builtins. */
24362459
void

libcpp/include/cpplib.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,12 @@ extern cppchar_t cpp_host_to_exec_charset (cpp_reader *, cppchar_t);
10761076
/* Used to register macros and assertions, perhaps from the command line.
10771077
The text is the same as the command line argument. */
10781078
extern void cpp_define (cpp_reader *, const char *);
1079+
extern void cpp_define_unused (cpp_reader *, const char *);
10791080
extern void cpp_define_formatted (cpp_reader *pfile,
10801081
const char *fmt, ...) ATTRIBUTE_PRINTF_2;
1082+
extern void cpp_define_formatted_unused (cpp_reader *pfile,
1083+
const char *fmt,
1084+
...) ATTRIBUTE_PRINTF_2;
10811085
extern void cpp_assert (cpp_reader *, const char *);
10821086
extern void cpp_undef (cpp_reader *, const char *);
10831087
extern void cpp_unassert (cpp_reader *, const char *);

0 commit comments

Comments
 (0)