A simple program causes gcc to use inordinate amounts of memory and finally crash. Environment: System: Linux glauke 2.6.8-powerpc #1 Sun Oct 3 13:22:21 CEST 2004 ppc GNU/Linux Architecture: ppc host: powerpc-unknown-linux-gnu build: powerpc-unknown-linux-gnu target: powerpc-unknown-linux-gnu configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada --prefix=/usr --libexecdir=/usr/lib --with-gxx-include-dir=/usr/include/c++/3.4 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --program-suffix=-3.4 --enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk --disable-multilib --disable-softfloat powerpc-linux How-To-Repeat: Compile this program as follows: gcc-3.4 -maltivec prog.c prog.c follows: #include <altivec.h> vector float foo(vector float a) { return vec_add(a, vec_add(a, vec_add(a, vec_add(a, a)))); }
Fix: Declare explicit temporary variables for the intermediate results.
This is the preprocessor f'ing up. The macros are complex which cause the problem, I might be able get a self contained example later on.
I wouldn't blame the preprocessor. The macros in altivec.h for C support have multiple occurences of their arguments. __builtin_choose_expr only evaluates one occurence, but that doesn't stop the preprocessor *substituting* the macro args multiple times. vec_add (a, a) expands to 8006 chars, vec_add (a, vec_add (a, a)) expands to 321430 vec_add (1, vec_add (a, vec_add (a, a))) expands to 12231542 and I didn't even try four levels. Perhaps this comment in altivec.h explains it.. /* "... and so I think no man in a century will suffer as greatly as you will." */
*** Bug 19821 has been marked as a duplicate of this bug. ***
Changing to target since this is due to Aldy's altivec.h implementation.
Fixed in 4.1.0 and above by: 2005-05-02 Paolo Bonzini <bonzini@gnu.org> * c-common.c (resolve_overloaded_builtin): Forward to target hook for BUILT_IN_MD built-ins. ....
*** Bug 21758 has been marked as a duplicate of this bug. ***
*** Bug 23759 has been marked as a duplicate of this bug. ***