Consider this testcase: ---- A.cpp ----- struct X { int A; X(); }; extern const X y; int foo(int *P) { int t = y.A; *P = 100; return t - y.A; } ---- Currently, llvmg++ marks 'y' as being llvm 'constant', allowing "foo" to be optimized to just a single store. However, this is incorrect, because X has a non-trivial ctor. The ctor could look like this: ---- B.cpp ---- struct X { int A; X(); }; int foo(int* P); X::X() { printf("%d", foo(&A)); } ---- ... in which the optimization breaks the program. This is a conformant C++ program, which we should not break. The fix is conceptually straight-forward: globals should not be marked constant if they have nontrivial ctor/dtors. -Chris
This is now fixed, patch here: http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20041004/018793.html Testcase here: test/Regression/C++Frontend/2004-10-04-ExternalGlobalConstant.cpp.tr This fixes the Prolangs-C++/city program. -Chris
Note, see Bug 502 for the ultimate resolution to this problem. -Chris