[LLVMbugs] [Bug 8927] New: Invalid constant merging

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jan 7 06:25:20 PST 2011


http://llvm.org/bugs/show_bug.cgi?id=8927

           Summary: Invalid constant merging
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Interprocedural Optimizations
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: rafael.espindola at gmail.com
                CC: llvmbugs at cs.uiuc.edu


The C standard says that

Two pointers compare equal if and only if both are null pointers, both are
pointers to the same object (including a pointer to an object and a subobject
at its beginning) or function, both are pointers to one past the last element
of the same array object, or one is a pointer to one past the end of one array
object and the other is a pointer to the start of a different array object that
happens to immediately follow the first array object in the address space.

With -O0 and some cleanup passes clang compiles

struct foobar {
  int x;
};
static const struct foobar* foo() {
  static const struct foobar d = { 0 };
  return &d;
}
static const struct foobar* bar() {
  static const struct foobar d = { 0 };
  return &d;
}
int zed(const struct foobar *a, const struct foobar *b);
int main() {
  zed(foo(), bar());
}


to

%struct.foobar = type { i32 }
@bar.d = internal constant %struct.foobar zeroinitializer, align 4
@foo.d = internal constant %struct.foobar zeroinitializer, align 4
define i32 @main() nounwind ssp {
entry:
  %call2 = tail call i32 @zed(%struct.foobar* @foo.d, %struct.foobar* @bar.d)
nounwind
  ret i32 0
}
declare i32 @zed(%struct.foobar*, %struct.foobar*)


but constmerge (which is included in -O2) transforms it to

%struct.foobar = type { i32 }
@bar.d = internal constant %struct.foobar zeroinitializer, align 4
define i32 @main() nounwind ssp {
entry:
  %call2 = tail call i32 @zed(%struct.foobar* @bar.d, %struct.foobar* @bar.d)
nounwind
  ret i32 0
}
declare i32 @zed(%struct.foobar*, %struct.foobar*)

Since the function zed in unknown, it might compare the pointers and now it
will get a different result.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list