[LLVMbugs] [Bug 23924] New: Clang exception handling: wrong IR generation for aggregated members' destructors calls during stack unwinding

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Jun 23 04:10:02 PDT 2015


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

            Bug ID: 23924
           Summary: Clang exception handling: wrong IR generation for
                    aggregated members' destructors calls during stack
                    unwinding
           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 14508
  --> https://llvm.org/bugs/attachment.cgi?id=14508&action=edit
Generated IR code

When compiling the following test:

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

struct B {
  int y;
  B() { y = 15; }
  B(const B &other) {
    y = 25;
    throw 1;
  }
};

struct C {
  int z; // memcpy-able member
  A a;   // memcpy-able member
  B b;   // explicit copy ctor
};

int main() {
  try {
    C c1;
    C c2(c1);
  } catch (...) {
    return 1;
  }
  return 0;
}

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

$ clang -cc1 -fexceptions -fcxx-exceptions -O0 test.cpp -emit-llvm -o test.ll

; Function Attrs: inlinehint
define linkonce_odr void @_ZN1CC2ERKS_(%struct.C* %this, %struct.C*
dereferenceable(12)) unnamed_addr #1 comdat align 2 personality i8* bitcast
(i32 (...)* @__gxx_personality_v0 to i8*) {
entry:
  %this.addr = alloca %struct.C*, align 8
  %.addr = alloca %struct.C*, align 8
  %exn.slot = alloca i8*
  %ehselector.slot = alloca i32
  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
  %z = getelementptr inbounds %struct.C, %struct.C* %this1, i32 0, i32 0
  %1 = load %struct.C*, %struct.C** %.addr
  %z2 = getelementptr inbounds %struct.C, %struct.C* %1, i32 0, i32 0
  %2 = bitcast i32* %z to i8*
  %3 = bitcast i32* %z2 to i8*
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* %2, i8* %3, i64 8, i32 4, i1 false)
  %b = getelementptr inbounds %struct.C, %struct.C* %this1, i32 0, i32 2
  %4 = load %struct.C*, %struct.C** %.addr, align 8
  %b3 = getelementptr inbounds %struct.C, %struct.C* %4, i32 0, i32 2
  invoke void @_ZN1BC1ERKS_(%struct.B* %b, %struct.B* dereferenceable(4) %b3)
          to label %invoke.cont unwind label %lpad

invoke.cont:                                      ; preds = %entry
  ret void

lpad:                                             ; preds = %entry
  %5 = landingpad { i8*, i32 }
          cleanup
  %6 = extractvalue { i8*, i32 } %5, 0
  store i8* %6, i8** %exn.slot
  %7 = extractvalue { i8*, i32 } %5, 1
  store i32 %7, i32* %ehselector.slot
  %8 = bitcast %struct.C* %this1 to %struct.A*
  invoke void @_ZN1AD1Ev(%struct.A* %8)
          to label %invoke.cont.4 unwind label %terminate.lpad

invoke.cont.4:                                    ; preds = %lpad
  br label %eh.resume

eh.resume:                                        ; preds = %invoke.cont.4
  %exn = load i8*, i8** %exn.slot
  %sel = load i32, i32* %ehselector.slot
  %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn, 0
  %lpad.val.5 = insertvalue { i8*, i32 } %lpad.val, i32 %sel, 1
  resume { i8*, i32 } %lpad.val.5

terminate.lpad:                                   ; preds = %lpad
  %9 = landingpad { i8*, i32 }
          catch i8* null
  %10 = extractvalue { i8*, i32 } %9, 0
  call void @__clang_call_terminate(i8* %10) #5
  unreachable
}

As you can see, there's an instruction in %lpad block "%8 = bitcast %struct.C*
%this1 to %struct.A*", which prepares the address of member C.a to call its
destructor and is incorrect, because I believe it must be a "getelementptr
inbounds" instruction for this purpose.

I will handle this case.

Denis Zobnin
=============
Software Engineer
Intel Compiler Team
Intel

-- 
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/20150623/4065a0a5/attachment.html>


More information about the llvm-bugs mailing list