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 [85.215.255.20]) by sourceware.org (Postfix) with ESMTPS id 5759E3852229 for ; Wed, 23 Nov 2022 17:44:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5759E3852229 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=1669225478; s=strato-dkim-0002; d=gjlay.de; h=In-Reply-To:From:References:Cc:To:Subject:Date:Message-ID:Cc:Date: From:Subject:Sender; bh=K0JtzXTTR2/qNMYlOippF/x8XtbFSZtxMHkji1uKDTQ=; b=QMh4TQh4akcFLiUeyKXb2dhnuwCvU9gZr+VTAQ67GV9iWT10VnIGGue8zSYc/sd67S HnC1KM2hekv+ifxSkUcMNwn6lXSIksVtgYVnXb8KLG4/rJCnGwV1COux4kT7//oonvAc J5ITdUITq9HYOmGaM42/xos6YISnehnyseWVWoBNfqS/J2KSFWX2phJ4JWa+cGQGJx38 Nl6rraD4A0tul+sbFky+1N+vSuWGcib6AU6OFX1pUSVx/87dGS4Wo8VBsALS8h4TFIMZ B1DU0UnDvbXGQ2Mp4dbfnMx4ckI5p0cy9zU1zMh8g4menJU/cuvuzVlb2j7TX60tIRwS TZEQ== 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 aba1dcyANHicbHO (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256 bits)) (Client did not present a certificate); Wed, 23 Nov 2022 18:44:38 +0100 (CET) Message-ID: Date: Wed, 23 Nov 2022 18:44:37 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: -Warray-bounds interprets int *var as int var[0] ? Content-Language: en-US To: Andrew Pinski Cc: gcc@gcc.gnu.org References: <6cf489d9-ccd6-af3c-b49e-7bc5166557c6@gjlay.de> From: Georg-Johann Lay In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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: Am 23.11.22 um 18:18 schrieb Andrew Pinski: > On Wed, Nov 23, 2022 at 9:15 AM Georg-Johann Lay wrote: >> >> 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? > > Either you need to use --param=min-pagesize=0 as an option or you need > to modify the avr backend to set that by default. > > Thanks, > Andrew Pinski Ok, thanks. I filed it as PR107842. 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)