On the arm platform, it seems that throwing and catching an exception clobbers
variable-size arrays. The following example exposes the bug:
#include <assert.h>
class exception{};
int main(int argc,char *argv[]) {
/*const*/ int size(32);
int test[size];
test[0] = 1234;
try {
throw exception();
}
catch (exception) {
}
assert(test[0] == 1234 && "array");
return(0);
}
Compiler specifics:
arm-unknown-linux-gnu-g++ -v
Using built-in specs.
Target: arm-unknown-linux-gnu
Configured with:
/var/tmp/cross/arm-unknown-linux-gnu/portage/gcc-4.1.1-r3/work/gcc-4.1.1/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/arm-unknownu
Thread model: posix
gcc version 4.1.1 (Gentoo 4.1.1-r3)
$ arm-unknown-linux-gnu-g++ -static -o test_exception test_exception.cpp
$ ./test_exception
test_exception: test_exception.cpp:18: int main(int, char**): Assertion
`test[0] == 1234 && "array"' failed.
Aborted
It seems this problem was already present in the 3.3 series.
I would like to point out the following:
- in a real-world program, code paths with exceptions thrown are rarely
executed, so bugs caused by this may be very hard to debug
- it is quite easy to us evariable-size arrays unintentionally by leaving out
the const keyword
- fortunately, using the -pedantic option will find all occurances of variable
size arrays.
Rupert
PS: the only thing done by the preprocessor is the expansion of the assert
macro, but I can also provide the preprocessed program if needed.
--
Summary: variable-size array confused by exceptions
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rks at mur dot at
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: arm-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31092