[LLVMbugs] [Bug 23911] New: Clang performs extra initialization of memcpy-able struct member

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Jun 22 07:54:36 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=23911

            Bug ID: 23911
           Summary: Clang performs extra initialization of memcpy-able
                    struct member
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: d.zobnin.bugzilla at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 14502
  --> https://llvm.org/bugs/attachment.cgi?id=14502&action=edit
Generated IR code

When compiling the following test:

int glob = 0;

struct A {
  int x;
  A() { x = 10; }
};

struct B {
  B() { glob = 15; }
  B(const B &other) { glob = 25; }
};

struct C {
  A a; // memcpy-able member
  B b; // non-trivial copy initialization
};

int main() {
  C c1;
  C c2(c1);
  return 0;
}

Clang generates the following code for copy-constructor of C:

$ clang -cc1 -O0 test.cpp -emit-llvm -o -

; Function Attrs: inlinehint nounwind
define linkonce_odr void @_ZN1CC2ERKS_(%struct.C* %this, %struct.C*
dereferenceable(8)) unnamed_addr #1 com
dat align 2 {
entry:
  %this.addr = alloca %struct.C*, align 8
  %.addr = alloca %struct.C*, align 8
  store %struct.C* %this, %struct.C** %this.addr, align 8
  store %struct.C* %0, %struct.C** %.addr, align 8
  %this1 = load %struct.C*, %struct.C** %this.addr
  %a = getelementptr inbounds %struct.C, %struct.C* %this1, i32 0, i32 0
  %1 = load %struct.C*, %struct.C** %.addr, align 8
  %a2 = getelementptr inbounds %struct.C, %struct.C* %1, i32 0, i32 0
  %2 = bitcast %struct.A* %a to i8*
  %3 = bitcast %struct.A* %a2 to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %3, i64 4, i32 4, i1 false)
  %b = getelementptr inbounds %struct.C, %struct.C* %this1, i32 0, i32 1
  %4 = load %struct.C*, %struct.C** %.addr, align 8
  %b3 = getelementptr inbounds %struct.C, %struct.C* %4, i32 0, i32 1
  call void @_ZN1BC1ERKS_(%struct.B* %b, %struct.B* dereferenceable(1) %b3)
  %a4 = getelementptr inbounds %struct.C, %struct.C* %this1, i32 0, i32 0
  %5 = load %struct.C*, %struct.C** %.addr, align 8
  %a5 = getelementptr inbounds %struct.C, %struct.C* %5, i32 0, i32 0
  %6 = bitcast %struct.A* %a4 to i8*
  %7 = bitcast %struct.A* %a5 to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %6, i8* %7, i64 4, i32 4, i1 false)
  ret void
}

As you can see, there's an extra initialization of memcpy-able member C.a.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150622/8275c3a4/attachment.html>


More information about the llvm-bugs mailing list