I get an ICE on the following code with GCC 9.0.1 20190407 (experimental) compiled for AVR. Works in GCC 8.x. If the __flash keyword is taken out before _str[]=("xx"), then it compiles OK. unsigned short sprintf(char *str, const char __flash *fmt, ...) { __builtin_va_list args; __builtin_va_start(args, fmt); __builtin_va_end(args); return 0; } extern char *s; int main() { s+=sprintf(s, ({ static const char __flash _str[]=("xx"); _str; })); } # avr-gcc -v -O -mmcu=atmega1284p -c test3.c -o test3.o Using built-in specs. Reading specs from /usr/local/avr/lib/gcc/avr/9.0.1/device-specs/specs-atmega1284p COLLECT_GCC=avr-gcc Target: avr Configured with: ../configure --target=avr --prefix=/usr/local/avr --disable-nls --enable-languages=c --disable-bootstrap --disable-libssp Thread model: single gcc version 9.0.1 20190407 (experimental) (GCC) COLLECT_GCC_OPTIONS='-v' '-O' '-c' '-o' 'test3.o' '-specs=device-specs/specs-atmega1284p' '-mmcu=avr51' /usr/local/avr/libexec/gcc/avr/9.0.1/cc1 -quiet -v -imultilib avr51 -D__AVR_ATmega1284P__ -D__AVR_DEVICE_NAME__=atmega1284p test3.c -mn-flash=2 -mno-skip-bug -quiet -dumpbase test3.c -mmcu=avr51 -auxbase-strip test3.o -O -version -o /tmp/ccm4oBir.s GNU C17 (GCC) version 9.0.1 20190407 (experimental) (avr) compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version none GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 ignoring nonexistent directory "/usr/local/avr/lib/gcc/avr/9.0.1/../../../../avr/sys-include" #include "..." search starts here: #include <...> search starts here: /usr/local/avr/lib/gcc/avr/9.0.1/include /usr/local/avr/lib/gcc/avr/9.0.1/include-fixed /usr/local/avr/lib/gcc/avr/9.0.1/../../../../avr/include End of search list. GNU C17 (GCC) version 9.0.1 20190407 (experimental) (avr) compiled by GNU C version 8.3.0, GMP version 6.1.2, MPFR version 4.0.2, MPC version 1.1.0, isl version none GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096 Compiler executable checksum: 082ea327cdf9723cb24010e987b4f891 test3.c: In function 'main': test3.c:12:5: error: non-trivial conversion at assignment 12 | int main() | ^~~~ short unsigned int int _6 = 2; during GIMPLE pass: printf-return-value test3.c:12:5: internal compiler error: verify_gimple failed 0xc51c8b verify_gimple_in_cfg(function*, bool) ../../gcc/tree-cfg.c:5386 0xb5ff2f execute_function_todo ../../gcc/passes.c:1977 0xb60e6e execute_todo ../../gcc/passes.c:2031 Please submit a full bug report.
Dup. *** This bug has been marked as a duplicate of bug 89996 ***
Maybe not exactly a dup but a related one.
There's another dup for this. But I wonder why it works in GCC 8 (maybe it only works with -fno-checking after all). So, can you try if GCC 8 fails the same way with -fchecking?
This has nothing to do with PR89996 and is not AVR specific either. Following can reproduce it on x86_64-linux: unsigned int sprintf (char *str, const char *fmt, ...); int foo (char *s) { return sprintf (s, "foo"); } and s/unsigned int/unsigned short/ on AVR. I'll handle it.
I think this started with r213951, though that is just a guess, our bisect seeder gave weird answers.
Created attachment 46097 [details] gcc9-pr89998.patch Untested fix.
This is another instance of the mismatched built-in signature problem. With -Wextra GCC 9 prints: warning: mismatch in return type of built-in function ‘sprintf’; expected ‘int’ [-Wbuiltin-declaration-mismatch] 1 | unsigned int sprintf (char *str, const char *fmt, ...); As we discussed, having the warning for the declaration disable treating the function as a built-in will avoid these bugs.
Author: jakub Date: Tue Apr 9 10:26:13 2019 New Revision: 270224 URL: https://gcc.gnu.org/viewcvs?rev=270224&root=gcc&view=rev Log: PR tree-optimization/89998 * gimple-ssa-sprintf.c (try_substitute_return_value): Use lhs type instead of integer_type_node if possible, don't add ranges if return type is not compatible with int. * gimple-fold.c (gimple_fold_builtin_sprintf, gimple_fold_builtin_snprintf): Use lhs type instead of hardcoded integer_type_node. * gcc.c-torture/compile/pr89998-1.c: New test. * gcc.c-torture/compile/pr89998-2.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/compile/pr89998-1.c trunk/gcc/testsuite/gcc.c-torture/compile/pr89998-2.c Modified: trunk/gcc/ChangeLog trunk/gcc/gimple-fold.c trunk/gcc/gimple-ssa-sprintf.c trunk/gcc/testsuite/ChangeLog
Fixed for trunk. As a workaround I'd suggest using a correct prototype or -fno-builtin-sprintf if you intentionally use a different one.
(In reply to Jakub Jelinek from comment #9) > Fixed for trunk. As a workaround I'd suggest using a correct prototype or > -fno-builtin-sprintf if you intentionally use a different one. Thanks. Using the correct prototype (dropping the 'unsigned') indeed works as a workaround.
Author: jakub Date: Tue Apr 30 20:58:00 2019 New Revision: 270745 URL: https://gcc.gnu.org/viewcvs?rev=270745&root=gcc&view=rev Log: Backported from mainline 2019-04-09 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/89998 * gimple-ssa-sprintf.c (try_substitute_return_value): Use lhs type instead of integer_type_node if possible, don't add ranges if return type is not compatible with int. * gimple-fold.c (gimple_fold_builtin_sprintf, gimple_fold_builtin_snprintf): Use lhs type instead of hardcoded integer_type_node. * gcc.c-torture/compile/pr89998-1.c: New test. * gcc.c-torture/compile/pr89998-2.c: New test. Added: branches/gcc-8-branch/gcc/testsuite/gcc.c-torture/compile/pr89998-1.c branches/gcc-8-branch/gcc/testsuite/gcc.c-torture/compile/pr89998-2.c Modified: branches/gcc-8-branch/gcc/ChangeLog branches/gcc-8-branch/gcc/gimple-fold.c branches/gcc-8-branch/gcc/gimple-ssa-sprintf.c branches/gcc-8-branch/gcc/testsuite/ChangeLog
Fixed for 8.4+ too.
Author: jakub Date: Fri Aug 30 12:35:05 2019 New Revision: 275146 URL: https://gcc.gnu.org/viewcvs?rev=275146&root=gcc&view=rev Log: Backported from mainline 2019-04-09 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/89998 * gimple-ssa-sprintf.c (try_substitute_return_value): Use lhs type instead of integer_type_node if possible, don't add ranges if return type is not compatible with int. * gimple-fold.c (gimple_fold_builtin_sprintf, gimple_fold_builtin_snprintf): Use lhs type instead of hardcoded integer_type_node. * gcc.c-torture/compile/pr89998-1.c: New test. * gcc.c-torture/compile/pr89998-2.c: New test. Added: branches/gcc-7-branch/gcc/testsuite/gcc.c-torture/compile/pr89998-1.c branches/gcc-7-branch/gcc/testsuite/gcc.c-torture/compile/pr89998-2.c Modified: branches/gcc-7-branch/gcc/ChangeLog branches/gcc-7-branch/gcc/gimple-fold.c branches/gcc-7-branch/gcc/gimple-ssa-sprintf.c branches/gcc-7-branch/gcc/testsuite/ChangeLog
Fixed.