From 0884c17d93e7622535d21969418b8aa43ec5092e Mon Sep 17 00:00:00 2001 From: Georg-Johann Lay Date: Tue, 22 Aug 2017 09:48:48 +0000 Subject: [PATCH] backport: re PR target/79883 (avr i18n: untranslated "interrupt" or "signal") gcc/ Backport from 2016-06-15 trunk r237486. Backport from 2017-07-12 trunk r250156. PR target/79883 PR target/67353 * config/avr/avr.c (avr_set_current_function): Warn misspelled ISR only if -Wmisspelled-isr is on. In diagnostic messages: Quote keywords and (parts of) identifiers. [WITH_AVRLIBC]: Warn functions named "ISR", "SIGNAL" or "INTERUPT". * doc/invoke.texi (AVR Options) <-Wmisspelled-isr>: Document. From-SVN: r251269 --- gcc/ChangeLog | 13 +++++++++++++ gcc/config/avr/avr.c | 32 ++++++++++++++++++++++++-------- gcc/config/avr/avr.opt | 4 ++++ gcc/doc/invoke.texi | 10 ++++++++-- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7928130304b1..62bb658bf19d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,16 @@ +2017-08-22 Georg-Johann Lay + + Backport from 2016-06-15 trunk r237486. + Backport from 2017-07-12 trunk r250156. + + PR target/79883 + PR target/67353 + * config/avr/avr.c (avr_set_current_function): Warn misspelled ISR + only if -Wmisspelled-isr is on. In diagnostic messages: Quote + keywords and (parts of) identifiers. + [WITH_AVRLIBC]: Warn functions named "ISR", "SIGNAL" or "INTERUPT". + * doc/invoke.texi (AVR Options) <-Wmisspelled-isr>: Document. + 2017-08-22 Georg-Johann Lay Backport from 2017-04-19 trunk r246997. diff --git a/gcc/config/avr/avr.c b/gcc/config/avr/avr.c index 497478c7a9f2..436ba034bc0a 100644 --- a/gcc/config/avr/avr.c +++ b/gcc/config/avr/avr.c @@ -769,12 +769,6 @@ avr_set_current_function (tree decl) name = default_strip_name_encoding (name); - /* Silently ignore 'signal' if 'interrupt' is present. AVR-LibC startet - using this when it switched from SIGNAL and INTERRUPT to ISR. */ - - if (cfun->machine->is_interrupt) - cfun->machine->is_signal = 0; - /* Interrupt handlers must be void __vector (void) functions. */ if (args && TREE_CODE (TREE_VALUE (args)) != VOID_TYPE) @@ -783,14 +777,36 @@ avr_set_current_function (tree decl) if (TREE_CODE (ret) != VOID_TYPE) error_at (loc, "%qs function cannot return a value", isr); +#if defined WITH_AVRLIBC + /* Silently ignore 'signal' if 'interrupt' is present. AVR-LibC startet + using this when it switched from SIGNAL and INTERRUPT to ISR. */ + + if (cfun->machine->is_interrupt) + cfun->machine->is_signal = 0; + /* If the function has the 'signal' or 'interrupt' attribute, ensure that the name of the function is "__vector_NN" so as to catch when the user misspells the vector name. */ if (!STR_PREFIX_P (name, "__vector")) - warning_at (loc, 0, "%qs appears to be a misspelled %s handler", - name, isr); + warning_at (loc, OPT_Wmisspelled_isr, "%qs appears to be a misspelled " + "%qs handler, missing %<__vector%> prefix", name, isr); +#endif // AVR-LibC naming conventions + } + +#if defined WITH_AVRLIBC + // Common problem is using "ISR" without first including avr/interrupt.h. + const char *name = IDENTIFIER_POINTER (DECL_NAME (decl)); + name = default_strip_name_encoding (name); + if (0 == strcmp ("ISR", name) + || 0 == strcmp ("INTERRUPT", name) + || 0 == strcmp ("SIGNAL", name)) + { + warning_at (loc, OPT_Wmisspelled_isr, "%qs is a reserved identifier" + " in AVR-LibC. Consider %<#include %>" + " before using the %qs macro", name, name); } +#endif // AVR-LibC naming conventions /* Don't print the above diagnostics more than once. */ diff --git a/gcc/config/avr/avr.opt b/gcc/config/avr/avr.opt index 7e32ce5a350f..dc7326c3d12c 100644 --- a/gcc/config/avr/avr.opt +++ b/gcc/config/avr/avr.opt @@ -91,6 +91,10 @@ Waddr-space-convert Warning C Report Var(avr_warn_addr_space_convert) Init(0) Warn if the address space of an address is changed. +Wmisspelled-isr +Warning C C++ Report Var(avr_warn_misspelled_isr) Init(1) +Warn if the ISR is misspelled, i.e. without __vector prefix. Enabled by default. + mfract-convert-truncate Target Report Mask(FRACT_CONV_TRUNC) Allow to use truncation instead of rounding towards 0 for fractional int types diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 05a042100025..6353fe7b68c7 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -574,7 +574,8 @@ Objective-C and Objective-C++ Dialects}. @emph{AVR Options} @gccoptlist{-mmcu=@var{mcu} -maccumulate-args -mbranch-cost=@var{cost} @gol -mcall-prologues -mint8 -mn_flash=@var{size} -mno-interrupts @gol --mrelax -mrmw -mstrict-X -mtiny-stack -nodevicelib -Waddr-space-convert} +-mrelax -mrmw -mstrict-X -mtiny-stack -nodevicelib -Waddr-space-convert @gol +-Wmisspelled-isr} @emph{Blackfin Options} @gccoptlist{-mcpu=@var{cpu}@r{[}-@var{sirevision}@r{]} @gol @@ -13656,12 +13657,17 @@ Only change the lower 8@tie{}bits of the stack pointer. @item -nodevicelib @opindex nodevicelib -Don't link against AVR-LibC's device specific library @code{libdev.a}. +Don't link against AVR-LibC's device specific library @code{lib.a}. @item -Waddr-space-convert @opindex Waddr-space-convert Warn about conversions between address spaces in the case where the resulting address space is not contained in the incoming address space. + +@item -Wmisspelled-isr +@opindex Wmisspelled-isr +Warn if the ISR is misspelled, i.e. without @code{__vector} prefix. +Enabled by default. @end table @subsubsection @code{EIND} and Devices with More Than 128 Ki Bytes of Flash -- 2.47.2