From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mo4-p00-ob.smtp.rzone.de (mo4-p00-ob.smtp.rzone.de [81.169.146.220]) by sourceware.org (Postfix) with ESMTPS id ACA2B3852225 for ; Wed, 23 Nov 2022 17:13:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ACA2B3852225 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gjlay.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=gjlay.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1669223626; s=strato-dkim-0002; d=gjlay.de; h=Subject:From:To:Date:Message-ID:Cc:Date:From:Subject:Sender; bh=ZynPA4hEBKTmUerti15BDuf3SBqnGyc4dF61FvTR7lo=; b=C/aWmVmcqRCR00B+nrqcDtK621mH80kuT1DVm4FsYEvOuannvV+kI2FJzHBdhd1QIo eUK1ymbYKTql5+CCpw/8vLciM4JiCABllxzNWRm2YScxbkTBhgQGVx9qrSRkzfqFhmf+ P4Rw789CfHj7hX5tSAgrw5DJxjKa01Ac65oOenRUGksMKkvTCdfR4tJ5vLQ5GlKsMMTY +BGtdg3EYm8k9rvkOWiVSX7EphbmkP7PAJyvimAwgOMVIvzzXyDDYghtzAsyXoATVhq9 Fwqs1I21HxEdEcnMdbniIX0HNYRH0KmVNGZy3IiFp+aNCQU8kkR0s/92cuHIMSNWCh3n ubIQ== Authentication-Results: strato.com; dkim=none X-RZG-AUTH: ":LXoWVUeid/7A29J/hMvvT3koxZnKT7Qq0xotTetVnKkbjtK7qmy9Jvpc5Ezo" X-RZG-CLASS-ID: mo00 Received: from [192.168.2.102] by smtp.strato.de (RZmta 48.2.1 DYNA|AUTH) with ESMTPSA id aba1dcyANHDkbCx (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate) for ; Wed, 23 Nov 2022 18:13:46 +0100 (CET) Message-ID: <6cf489d9-ccd6-af3c-b49e-7bc5166557c6@gjlay.de> Date: Wed, 23 Nov 2022 18:13:39 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Content-Language: en-US To: gcc@gcc.gnu.org From: Georg-Johann Lay Subject: -Warray-bounds interprets int *var as int var[0] ? Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The following code throws a warning which I do not understand. Purpose is to save and restore SREG, which is a special function register (SFR) defined by its hardware address as: #define SREG (*(volatile uint8_t*) (0x3F + __AVR_SFR_OFFSET__)) which is the common C idiom to define such an SFR. The C code is: typedef __UINT8_TYPE__ uint8_t; #define SREG (*(volatile uint8_t*) (0x3F + __AVR_SFR_OFFSET__)) static __inline__ uint8_t __iCliRetVal (void) { __asm__ __volatile__ ("cli" ::: "memory"); return 1; } static __inline__ void __iRestore (const uint8_t *__s) { SREG = *__s; __asm__ volatile ("" ::: "memory"); } void foo (void) { for (uint8_t sreg_save __attribute__((__cleanup__(__iRestore))) = SREG, __ToDo = __iCliRetVal(); __ToDo ; __ToDo = 0 ) { __asm ("nop"); } } The documentation of attribute cleanup says that the function provided to cleanup (__iRestore) must take a pointer type that is compatible with the attributed variable, which is the case. The warning is: avr-gcc-13 -c foo-i.c -mmcu=atmega8 -Os -Wall -save-temps -dumpbase "" foo-i.c: In function 'foo': foo-i.c:20:71: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Warray-bounds] 20 | for (uint8_t sreg_save __attribute__((__cleanup__(__iRestore))) = SREG, | ~^~~~ In function '__iRestore', inlined from 'foo' at foo-i.c:20:17: foo-i.c:13:42: warning: array subscript 0 is outside array bounds of 'volatile uint8_t[0]' {aka 'volatile unsigned char[]'} [-Warray-bounds] 13 | SREG = *__s; | ~~~~~~~~~~~~ ^ To me this looks like a GCC problem, and older versions of the compiler don't complain. Or is there actually an issue with that code? Purpose of the code is to save / restore SREG around a block of code, "nop" in the example. The warning complains about the places that are using SREG, so it that macro definition wrong? Thanks in advance, Johann > avr-gcc-13 -v Using built-in specs. Reading specs from /home/DATA/gnu/install/gcc-master-avr/bin/../lib/gcc/avr/13.0.0/device-specs/specs-avr2 COLLECT_GCC=avr-gcc-13 COLLECT_LTO_WRAPPER=/home/DATA/gnu/install/gcc-master-avr/bin/../libexec/gcc/avr/13.0.0/lto-wrapper Target: avr Configured with: ../../source/gcc-master/configure --target=avr --disable-nls --with-dwarf2 --enable-languages=c,c++ --with-gnu-as --with-gnu-ld --disable-shared --with-fixed-point=no --prefix=/home/john/gnu/install/gcc-master-avr --enable-checking=release Thread model: single Supported LTO compression algorithms: zlib gcc version 13.0.0 20221103 (experimental) (GCC)