Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvmg++] Extern const globals cannot be marked 'constant' if they have nontrivial ctors or dtors #822

Closed
lattner opened this issue Oct 5, 2004 · 3 comments
Labels
bugzilla Issues migrated from bugzilla llvm-tools All llvm tools that do not have corresponding tag miscompilation

Comments

@lattner
Copy link
Collaborator

lattner commented Oct 5, 2004

Bugzilla Link 450
Resolution FIXED
Resolved on Feb 22, 2010 12:42
Version trunk
OS All
Depends On llvm/llvm-bugzilla-archive#502

Extended Description

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

@lattner
Copy link
Collaborator Author

lattner commented Oct 5, 2004

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

@lattner
Copy link
Collaborator Author

lattner commented Feb 12, 2005

Note, see Bug 502 for the ultimate resolution to this problem.

-Chris

@lattner
Copy link
Collaborator Author

lattner commented Nov 27, 2021

mentioned in issue llvm/llvm-bugzilla-archive#502

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 3, 2021
kwk pushed a commit to kwk/llvm-project that referenced this issue Feb 1, 2022
… commit messages

This adds a new action that will automatically create a backport request
for the release branch any time a bug is automatically closed by
having a reference to it (e.g. Fixes llvm#12345) in a commit message.

Fixes llvm#822
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla llvm-tools All llvm tools that do not have corresponding tag miscompilation
Projects
None yet
Development

No branches or pull requests

1 participant