This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: avr-gcc optimization issue


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]