This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: avr-gcc optimization issue
- From: Oleg Endo <oleg dot endo at t-online dot de>
- To: Henrik Juul Pedersen <hjp at liab dot dk>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Fri, 07 Mar 2014 16:28:26 +0100
- Subject: Re: avr-gcc optimization issue
- Authentication-results: sourceware.org; auth=none
- References: <CABQZ+_RchpKqywV-JHOTRKgRTOtdzy2jU_i9O69XJK6OfHhHiw at mail dot gmail dot com>
Hello,
On Fri, 2014-03-07 at 15:39 +0100, Henrik Juul Pedersen wrote:
> Hi, I'm not sure if this is the correct forum, but I'm not sure
> whether this is a bug, or a feature.
Yes, gcc-help is for these kind of questions, however ...
>
> Im working on a program for an AVR microcontroller using avr-gcc for
> the compilation.
>
> $ avr-gcc -v
> Using built-in specs.
> COLLECT_GCC=avr-gcc
> COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.8.2/lto-wrapper
> Target: avr
> Configured with: /build/avr-gcc/src/gcc-4.8.2/configure
> --disable-cloog-version-check --disable-install-libiberty
> --disable-libssp --disable-libstdcxx-pch
> --disable-libunwind-exceptions --disable-linker-build-id --disable-nls
> --disable-werror --enable-__cxa_atexit --enable-checking=release
> --enable-clocale=gnu --enable-cloog-backend=isl
> --enable-gnu-unique-object --enable-gold --enable-languages=c,c++
> --enable-ld=default --enable-lto --enable-plugin --enable-shared
> --infodir=/usr/share/info --libdir=/usr/lib --libexecdir=/usr/lib
> --mandir=/usr/share/man --prefix=/usr --target=avr
> --with-as=/usr/bin/avr-as --with-gnu-as --with-gnu-ld
> --with-ld=/usr/bin/avr-ld --with-plugin-ld=ld.gold --with-system-zlib
> Thread model: single
> gcc version 4.8.2 (GCC)
>
> I have gotten an issue with a single function variable not being
> checked after optimization.
> My question is: shouldn't I be able to assume that function variables
> are treated as being volatile, unless optimized away completely?
> Marking the function variable volatile solves the issue.
>
> The code is compiled with -O2 -ffreestanding -Wall -Wextra and
> produces no warnings.
>
> I have not been able to create a simple test-case, but I can supply
> the entire source upon request.
... it's difficult to answer your question, because of lack of source
code that shows the problem. There could be a bug in the compiler, or
there could be a bug in your code.
The compiler may remove local variables, if it thinks they are not
needed. For example:
int test (int a)
{
int b = 5;
int c = a + b;
return c;
}
will effectively be converted to 'return a + 5'. If one of the local
variables is marked volatile, it will be usually allocated and
loaded/stored using stack memory -- this is not the default behavior.
Cheers,
Oleg