LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 450 - [llvmg++] Extern const globals cannot be marked 'constant' if they have nontrivial ctors or dtors
Summary: [llvmg++] Extern const globals cannot be marked 'constant' if they have nontr...
Status: RESOLVED FIXED
Alias: None
Product: tools
Classification: Unclassified
Component: llvm-g++ (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords: miscompilation
Depends on: 502
Blocks:
  Show dependency tree
 
Reported: 2004-10-04 18:34 PDT by Chris Lattner
Modified: 2010-02-22 12:42 PST (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2004-10-04 18:34:08 PDT
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 Chris Lattner 2004-10-04 19:21:25 PDT
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 Chris Lattner 2005-02-12 13:02:54 PST
Note, see Bug 502 for the ultimate resolution to this problem.

-Chris