[llvmg++] Extern const globals cannot be marked 'constant' if they have nontrivial ctors or dtors #822
Labels
bugzilla
Issues migrated from bugzilla
llvm-tools
All llvm tools that do not have corresponding tag
miscompilation
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
The text was updated successfully, but these errors were encountered: