First Last Prev Next    No search results available
Details
: [llvmg++] Extern const globals cannot be marked 'constant...
Bug#: 450
: tools
: llvm-g++
Status: RESOLVED
Resolution: FIXED
: All
: All
: trunk
: P2
: normal
: 1.4

:
: miscompilation
: 502
:
  Show dependency tree - Show dependency graph
People
Reporter: Chris Lattner <sabre@nondot.org>
Assigned To: Unassigned LLVM Bugs <unassignedbugs@nondot.org>

Attachments


Note

You need to log in before you can comment on or make changes to this bug.

Related actions


Description:   Opened: 2004-10-04 18:34
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
------- Comment #1 From Chris Lattner 2004-10-04 19:21:25 -------
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
------- Comment #2 From Chris Lattner 2005-02-12 13:02:54 -------
Note, see Bug 502 for the ultimate resolution to this problem.

-Chris

First Last Prev Next    No search results available