public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "saaadhu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug target/101188] [AVR] Miscompilation and function pointers Date: Fri, 25 Jun 2021 08:09:36 +0000 [thread overview] Message-ID: <bug-101188-4-qaJuUWFiCc@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-101188-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101188 Senthil Kumar Selvaraj <saaadhu at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW CC| |saaadhu at gcc dot gnu.org Ever confirmed|0 |1 Last reconfirmed| |2021-06-25 --- Comment #1 from Senthil Kumar Selvaraj <saaadhu at gcc dot gnu.org> --- Confirmed with 12.0.0 20210625 Here's a reduced testcase that hangs indefinitely with avrtest - the log shows call to address 0. $ cat fail.c #include <stdint.h> #include <stdlib.h> typedef uint8_t (*fn1)(void *a); typedef void (*fn2)(void *a, const uint32_t *arg); struct S { uint8_t buffer[64]; uint16_t n; fn2 f2; void *a; fn1 f1; }; volatile uint16_t x; void __attribute__((noinline)) foo(uint16_t n) { x = n; } void __attribute__((noinline)) testfn(struct S *self) { uint32_t arg; foo(self->n); self->n++; self->f2(self->a, &arg); self->buffer[0] = self->f1(self->a); } static unsigned char myfn2_called = 0; static void myfn2(void *a, const uint32_t * arg) { myfn2_called = 1; } static uint8_t myfn1(void *a) { } int main() { struct S s; s.n = 0; s.f2 = myfn2; s.f1 = myfn1; testfn(&s); if (myfn2_called != 1) abort(); return 0; } $ avr-gcc -mmcu=atmega128 fail.c -O2 ~/code/avrtest/exit-atmega128.o --version avr-gcc (GCC) 12.0.0 20210625 (experimental) Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ ~/code/avrtest/avrtest -mmcu=avr51 a.out ^C The below code is at fault - there's an ldi to r31, followed by a load to Z using R31:R30, and then an icall. The clobbering of r31 at 0x138 causes junk values (0) to be read into Z, and icall calls address 0. 138: f4 e4 ldi r31, 0x44 ; 68 13a: ef 0e add r14, r31 13c: f1 1c adc r15, r1 13e: 32 96 adiw r30, 0x02 ; 2 140: 01 90 ld r0, Z+ 142: f0 81 ld r31, Z 144: e0 2d mov r30, r0 146: be 01 movw r22, r28 148: 6f 5f subi r22, 0xFF ; 255 14a: 7f 4f sbci r23, 0xFF ; 255 14c: d7 01 movw r26, r14 14e: 8d 91 ld r24, X+ 150: 9c 91 ld r25, X 152: 09 95 icall
next prev parent reply other threads:[~2021-06-25 8:09 UTC|newest] Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-24 7:36 [Bug c/101188] New: " joel.bertrand at systella dot fr 2021-06-25 8:09 ` saaadhu at gcc dot gnu.org [this message] 2023-05-24 6:56 ` [Bug target/101188] " gjl at gcc dot gnu.org 2023-05-24 7:21 ` [Bug rtl-optimization/101188] " gjl at gcc dot gnu.org 2023-05-24 7:44 ` gjl at gcc dot gnu.org 2023-05-24 11:07 ` gjl at gcc dot gnu.org 2023-05-24 19:07 ` gjl at gcc dot gnu.org 2023-05-25 9:47 ` gjl at gcc dot gnu.org 2023-05-28 9:24 ` [Bug rtl-optimization/101188] [postreload] Uses content of a clobbered register gjl at gcc dot gnu.org 2023-05-28 19:26 ` gjl at gcc dot gnu.org 2023-05-29 19:35 ` gjl at gcc dot gnu.org 2023-05-30 19:05 ` gjl at gcc dot gnu.org 2023-06-02 10:36 ` uweigand at gcc dot gnu.org 2023-06-02 11:27 ` gjl at gcc dot gnu.org 2023-06-02 15:35 ` uweigand at gcc dot gnu.org 2023-06-12 18:55 ` cvs-commit at gcc dot gnu.org 2023-06-13 11:42 ` gjl at gcc dot gnu.org 2023-06-13 11:45 ` gjl at gcc dot gnu.org 2023-08-09 18:57 ` gjl at gcc dot gnu.org 2024-02-09 11:23 ` [Bug rtl-optimization/101188] [11/12/13 Regression] " gjl at gcc dot gnu.org 2024-02-09 13:02 ` rguenth at gcc dot gnu.org 2024-05-08 11:47 ` rguenth at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-101188-4-qaJuUWFiCc@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).