[LLVMbugs] [Bug 450] NEW: [llvmg++] Extern const globals cannot be marked 'constant' if they have nontrivial ctors or dtors

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Mon Oct 4 16:34:09 PDT 2004


http://llvm.cs.uiuc.edu/bugs/show_bug.cgi?id=450

           Summary: [llvmg++] Extern const globals cannot be marked
                    'constant' if they have nontrivial ctors or dtors
           Product: tools
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: llvm-g++
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: sabre at nondot.org


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



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.




More information about the llvm-bugs mailing list