[LLVMbugs] [Bug 10895] New: throw() with -fno-exceptions generates worse code than throw(std::bad_alloc)

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Sep 8 12:24:18 PDT 2011


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

           Summary: throw() with -fno-exceptions generates worse code than
                    throw(std::bad_alloc)
           Product: clang
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: jmuizelaar at mozilla.com
                CC: llvmbugs at cs.uiuc.edu, dgregor at apple.com


Building the following with
clang -S -emit-llvm -fno-exceptions test.cc 

#include <new>

void* operator new(std::size_t size) throw();

struct Timer {
        virtual void Dance();

};

Timer *foo()
{
        Timer *t = new Timer;
        t->Dance();
        return t;
}

gives:

define %struct.Timer* @_Z3foov() nounwind uwtable ssp {
entry:
  %t = alloca %struct.Timer*, align 8
  %call = call noalias i8* @_Znwm(i64 8) nounwind
  %new.isnull = icmp eq i8* %call, null
  br i1 %new.isnull, label %new.cont, label %new.notnull

new.notnull:                                      ; preds = %entry
  %0 = bitcast i8* %call to %struct.Timer*
  call void @_ZN5TimerC1Ev(%struct.Timer* %0) nounwind
  br label %new.cont

new.cont:                                         ; preds = %new.notnull,
%entry
  %1 = phi %struct.Timer* [ %0, %new.notnull ], [ null, %entry ]
  store %struct.Timer* %1, %struct.Timer** %t, align 8
  %tmp = load %struct.Timer** %t, align 8
  %2 = bitcast %struct.Timer* %tmp to void (%struct.Timer*)***
  %vtable = load void (%struct.Timer*)*** %2
  %vfn = getelementptr inbounds void (%struct.Timer*)** %vtable, i64 0
  %3 = load void (%struct.Timer*)** %vfn
  call void %3(%struct.Timer* %tmp)
  %tmp1 = load %struct.Timer** %t, align 8
  ret %struct.Timer* %tmp1
}

with 'void* operator new(std::size_t size) throw(std::bad_alloc);' it gives the
better:

define %struct.Timer* @_Z3foov() nounwind uwtable ssp {
entry:
  %t = alloca %struct.Timer*, align 8
  %call = call noalias i8* @_Znwm(i64 8)
  %0 = bitcast i8* %call to %struct.Timer*
  call void @_ZN5TimerC1Ev(%struct.Timer* %0) nounwind
  store %struct.Timer* %0, %struct.Timer** %t, align 8
  %tmp = load %struct.Timer** %t, align 8
  %1 = bitcast %struct.Timer* %tmp to void (%struct.Timer*)***
  %vtable = load void (%struct.Timer*)*** %1
  %vfn = getelementptr inbounds void (%struct.Timer*)** %vtable, i64 0
  %2 = load void (%struct.Timer*)** %vfn
  call void %2(%struct.Timer* %tmp)
  %tmp1 = load %struct.Timer** %t, align 8
  ret %struct.Timer* %tmp1
}

-- 
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