unknown [load] impl: native for item
Using the recent emscripten code from incoming, I run into a compile error in -O2 (during the JS generation phase), reporting "unknown [load] impl: native for item" (from makeFuncLineActor in jsifier.js) when linking the LLVM bitcode from a large C++ code base. I could successfully narrow down the root cause to the following statements:
const int nbr_cnt = 4;
int x_del[nbr_cnt] = {-1, 0, 1, -1}, y_del[nbr_cnt] = {-1, -1, -1, 0};
When I replace the array definitions with a plain declaration:
int *x_del, *y_del;
the code compiles successfully (it would probably not run due to the missing array initialisation). Unfortunately, it turns out to be very hard to reproduce the issue. Just creating a stripped-down code snippet with these statements does not provoke the compile issue.
Similarly, the same compile error also occurs in another function on a statement:
ConComp **concomp_array = new ConComp *[seg_pt_cnt + 1];
where ConComp is a simple C++ class and seg_pt_cnt is an integer. Again, replacing the array definition with a plain declaration
ConComp **concomp_array;
resolves the compile issue. Again, I did not yet manage to reproduce the issue in a small test case.
For your reference, I have zipped up the emscripten_tmp directory for both errors containing the disassembled LLVM bitcode:
https://www.dropbox.com/sh/wneoqvkl4pa415d/xitsIUHo9W?m
In case of the first case (error1.zip), the statements from above are in a function "__ZNK9tesseract4Bmp812FindConCompsEPii", for the second error (error2.zip) the statement is in "__ZN9tesseract7ConComp7SegmentEiPi".
The LLVM disassembly of these functions is:
define internal %"class.tesseract::ConComp"** @_ZNK9tesseract4Bmp812FindConCompsEPii(%"class.tesseract::Bmp8"* nocapture %this, i32* nocapture %concomp_cnt, i32 %min_size) align 2 {
entry:
store i32 0, i32* %concomp_cnt, align 4
%wid_ = getelementptr inbounds %"class.tesseract::Bmp8"* %this, i32 0, i32 1
%0 = load i16* %wid_, align 2
%conv = zext i16 %0 to i32
%hgt_ = getelementptr inbounds %"class.tesseract::Bmp8"* %this, i32 0, i32 2
%1 = load i16* %hgt_, align 2
%conv2 = zext i16 %1 to i32
%umul_with_overflow = shl nuw nsw i32 %conv2, 4
%call.i = tail call noalias i8* @_Znaj(i32 %umul_with_overflow)
%2 = bitcast i8* %call.i to i32**
%tobool.i = icmp eq i8* %call.i, null
br i1 %tobool.i, label %if.then, label %if.end.i
if.end.i: ; preds = %entry
%mul1.i = shl nuw nsw i32 %conv, 2
%mul2.i = mul i32 %mul1.i, %conv2
%3 = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %mul2.i, i32 4)
%4 = extractvalue { i32, i1 } %3, 1
%5 = extractvalue { i32, i1 } %3, 0
%6 = select i1 %4, i32 -1, i32 %5
%call3.i = tail call noalias i8* @_Znaj(i32 %6)
%7 = bitcast i8* %call3.i to i32*
store i32* %7, i32** %2, align 4
%tobool5.i = icmp eq i8* %call3.i, null
br i1 %tobool5.i, label %if.then, label %if.end7.i
if.end7.i: ; preds = %if.end.i
tail call void @llvm.memset.p0i8.i32(i8* %call3.i, i8 0, i32 %mul2.i, i32 4, i1 false)
%cmp16.i = icmp ugt i16 %1, 1
br i1 %cmp16.i, label %for.body.i, label %for.cond.preheader
for.body.i: ; preds = %for.body.i, %if.end7.i
%8 = phi i32* [ %add.ptr.i, %for.body.i ], [ %7, %if.end7.i ]
%y.017.i = phi i32 [ %inc.i, %for.body.i ], [ 1, %if.end7.i ]
%add.ptr.i = getelementptr inbounds i32* %8, i32 %conv
%arrayidx12.i = getelementptr inbounds i32** %2, i32 %y.017.i
store i32* %add.ptr.i, i32** %arrayidx12.i, align 4
%inc.i = add nsw i32 %y.017.i, 1
%exitcond.i = icmp eq i32 %inc.i, %conv2
br i1 %exitcond.i, label %for.cond.preheader, label %for.body.i
for.cond.preheader: ; preds = %for.body.i, %if.end7.i
%9 = load i16* %hgt_, align 2
%cmp6250 = icmp eq i16 %9, 0
br i1 %cmp6250, label %if.then.i100, label %for.cond7.preheader.lr.ph
for.cond7.preheader.lr.ph: ; preds = %for.cond.preheader
%line_buff_ = getelementptr inbounds %"class.tesseract::Bmp8"* %this, i32 0, i32 3
%.pre = load i16* %wid_, align 2
br label %for.cond7.preheader
if.then: ; preds = %if.end.i, %entry
%10 = load %struct.__sFILE** @stderr, align 4
%11 = tail call i32 @fwrite(i8* getelementptr inbounds ([66 x i8]* @.str2451, i32 0, i32 0), i32 65, i32 1, %struct.__sFILE* %10)
br label %return
for.cond7.preheader: ; preds = %for.inc129, %for.cond7.preheader.lr.ph
%12 = phi i16 [ %9, %for.cond7.preheader.lr.ph ], [ %107, %for.inc129 ]
%13 = phi i16 [ %.pre, %for.cond7.preheader.lr.ph ], [ %108, %for.inc129 ]
%concomp_array.0254 = phi %"class.tesseract::ConComp"** [ null, %for.cond7.preheader.lr.ph ], [ %concomp_array.1.lcssa, %for.inc129 ]
%y.0252 = phi i32 [ 0, %for.cond7.preheader.lr.ph ], [ %inc130, %for.inc129 ]
%alloc_concomp_cnt.0251 = phi i32 [ 0, %for.cond7.preheader.lr.ph ], [ %alloc_concomp_cnt.1.lcssa, %for.inc129 ]
%cmp10228 = icmp eq i16 %13, 0
br i1 %cmp10228, label %for.inc129, label %for.body11.lr.ph
for.body11.lr.ph: ; preds = %for.cond7.preheader
%arrayidx77 = getelementptr inbounds i32** %2, i32 %y.0252
br label %for.body11
for.body11: ; preds = %for.inc126, %for.body11.lr.ph
%concomp_array.1232 = phi %"class.tesseract::ConComp"** [ %concomp_array.0254, %for.body11.lr.ph ], [ %concomp_array.3, %for.inc126 ]
%x.0230 = phi i32 [ 0, %for.body11.lr.ph ], [ %inc127, %for.inc126 ]
%alloc_concomp_cnt.1229 = phi i32 [ %alloc_concomp_cnt.0251, %for.body11.lr.ph ], [ %alloc_concomp_cnt.2, %for.inc126 ]
%14 = load i8*** %line_buff_, align 4
%arrayidx = getelementptr inbounds i8** %14, i32 %y.0252
%15 = load i8** %arrayidx, align 4
%arrayidx12 = getelementptr inbounds i8* %15, i32 %x.0230
%16 = load i8* %arrayidx12, align 1
%cmp14 = icmp eq i8 %16, -1
br i1 %cmp14, label %for.inc126, label %for.body18
for.body18: ; preds = %for.inc, %for.body11
%nbr.0211 = phi i32 [ %inc, %for.inc ], [ 0, %for.body11 ]
%master_concomp.0210 = phi %"class.tesseract::ConComp"* [ %master_concomp.1, %for.inc ], [ null, %for.body11 ]
%master_concomp_id.0209 = phi i32 [ %master_concomp_id.1, %for.inc ], [ 0, %for.body11 ]
%arrayidx19 = getelementptr inbounds [4 x i32]* @_ZZNK9tesseract4Bmp812FindConCompsEPiiE5x_del, i32 0, i32 %nbr.0211
%17 = load i32* %arrayidx19, align 4
%add = add nsw i32 %17, %x.0230
%arrayidx20 = getelementptr inbounds [4 x i32]* @_ZZNK9tesseract4Bmp812FindConCompsEPiiE5y_del, i32 0, i32 %nbr.0211
%18 = load i32* %arrayidx20, align 4
%add21 = add nsw i32 %18, %y.0252
%19 = or i32 %add21, %add
%20 = icmp slt i32 %19, 0
br i1 %20, label %for.inc, label %lor.lhs.false24
lor.lhs.false24: ; preds = %for.body18
%21 = load i16* %wid_, align 2
%conv26 = zext i16 %21 to i32
%cmp27 = icmp slt i32 %add, %conv26
br i1 %cmp27, label %lor.lhs.false28, label %for.inc
lor.lhs.false28: ; preds = %lor.lhs.false24
%22 = load i16* %hgt_, align 2
%conv30 = zext i16 %22 to i32
%cmp31 = icmp slt i32 %add21, %conv30
br i1 %cmp31, label %if.end33, label %for.inc
if.end33: ; preds = %lor.lhs.false28
%23 = load i8*** %line_buff_, align 4
%arrayidx35 = getelementptr inbounds i8** %23, i32 %add21
%24 = load i8** %arrayidx35, align 4
%arrayidx36 = getelementptr inbounds i8* %24, i32 %add
%25 = load i8* %arrayidx36, align 1
%cmp38 = icmp eq i8 %25, -1
br i1 %cmp38, label %for.inc, label %if.then39
if.then39: ; preds = %if.end33
%arrayidx40 = getelementptr inbounds i32** %2, i32 %add21
%26 = load i32** %arrayidx40, align 4
%arrayidx41 = getelementptr inbounds i32* %26, i32 %add
%27 = load i32* %arrayidx41, align 4
%cmp42 = icmp slt i32 %27, 1
%cmp44 = icmp sgt i32 %27, %alloc_concomp_cnt.1229
%or.cond94 = or i1 %cmp42, %cmp44
br i1 %or.cond94, label %if.then45, label %if.end47
if.then45: ; preds = %if.then39
%28 = load %struct.__sFILE** @stderr, align 4
%call46 = tail call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %28, i8* getelementptr inbounds ([69 x i8]* @.str12452, i32 0, i32 0), i32 %27)
%29 = load i32** %2, align 4
%cmp1.i = icmp eq i32* %29, null
br i1 %cmp1.i, label %delete.notnull5.i, label %delete.notnull.i
delete.notnull.i: ; preds = %if.then45
%30 = bitcast i32* %29 to i8*
tail call void @_ZdaPv(i8* %30) nounwind
br label %delete.notnull5.i
delete.notnull5.i: ; preds = %delete.notnull.i, %if.then45
tail call void @_ZdaPv(i8* %call.i) nounwind
%isnull = icmp eq %"class.tesseract::ConComp"** %concomp_array.1232, null
br i1 %isnull, label %return, label %delete.notnull
delete.notnull: ; preds = %delete.notnull5.i
%31 = bitcast %"class.tesseract::ConComp"** %concomp_array.1232 to i8*
tail call void @_ZdaPv(i8* %31) nounwind
br label %return
if.end47: ; preds = %if.then39
%cmp48 = icmp eq %"class.tesseract::ConComp"* %master_concomp.0210, null
%cmp49 = icmp eq i32 %27, %master_concomp_id.0209
%or.cond95 = or i1 %cmp48, %cmp49
%sub75 = add nsw i32 %27, -1
%arrayidx76 = getelementptr inbounds %"class.tesseract::ConComp"** %concomp_array.1232, i32 %sub75
%32 = load %"class.tesseract::ConComp"** %arrayidx76, align 4
br i1 %or.cond95, label %if.else, label %if.then50
if.then50: ; preds = %if.end47
%head_.i = getelementptr inbounds %"class.tesseract::ConComp"* %32, i32 0, i32 8
%pt_ptr.0201 = load %"class.tesseract::ConCompPt"** %head_.i, align 4
%cmp53202 = icmp eq %"class.tesseract::ConCompPt"* %pt_ptr.0201, null
br i1 %cmp53202, label %while.end, label %while.body
while.body: ; preds = %while.body, %if.then50
%pt_ptr.0203 = phi %"class.tesseract::ConCompPt"* [ %pt_ptr.0, %while.body ], [ %pt_ptr.0201, %if.then50 ]
%x_.i = getelementptr inbounds %"class.tesseract::ConCompPt"* %pt_ptr.0203, i32 0, i32 0
%33 = load i32* %x_.i, align 4
%y_.i = getelementptr inbounds %"class.tesseract::ConCompPt"* %pt_ptr.0203, i32 0, i32 1
%34 = load i32* %y_.i, align 4
%arrayidx56 = getelementptr inbounds i32** %2, i32 %34
%35 = load i32** %arrayidx56, align 4
%arrayidx57 = getelementptr inbounds i32* %35, i32 %33
store i32 %master_concomp_id.0209, i32* %arrayidx57, align 4
%next_pt_.i = getelementptr inbounds %"class.tesseract::ConCompPt"* %pt_ptr.0203, i32 0, i32 2
%pt_ptr.0 = load %"class.tesseract::ConCompPt"** %next_pt_.i, align 4
%cmp53 = icmp eq %"class.tesseract::ConCompPt"* %pt_ptr.0, null
br i1 %cmp53, label %while.cond.while.end_crit_edge, label %while.body
while.cond.while.end_crit_edge: ; preds = %while.body
%.pre275 = load %"class.tesseract::ConComp"** %arrayidx76, align 4
br label %while.end
while.end: ; preds = %while.cond.while.end_crit_edge, %if.then50
%36 = phi %"class.tesseract::ConComp"* [ %.pre275, %while.cond.while.end_crit_edge ], [ %32, %if.then50 ]
%head_.i105 = getelementptr inbounds %"class.tesseract::ConComp"* %master_concomp.0210, i32 0, i32 8
%37 = load %"class.tesseract::ConCompPt"** %head_.i105, align 4
%cmp.i106 = icmp eq %"class.tesseract::ConCompPt"* %37, null
br i1 %cmp.i106, label %if.then62, label %lor.lhs.false.i
lor.lhs.false.i: ; preds = %while.end
%tail_.i = getelementptr inbounds %"class.tesseract::ConComp"* %master_concomp.0210, i32 0, i32 9
%38 = load %"class.tesseract::ConCompPt"** %tail_.i, align 4
%cmp2.i = icmp eq %"class.tesseract::ConCompPt"* %38, null
br i1 %cmp2.i, label %if.then62, label %lor.lhs.false3.i
lor.lhs.false3.i: ; preds = %lor.lhs.false.i
%head_4.i = getelementptr inbounds %"class.tesseract::ConComp"* %36, i32 0, i32 8
%39 = load %"class.tesseract::ConCompPt"** %head_4.i, align 4
%cmp5.i = icmp eq %"class.tesseract::ConCompPt"* %39, null
br i1 %cmp5.i, label %if.then62, label %lor.lhs.false6.i
lor.lhs.false6.i: ; preds = %lor.lhs.false3.i
%tail_7.i = getelementptr inbounds %"class.tesseract::ConComp"* %36, i32 0, i32 9
%40 = load %"class.tesseract::ConCompPt"** %tail_7.i, align 4
%cmp8.i = icmp eq %"class.tesseract::ConCompPt"* %40, null
br i1 %cmp8.i, label %if.then62, label %if.end67
if.then62: ; preds = %lor.lhs.false6.i, %lor.lhs.false3.i, %lor.lhs.false.i, %while.end
%41 = load %struct.__sFILE** @stderr, align 4
%call63 = tail call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %41, i8* getelementptr inbounds ([74 x i8]* @.str22453, i32 0, i32 0), i32 %27)
%42 = load i32** %2, align 4
%cmp1.i111 = icmp eq i32* %42, null
br i1 %cmp1.i111, label %delete.notnull5.i114, label %delete.notnull.i113
delete.notnull.i113: ; preds = %if.then62
%43 = bitcast i32* %42 to i8*
tail call void @_ZdaPv(i8* %43) nounwind
br label %delete.notnull5.i114
delete.notnull5.i114: ; preds = %delete.notnull.i113, %if.then62
tail call void @_ZdaPv(i8* %call.i) nounwind
%isnull64 = icmp eq %"class.tesseract::ConComp"** %concomp_array.1232, null
br i1 %isnull64, label %return, label %delete.notnull65
delete.notnull65: ; preds = %delete.notnull5.i114
%44 = bitcast %"class.tesseract::ConComp"** %concomp_array.1232 to i8*
tail call void @_ZdaPv(i8* %44) nounwind
br label %return
if.end67: ; preds = %lor.lhs.false6.i
%next_pt_.i.i = getelementptr inbounds %"class.tesseract::ConCompPt"* %38, i32 0, i32 2
store %"class.tesseract::ConCompPt"* %39, %"class.tesseract::ConCompPt"** %next_pt_.i.i, align 4
%45 = load %"class.tesseract::ConCompPt"** %tail_7.i, align 4
store %"class.tesseract::ConCompPt"* %45, %"class.tesseract::ConCompPt"** %tail_.i, align 4
%left_.i = getelementptr inbounds %"class.tesseract::ConComp"* %master_concomp.0210, i32 0, i32 4
%46 = load i32* %left_.i, align 4
%left_13.i = getelementptr inbounds %"class.tesseract::ConComp"* %36, i32 0, i32 4
%47 = load i32* %left_13.i, align 4
%cmp14.i = icmp sgt i32 %46, %47
%..i = select i1 %cmp14.i, i32 %47, i32 %46
store i32 %..i, i32* %left_.i, align 4
%top_.i = getelementptr inbounds %"class.tesseract::ConComp"* %master_concomp.0210, i32 0, i32 5
%48 = load i32* %top_.i, align 4
%top_18.i = getelementptr inbounds %"class.tesseract::ConComp"* %36, i32 0, i32 5
%49 = load i32* %top_18.i, align 4
%cmp19.i = icmp sgt i32 %48, %49
%cond25.i = select i1 %cmp19.i, i32 %49, i32 %48
store i32 %cond25.i, i32* %top_.i, align 4
%right_.i = getelementptr inbounds %"class.tesseract::ConComp"* %master_concomp.0210, i32 0, i32 6
%50 = load i32* %right_.i, align 4
%right_27.i = getelementptr inbounds %"class.tesseract::ConComp"* %36, i32 0, i32 6
%51 = load i32* %right_27.i, align 4
%cmp28.i = icmp slt i32 %50, %51
%.15.i = select i1 %cmp28.i, i32 %51, i32 %50
store i32 %.15.i, i32* %right_.i, align 4
%bottom_.i = getelementptr inbounds %"class.tesseract::ConComp"* %master_concomp.0210, i32 0, i32 7
%52 = load i32* %bottom_.i, align 4
%bottom_36.i = getelementptr inbounds %"class.tesseract::ConComp"* %36, i32 0, i32 7
%53 = load i32* %bottom_36.i, align 4
%cmp37.i = icmp slt i32 %52, %53
%cond43.i = select i1 %cmp37.i, i32 %53, i32 %52
store i32 %cond43.i, i32* %bottom_.i, align 4
%pt_cnt_.i107 = getelementptr inbounds %"class.tesseract::ConComp"* %36, i32 0, i32 10
%54 = load i32* %pt_cnt_.i107, align 4
%pt_cnt_45.i = getelementptr inbounds %"class.tesseract::ConComp"* %master_concomp.0210, i32 0, i32 10
%55 = load i32* %pt_cnt_45.i, align 4
%add.i = add nsw i32 %55, %54
store i32 %add.i, i32* %pt_cnt_45.i, align 4
store %"class.tesseract::ConCompPt"* null, %"class.tesseract::ConCompPt"** %head_4.i, align 4
store %"class.tesseract::ConCompPt"* null, %"class.tesseract::ConCompPt"** %tail_7.i, align 4
%56 = load %"class.tesseract::ConComp"** %arrayidx76, align 4
%isnull70 = icmp eq %"class.tesseract::ConComp"* %56, null
br i1 %isnull70, label %delete.end72, label %delete.notnull71
delete.notnull71: ; preds = %if.end67
%57 = bitcast %"class.tesseract::ConComp"* %56 to void (%"class.tesseract::ConComp"*)***
%vtable = load void (%"class.tesseract::ConComp"*)*** %57, align 4
%vfn = getelementptr inbounds void (%"class.tesseract::ConComp"*)** %vtable, i32 1
%58 = load void (%"class.tesseract::ConComp"*)** %vfn, align 4
tail call void %58(%"class.tesseract::ConComp"* %56)
br label %delete.end72
delete.end72: ; preds = %delete.notnull71, %if.end67
store %"class.tesseract::ConComp"* null, %"class.tesseract::ConComp"** %arrayidx76, align 4
br label %for.inc
if.else: ; preds = %if.end47
%59 = load i32** %arrayidx77, align 4
%arrayidx78 = getelementptr inbounds i32* %59, i32 %x.0230
store i32 %27, i32* %arrayidx78, align 4
%call.i117 = tail call noalias i8* @_Znwj(i32 12)
%60 = bitcast i8* %call.i117 to %"class.tesseract::ConCompPt"*
%x_.i.i.i = bitcast i8* %call.i117 to i32*
store i32 %x.0230, i32* %x_.i.i.i, align 4
%y_.i.i.i = getelementptr inbounds i8* %call.i117, i32 4
%61 = bitcast i8* %y_.i.i.i to i32*
store i32 %y.0252, i32* %61, align 4
%next_pt_.i.i.i = getelementptr inbounds i8* %call.i117, i32 8
%62 = bitcast i8* %next_pt_.i.i.i to %"class.tesseract::ConCompPt"**
store %"class.tesseract::ConCompPt"* null, %"class.tesseract::ConCompPt"** %62, align 4
%cmp.i118 = icmp eq i8* %call.i117, null
br i1 %cmp.i118, label %if.then80, label %if.end.i122
if.end.i122: ; preds = %if.else
%head_.i119 = getelementptr inbounds %"class.tesseract::ConComp"* %32, i32 0, i32 8
%63 = load %"class.tesseract::ConCompPt"** %head_.i119, align 4
%cmp2.i120 = icmp eq %"class.tesseract::ConCompPt"* %63, null
%left_.i121 = getelementptr inbounds %"class.tesseract::ConComp"* %32, i32 0, i32 4
br i1 %cmp2.i120, label %if.then3.i, label %if.else.i
if.then3.i: ; preds = %if.end.i122
store i32 %x.0230, i32* %left_.i121, align 4
%right_.i123 = getelementptr inbounds %"class.tesseract::ConComp"* %32, i32 0, i32 6
store i32 %x.0230, i32* %right_.i123, align 4
%top_.i124 = getelementptr inbounds %"class.tesseract::ConComp"* %32, i32 0, i32 5
store i32 %y.0252, i32* %top_.i124, align 4
%bottom_.i125 = getelementptr inbounds %"class.tesseract::ConComp"* %32, i32 0, i32 7
store i32 %y.0252, i32* %bottom_.i125, align 4
store %"class.tesseract::ConCompPt"* %60, %"class.tesseract::ConCompPt"** %head_.i119, align 4
br label %if.end33.i
if.else.i: ; preds = %if.end.i122
%64 = load i32* %left_.i121, align 4
%cmp6.i = icmp sgt i32 %64, %x.0230
%x..i = select i1 %cmp6.i, i32 %x.0230, i32 %64
store i32 %x..i, i32* %left_.i121, align 4
%top_9.i = getelementptr inbounds %"class.tesseract::ConComp"* %32, i32 0, i32 5
%65 = load i32* %top_9.i, align 4
%cmp10.i = icmp sgt i32 %65, %y.0252
%cond15.i = select i1 %cmp10.i, i32 %y.0252, i32 %65
store i32 %cond15.i, i32* %top_9.i, align 4
%right_17.i = getelementptr inbounds %"class.tesseract::ConComp"* %32, i32 0, i32 6
%66 = load i32* %right_17.i, align 4
%cmp18.i = icmp slt i32 %66, %x.0230
%x.16.i = select i1 %cmp18.i, i32 %x.0230, i32 %66
store i32 %x.16.i, i32* %right_17.i, align 4
%bottom_25.i = getelementptr inbounds %"class.tesseract::ConComp"* %32, i32 0, i32 7
%67 = load i32* %bottom_25.i, align 4
%cmp26.i = icmp slt i32 %67, %y.0252
%cond31.i = select i1 %cmp26.i, i32 %y.0252, i32 %67
store i32 %cond31.i, i32* %bottom_25.i, align 4
br label %if.end33.i
if.end33.i: ; preds = %if.else.i, %if.then3.i
%tail_.i126 = getelementptr inbounds %"class.tesseract::ConComp"* %32, i32 0, i32 9
%68 = load %"class.tesseract::ConCompPt"** %tail_.i126, align 4
%cmp34.i = icmp eq %"class.tesseract::ConCompPt"* %68, null
br i1 %cmp34.i, label %_ZN9tesseract7ConComp3AddEii.exit.thread, label %if.then35.i
if.then35.i: ; preds = %if.end33.i
%next_pt_.i.i127 = getelementptr inbounds %"class.tesseract::ConCompPt"* %68, i32 0, i32 2
store %"class.tesseract::ConCompPt"* %60, %"class.tesseract::ConCompPt"** %next_pt_.i.i127, align 4
br label %_ZN9tesseract7ConComp3AddEii.exit.thread
_ZN9tesseract7ConComp3AddEii.exit.thread: ; preds = %if.then35.i, %if.end33.i
store %"class.tesseract::ConCompPt"* %60, %"class.tesseract::ConCompPt"** %tail_.i126, align 4
%pt_cnt_.i128 = getelementptr inbounds %"class.tesseract::ConComp"* %32, i32 0, i32 10
%69 = load i32* %pt_cnt_.i128, align 4
%inc.i129 = add nsw i32 %69, 1
store i32 %inc.i129, i32* %pt_cnt_.i128, align 4
br label %for.inc
if.then80: ; preds = %if.else
%70 = load %struct.__sFILE** @stderr, align 4
%call81 = tail call i32 (%struct.__sFILE*, i8*, ...)* @fprintf(%struct.__sFILE* %70, i8* getelementptr inbounds ([76 x i8]* @.str32454, i32 0, i32 0), i32 %x.0230, i32 %y.0252)
%71 = load i32** %2, align 4
%cmp1.i132 = icmp eq i32* %71, null
br i1 %cmp1.i132, label %delete.notnull5.i135.thread, label %delete.notnull5.i135
delete.notnull5.i135.thread: ; preds = %if.then80
tail call void @_ZdaPv(i8* %call.i) nounwind
br label %delete.notnull83
delete.notnull5.i135: ; preds = %if.then80
%72 = bitcast i32* %71 to i8*
tail call void @_ZdaPv(i8* %72) nounwind
tail call void @_ZdaPv(i8* %call.i) nounwind
br label %delete.notnull83
delete.notnull83: ; preds = %delete.notnull5.i135, %delete.notnull5.i135.thread
%73 = bitcast %"class.tesseract::ConComp"** %concomp_array.1232 to i8*
tail call void @_ZdaPv(i8* %73) nounwind
br label %return
for.inc: ; preds = %_ZN9tesseract7ConComp3AddEii.exit.thread, %delete.end72, %if.end33, %lor.lhs.false28, %lor.lhs.false24, %for.body18
%master_concomp_id.1 = phi i32 [ %master_concomp_id.0209, %for.body18 ], [ %master_concomp_id.0209, %lor.lhs.false24 ], [ %master_concomp_id.0209, %lor.lhs.false28 ], [ %master_concomp_id.0209, %delete.end72 ], [ %master_concomp_id.0209, %if.end33 ], [ %27, %_ZN9tesseract7ConComp3AddEii.exit.thread ]
%master_concomp.1 = phi %"class.tesseract::ConComp"* [ %master_concomp.0210, %for.body18 ], [ %master_concomp.0210, %lor.lhs.false24 ], [ %master_concomp.0210, %lor.lhs.false28 ], [ %master_concomp.0210, %delete.end72 ], [ %master_concomp.0210, %if.end33 ], [ %32, %_ZN9tesseract7ConComp3AddEii.exit.thread ]
%inc = add nsw i32 %nbr.0211, 1
%cmp17 = icmp slt i32 %inc, 4
br i1 %cmp17, label %for.body18, label %for.end
for.end: ; preds = %for.inc
%cmp88 = icmp eq %"class.tesseract::ConComp"* %master_concomp.1, null
br i1 %cmp88, label %if.then89, label %for.inc126
if.then89: ; preds = %for.end
%call90 = tail call noalias i8* @_Znwj(i32 40)
%74 = bitcast i8* %call90 to %"class.tesseract::ConComp"*
%75 = bitcast i8* %call90 to i32 (...)***
store i32 (...)** bitcast (i8** getelementptr inbounds ([4 x i8*]* @_ZTVN9tesseract7ConCompE, i32 0, i32 2) to i32 (...)**), i32 (...)*** %75, align 4
%left_.i138 = getelementptr inbounds i8* %call90, i32 12
%76 = bitcast i8* %left_.i138 to i32*
%77 = getelementptr inbounds i8* %call90, i32 8
store i8 0, i8* %77, align 1
%78 = getelementptr inbounds i8* %call90, i32 9
store i8 0, i8* %78, align 1
%id_.i141 = getelementptr inbounds i8* %call90, i32 4
%79 = bitcast i8* %id_.i141 to i32*
tail call void @llvm.memset.p0i8.i64(i8* %left_.i138, i8 0, i64 24, i32 4, i1 false) nounwind
store i32 -1, i32* %79, align 4
%pt_cnt_.i142 = getelementptr inbounds i8* %call90, i32 36
%80 = bitcast i8* %pt_cnt_.i142 to i32*
store i32 0, i32* %80, align 4
%cmp91 = icmp eq i8* %call90, null
br i1 %cmp91, label %if.then96, label %lor.lhs.false92
lor.lhs.false92: ; preds = %if.then89
%call.i143 = tail call noalias i8* @_Znwj(i32 12)
%81 = bitcast i8* %call.i143 to %"class.tesseract::ConCompPt"*
%x_.i.i.i144 = bitcast i8* %call.i143 to i32*
store i32 %x.0230, i32* %x_.i.i.i144, align 4
%y_.i.i.i145 = getelementptr inbounds i8* %call.i143, i32 4
%82 = bitcast i8* %y_.i.i.i145 to i32*
store i32 %y.0252, i32* %82, align 4
%next_pt_.i.i.i146 = getelementptr inbounds i8* %call.i143, i32 8
%83 = bitcast i8* %next_pt_.i.i.i146 to %"class.tesseract::ConCompPt"**
store %"class.tesseract::ConCompPt"* null, %"class.tesseract::ConCompPt"** %83, align 4
%cmp.i147 = icmp eq i8* %call.i143, null
br i1 %cmp.i147, label %if.then96, label %if.end101
if.then96: ; preds = %lor.lhs.false92, %if.then89
%84 = load %struct.__sFILE** @stderr, align 4
%85 = tail call i32 @fwrite(i8* getelementptr inbounds ([82 x i8]* @.str42455, i32 0, i32 0), i32 81, i32 1, %struct.__sFILE* %84)
%86 = load i32** %2, align 4
%cmp1.i179 = icmp eq i32* %86, null
br i1 %cmp1.i179, label %delete.notnull5.i182, label %delete.notnull.i181
delete.notnull.i181: ; preds = %if.then96
%87 = bitcast i32* %86 to i8*
tail call void @_ZdaPv(i8* %87) nounwind
br label %delete.notnull5.i182
delete.notnull5.i182: ; preds = %delete.notnull.i181, %if.then96
tail call void @_ZdaPv(i8* %call.i) nounwind
%isnull98 = icmp eq %"class.tesseract::ConComp"** %concomp_array.1232, null
br i1 %isnull98, label %return, label %delete.notnull99
delete.notnull99: ; preds = %delete.notnull5.i182
%88 = bitcast %"class.tesseract::ConComp"** %concomp_array.1232 to i8*
tail call void @_ZdaPv(i8* %88) nounwind
br label %return
if.end101: ; preds = %lor.lhs.false92
%head_.i148 = getelementptr inbounds i8* %call90, i32 28
%89 = bitcast i8* %head_.i148 to %"class.tesseract::ConCompPt"**
store i32 %x.0230, i32* %76, align 4
%right_.i152 = getelementptr inbounds i8* %call90, i32 20
%90 = bitcast i8* %right_.i152 to i32*
store i32 %x.0230, i32* %90, align 4
%top_.i153 = getelementptr inbounds i8* %call90, i32 16
%91 = bitcast i8* %top_.i153 to i32*
store i32 %y.0252, i32* %91, align 4
%bottom_.i154 = getelementptr inbounds i8* %call90, i32 24
%92 = bitcast i8* %bottom_.i154 to i32*
store i32 %y.0252, i32* %92, align 4
store %"class.tesseract::ConCompPt"* %81, %"class.tesseract::ConCompPt"** %89, align 4
%tail_.i168 = getelementptr inbounds i8* %call90, i32 32
%93 = bitcast i8* %tail_.i168 to %"class.tesseract::ConCompPt"**
store %"class.tesseract::ConCompPt"* %81, %"class.tesseract::ConCompPt"** %93, align 4
store i32 1, i32* %80, align 4
%rem93 = and i32 %alloc_concomp_cnt.1229, 15
%cmp102 = icmp eq i32 %rem93, 0
br i1 %cmp102, label %if.then103, label %if.end119
if.then103: ; preds = %if.end101
%add104 = add nsw i32 %alloc_concomp_cnt.1229, 16
%94 = tail call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %add104, i32 4)
%95 = extractvalue { i32, i1 } %94, 1
%96 = extractvalue { i32, i1 } %94, 0
%97 = select i1 %95, i32 -1, i32 %96
%call105 = tail call noalias i8* @_Znaj(i32 %97)
%98 = bitcast i8* %call105 to %"class.tesseract::ConComp"**
%cmp106 = icmp eq i8* %call105, null
br i1 %cmp106, label %if.then107, label %if.end112
if.then107: ; preds = %if.then103
%99 = load %struct.__sFILE** @stderr, align 4
%100 = tail call i32 @fwrite(i8* getelementptr inbounds ([81 x i8]* @.str5966, i32 0, i32 0), i32 80, i32 1, %struct.__sFILE* %99)
%101 = load i32** %2, align 4
%cmp1.i186 = icmp eq i32* %101, null
br i1 %cmp1.i186, label %delete.notnull5.i189, label %delete.notnull.i188
delete.notnull.i188: ; preds = %if.then107
%102 = bitcast i32* %101 to i8*
tail call void @_ZdaPv(i8* %102) nounwind
br label %delete.notnull5.i189
delete.notnull5.i189: ; preds = %delete.notnull.i188, %if.then107
tail call void @_ZdaPv(i8* %call.i) nounwind
%isnull109 = icmp eq %"class.tesseract::ConComp"** %concomp_array.1232, null
br i1 %isnull109, label %return, label %delete.notnull110
delete.notnull110: ; preds = %delete.notnull5.i189
%103 = bitcast %"class.tesseract::ConComp"** %concomp_array.1232 to i8*
tail call void @_ZdaPv(i8* %103) nounwind
br label %return
if.end112: ; preds = %if.then103
%cmp113 = icmp sgt i32 %alloc_concomp_cnt.1229, 0
br i1 %cmp113, label %if.then114, label %if.end119
if.then114: ; preds = %if.end112
%104 = bitcast %"class.tesseract::ConComp"** %concomp_array.1232 to i8*
%mul = shl i32 %alloc_concomp_cnt.1229, 2
tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %call105, i8* %104, i32 %mul, i32 4, i1 false)
%isnull115 = icmp eq %"class.tesseract::ConComp"** %concomp_array.1232, null
br i1 %isnull115, label %if.end119, label %delete.notnull116
delete.notnull116: ; preds = %if.then114
tail call void @_ZdaPv(i8* %104) nounwind
br label %if.end119
if.end119: ; preds = %delete.notnull116, %if.then114, %if.end112, %if.end101
%concomp_array.2 = phi %"class.tesseract::ConComp"** [ %concomp_array.1232, %if.end101 ], [ %98, %if.then114 ], [ %98, %delete.notnull116 ], [ %98, %if.end112 ]
%inc120 = add nsw i32 %alloc_concomp_cnt.1229, 1
%arrayidx121 = getelementptr inbounds %"class.tesseract::ConComp"** %concomp_array.2, i32 %alloc_concomp_cnt.1229
store %"class.tesseract::ConComp"* %74, %"class.tesseract::ConComp"** %arrayidx121, align 4
%105 = load i32** %arrayidx77, align 4
%arrayidx123 = getelementptr inbounds i32* %105, i32 %x.0230
store i32 %inc120, i32* %arrayidx123, align 4
br label %for.inc126
for.inc126: ; preds = %if.end119, %for.end, %for.body11
%alloc_concomp_cnt.2 = phi i32 [ %inc120, %if.end119 ], [ %alloc_concomp_cnt.1229, %for.body11 ], [ %alloc_concomp_cnt.1229, %for.end ]
%concomp_array.3 = phi %"class.tesseract::ConComp"** [ %concomp_array.2, %if.end119 ], [ %concomp_array.1232, %for.body11 ], [ %concomp_array.1232, %for.end ]
%inc127 = add nsw i32 %x.0230, 1
%106 = load i16* %wid_, align 2
%conv9 = zext i16 %106 to i32
%cmp10 = icmp slt i32 %inc127, %conv9
br i1 %cmp10, label %for.body11, label %for.cond7.for.inc129_crit_edge
for.cond7.for.inc129_crit_edge: ; preds = %for.inc126
%.pre274 = load i16* %hgt_, align 2
br label %for.inc129
for.inc129: ; preds = %for.cond7.for.inc129_crit_edge, %for.cond7.preheader
%107 = phi i16 [ %.pre274, %for.cond7.for.inc129_crit_edge ], [ %12, %for.cond7.preheader ]
%108 = phi i16 [ %106, %for.cond7.for.inc129_crit_edge ], [ 0, %for.cond7.preheader ]
%concomp_array.1.lcssa = phi %"class.tesseract::ConComp"** [ %concomp_array.3, %for.cond7.for.inc129_crit_edge ], [ %concomp_array.0254, %for.cond7.preheader ]
%alloc_concomp_cnt.1.lcssa = phi i32 [ %alloc_concomp_cnt.2, %for.cond7.for.inc129_crit_edge ], [ %alloc_concomp_cnt.0251, %for.cond7.preheader ]
%inc130 = add nsw i32 %y.0252, 1
%conv5 = zext i16 %107 to i32
%cmp6 = icmp slt i32 %inc130, %conv5
br i1 %cmp6, label %for.cond7.preheader, label %if.then.i100
if.then.i100: ; preds = %for.inc129, %for.cond.preheader
%concomp_array.0.lcssa = phi %"class.tesseract::ConComp"** [ null, %for.cond.preheader ], [ %concomp_array.1.lcssa, %for.inc129 ]
%alloc_concomp_cnt.0.lcssa = phi i32 [ 0, %for.cond.preheader ], [ %alloc_concomp_cnt.1.lcssa, %for.inc129 ]
%109 = load i32** %2, align 4
%cmp1.i99 = icmp eq i32* %109, null
br i1 %cmp1.i99, label %delete.notnull5.i102, label %delete.notnull.i101
delete.notnull.i101: ; preds = %if.then.i100
%110 = bitcast i32* %109 to i8*
tail call void @_ZdaPv(i8* %110) nounwind
br label %delete.notnull5.i102
delete.notnull5.i102: ; preds = %delete.notnull.i101, %if.then.i100
tail call void @_ZdaPv(i8* %call.i) nounwind
%cmp132 = icmp slt i32 %alloc_concomp_cnt.0.lcssa, 1
%cmp134 = icmp eq %"class.tesseract::ConComp"** %concomp_array.0.lcssa, null
%or.cond96 = or i1 %cmp132, %cmp134
br i1 %or.cond96, label %return, label %if.then135
if.then135: ; preds = %delete.notnull5.i102
store i32 0, i32* %concomp_cnt, align 4
%cmp137199 = icmp sgt i32 %alloc_concomp_cnt.0.lcssa, 0
br i1 %cmp137199, label %for.body138, label %return
for.body138: ; preds = %for.inc155, %if.then135
%concomp_idx.0200 = phi i32 [ %inc156, %for.inc155 ], [ 0, %if.then135 ]
%arrayidx139 = getelementptr inbounds %"class.tesseract::ConComp"** %concomp_array.0.lcssa, i32 %concomp_idx.0200
%111 = load %"class.tesseract::ConComp"** %arrayidx139, align 4
%cmp140 = icmp eq %"class.tesseract::ConComp"* %111, null
br i1 %cmp140, label %for.inc155, label %if.then141
if.then141: ; preds = %for.body138
%pt_cnt_.i = getelementptr inbounds %"class.tesseract::ConComp"* %111, i32 0, i32 10
%112 = load i32* %pt_cnt_.i, align 4
%cmp143 = icmp sgt i32 %112, %min_size
br i1 %cmp143, label %if.then144, label %delete.notnull149
if.then144: ; preds = %if.then141
%left_most_.i = getelementptr inbounds %"class.tesseract::ConComp"* %111, i32 0, i32 2
store i8 1, i8* %left_most_.i, align 1
%right_most_.i = getelementptr inbounds %"class.tesseract::ConComp"* %111, i32 0, i32 3
store i8 1, i8* %right_most_.i, align 1
%113 = load i32* %concomp_cnt, align 4
%id_.i = getelementptr inbounds %"class.tesseract::ConComp"* %111, i32 0, i32 1
store i32 %113, i32* %id_.i, align 4
%114 = load i32* %concomp_cnt, align 4
%inc145 = add nsw i32 %114, 1
store i32 %inc145, i32* %concomp_cnt, align 4
%arrayidx146 = getelementptr inbounds %"class.tesseract::ConComp"** %concomp_array.0.lcssa, i32 %114
store %"class.tesseract::ConComp"* %111, %"class.tesseract::ConComp"** %arrayidx146, align 4
br label %for.inc155
delete.notnull149: ; preds = %if.then141
%115 = bitcast %"class.tesseract::ConComp"* %111 to void (%"class.tesseract::ConComp"*)***
%vtable150 = load void (%"class.tesseract::ConComp"*)*** %115, align 4
%vfn151 = getelementptr inbounds void (%"class.tesseract::ConComp"*)** %vtable150, i32 1
%116 = load void (%"class.tesseract::ConComp"*)** %vfn151, align 4
tail call void %116(%"class.tesseract::ConComp"* %111)
br label %for.inc155
for.inc155: ; preds = %delete.notnull149, %if.then144, %for.body138
%inc156 = add nsw i32 %concomp_idx.0200, 1
%exitcond = icmp eq i32 %inc156, %alloc_concomp_cnt.0.lcssa
br i1 %exitcond, label %return, label %for.body138
return: ; preds = %for.inc155, %if.then135, %delete.notnull5.i102, %delete.notnull110, %delete.notnull5.i189, %delete.notnull99, %delete.notnull5.i182, %delete.notnull83, %delete.notnull65, %delete.notnull5.i114, %delete.notnull, %delete.notnull5.i, %if.then
%retval.0 = phi %"class.tesseract::ConComp"** [ null, %if.then ], [ null, %delete.notnull ], [ null, %delete.notnull5.i ], [ null, %delete.notnull65 ], [ null, %delete.notnull5.i114 ], [ null, %delete.notnull83 ], [ null, %delete.notnull99 ], [ null, %delete.notnull5.i182 ], [ null, %delete.notnull110 ], [ null, %delete.notnull5.i189 ], [ %concomp_array.0.lcssa, %delete.notnull5.i102 ], [ %concomp_array.0.lcssa, %for.inc155 ], [ %concomp_array.0.lcssa, %if.then135 ]
ret %"class.tesseract::ConComp"** %retval.0
}
and
define internal %"class.tesseract::ConComp"** @_ZN9tesseract7ConComp7SegmentEiPi(%"class.tesseract::ConComp"* nocapture %this, i32 %max_hist_wnd, i32* nocapture %concomp_cnt) align 2 {
entry:
%seg_pt_cnt = alloca i32, align 4
store i32 0, i32* %concomp_cnt, align 4
%head_ = getelementptr inbounds %"class.tesseract::ConComp"* %this, i32 0, i32 8
%0 = load %"class.tesseract::ConCompPt"** %head_, align 4
%cmp = icmp eq %"class.tesseract::ConCompPt"* %0, null
br i1 %cmp, label %return, label %if.end
if.end: ; preds = %entry
store i32 0, i32* %seg_pt_cnt, align 4
%right_.i = getelementptr inbounds %"class.tesseract::ConComp"* %this, i32 0, i32 6
%1 = load i32* %right_.i, align 4
%left_.i = getelementptr inbounds %"class.tesseract::ConComp"* %this, i32 0, i32 4
%2 = load i32* %left_.i, align 4
%sub.i = sub nsw i32 %1, %2
%add.i = add nsw i32 %sub.i, 1
%bottom_.i = getelementptr inbounds %"class.tesseract::ConComp"* %this, i32 0, i32 7
%3 = load i32* %bottom_.i, align 4
%top_.i = getelementptr inbounds %"class.tesseract::ConComp"* %this, i32 0, i32 5
%4 = load i32* %top_.i, align 4
%sub2.i = add i32 %3, 1
%add3.i = sub i32 %sub2.i, %4
%conv.i = sitofp i32 %add3.i to float
%mul.i = fmul float %conv.i, 0x3FB99999A0000000
%conv4.i = fptosi float %mul.i to i32
%cmp.i = icmp sgt i32 %conv4.i, %max_hist_wnd
%max_hist_wnd.conv4.i = select i1 %cmp.i, i32 %max_hist_wnd, i32 %conv4.i
%sub14.i = sub nsw i32 0, %max_hist_wnd.conv4.i
%5 = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %add.i, i32 4)
%6 = extractvalue { i32, i1 } %5, 1
%7 = extractvalue { i32, i1 } %5, 0
%8 = select i1 %6, i32 -1, i32 %7
%call.i = call noalias i8* @_Znaj(i32 %8)
%9 = bitcast i8* %call.i to i32*
%cmp5.i = icmp eq i8* %call.i, null
br i1 %cmp5.i, label %return, label %if.end7.i
if.end7.i: ; preds = %if.end
%mul8.i = shl i32 %add.i, 2
call void @llvm.memset.p0i8.i32(i8* %call.i, i8 0, i32 %mul8.i, i32 4, i1 false)
%pt_ptr.020.i = load %"class.tesseract::ConCompPt"** %head_, align 4
%cmp921.i = icmp eq %"class.tesseract::ConCompPt"* %pt_ptr.020.i, null
br i1 %cmp921.i, label %if.end4, label %while.body.lr.ph.i
while.body.lr.ph.i: ; preds = %if.end7.i
%10 = load i32* %left_.i, align 4
%cmp1517.i = icmp slt i32 %max_hist_wnd.conv4.i, %sub14.i
%sum = add i32 %10, %max_hist_wnd.conv4.i
br label %while.body.i
while.body.i: ; preds = %for.end.i, %while.body.lr.ph.i
%pt_ptr.022.i = phi %"class.tesseract::ConCompPt"* [ %pt_ptr.020.i, %while.body.lr.ph.i ], [ %pt_ptr.0.i, %for.end.i ]
br i1 %cmp1517.i, label %for.end.i, label %for.body.lr.ph.i
for.body.lr.ph.i: ; preds = %while.body.i
%x_.i.i = getelementptr inbounds %"class.tesseract::ConCompPt"* %pt_ptr.022.i, i32 0, i32 0
%11 = load i32* %x_.i.i, align 4
%sub13.i = sub i32 %11, %sum
br label %for.body.i
for.body.i: ; preds = %for.inc.i, %for.body.lr.ph.i
%xdel.019.i = phi i32 [ %sub14.i, %for.body.lr.ph.i ], [ %inc20.i, %for.inc.i ]
%xw.018.i = phi i32 [ %sub13.i, %for.body.lr.ph.i ], [ %inc21.i, %for.inc.i ]
%cmp16.i = icmp sgt i32 %xw.018.i, -1
%cmp17.i = icmp slt i32 %xw.018.i, %add.i
%or.cond.i = and i1 %cmp16.i, %cmp17.i
br i1 %or.cond.i, label %if.then18.i, label %for.inc.i
if.then18.i: ; preds = %for.body.i
%arrayidx.i = getelementptr inbounds i32* %9, i32 %xw.018.i
%12 = load i32* %arrayidx.i, align 4
%inc.i = add nsw i32 %12, 1
store i32 %inc.i, i32* %arrayidx.i, align 4
br label %for.inc.i
for.inc.i: ; preds = %if.then18.i, %for.body.i
%inc20.i = add nsw i32 %xdel.019.i, 1
%inc21.i = add nsw i32 %xw.018.i, 1
%cmp15.i = icmp sgt i32 %inc20.i, %max_hist_wnd.conv4.i
br i1 %cmp15.i, label %for.end.i, label %for.body.i
for.end.i: ; preds = %for.inc.i, %while.body.i
%next_pt_.i.i = getelementptr inbounds %"class.tesseract::ConCompPt"* %pt_ptr.022.i, i32 0, i32 2
%pt_ptr.0.i = load %"class.tesseract::ConCompPt"** %next_pt_.i.i, align 4
%cmp9.i = icmp eq %"class.tesseract::ConCompPt"* %pt_ptr.0.i, null
br i1 %cmp9.i, label %if.end4, label %while.body.i
if.end4: ; preds = %for.end.i, %if.end7.i
%call5 = call i32* @_ZN9tesseract7ConComp16SegmentHistogramEPiS1_(%"class.tesseract::ConComp"* %this, i32* %9, i32* %seg_pt_cnt)
call void @_ZdaPv(i8* %call.i) nounwind
%13 = load i32* %seg_pt_cnt, align 4
%cmp6 = icmp eq i32 %13, 0
br i1 %cmp6, label %return, label %if.end8
if.end8: ; preds = %if.end4
%add = add nsw i32 %13, 1
%14 = call { i32, i1 } @llvm.umul.with.overflow.i32(i32 %add, i32 4)
%15 = extractvalue { i32, i1 } %14, 1
%16 = extractvalue { i32, i1 } %14, 0
%17 = select i1 %15, i32 -1, i32 %16
%call9 = call noalias i8* @_Znaj(i32 %17)
%18 = bitcast i8* %call9 to %"class.tesseract::ConComp"**
%cmp10 = icmp eq i8* %call9, null
br i1 %cmp10, label %if.then11, label %for.cond.preheader
for.cond.preheader: ; preds = %if.end8
%cmp1647 = icmp slt i32 %13, 0
br i1 %cmp1647, label %for.end, label %for.body.lr.ph
for.body.lr.ph: ; preds = %for.cond.preheader
%id_ = getelementptr inbounds %"class.tesseract::ConComp"* %this, i32 0, i32 1
br label %for.body
if.then11: ; preds = %if.end8
%isnull12 = icmp eq i32* %call5, null
br i1 %isnull12, label %return, label %delete.notnull13
delete.notnull13: ; preds = %if.then11
%19 = bitcast i32* %call5 to i8*
call void @_ZdaPv(i8* %19) nounwind
br label %return
for.body: ; preds = %if.end27, %for.body.lr.ph
%concomp.048 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %if.end27 ]
%call17 = call noalias i8* @_Znwj(i32 40)
%20 = bitcast i8* %call17 to %"class.tesseract::ConComp"*
%21 = bitcast i8* %call17 to i32 (...)***
store i32 (...)** bitcast (i8** getelementptr inbounds ([4 x i8*]* @_ZTVN9tesseract7ConCompE, i32 0, i32 2) to i32 (...)**), i32 (...)*** %21, align 4
%left_.i28 = getelementptr inbounds i8* %call17, i32 12
%22 = getelementptr inbounds i8* %call17, i32 8
store i8 0, i8* %22, align 1
%23 = getelementptr inbounds i8* %call17, i32 9
store i8 0, i8* %23, align 1
%id_.i = getelementptr inbounds i8* %call17, i32 4
%24 = bitcast i8* %id_.i to i32*
call void @llvm.memset.p0i8.i64(i8* %left_.i28, i8 0, i64 24, i32 4, i1 false) nounwind
store i32 -1, i32* %24, align 4
%pt_cnt_.i = getelementptr inbounds i8* %call17, i32 36
%25 = bitcast i8* %pt_cnt_.i to i32*
store i32 0, i32* %25, align 4
%arrayidx = getelementptr inbounds %"class.tesseract::ConComp"** %18, i32 %concomp.048
store %"class.tesseract::ConComp"* %20, %"class.tesseract::ConComp"** %arrayidx, align 4
%cmp19 = icmp eq i8* %call17, null
br i1 %cmp19, label %if.then20, label %if.end27
if.then20: ; preds = %for.body
%isnull21 = icmp eq i32* %call5, null
br i1 %isnull21, label %delete.notnull25, label %delete.notnull22
delete.notnull22: ; preds = %if.then20
%26 = bitcast i32* %call5 to i8*
call void @_ZdaPv(i8* %26) nounwind
br label %delete.notnull25
delete.notnull25: ; preds = %delete.notnull22, %if.then20
call void @_ZdaPv(i8* %call9) nounwind
br label %return
if.end27: ; preds = %for.body
%27 = load i32* %id_, align 4
store i32 %27, i32* %24, align 4
%inc = add nsw i32 %concomp.048, 1
%cmp16 = icmp sgt i32 %inc, %13
br i1 %cmp16, label %for.end, label %for.body
for.end: ; preds = %if.end27, %for.cond.preheader
%28 = load %"class.tesseract::ConComp"** %18, align 4
%left_most_ = getelementptr inbounds %"class.tesseract::ConComp"* %28, i32 0, i32 2
store i8 1, i8* %left_most_, align 1
%arrayidx30 = getelementptr inbounds %"class.tesseract::ConComp"** %18, i32 %13
%29 = load %"class.tesseract::ConComp"** %arrayidx30, align 4
%right_most_ = getelementptr inbounds %"class.tesseract::ConComp"* %29, i32 0, i32 3
store i8 1, i8* %right_most_, align 1
%pt_ptr.044 = load %"class.tesseract::ConCompPt"** %head_, align 4
%cmp3245 = icmp eq %"class.tesseract::ConCompPt"* %pt_ptr.044, null
br i1 %cmp3245, label %while.end, label %for.cond33.preheader
for.cond33.preheader: ; preds = %if.end57, %for.end
%pt_ptr.046 = phi %"class.tesseract::ConCompPt"* [ %pt_ptr.0, %if.end57 ], [ %pt_ptr.044, %for.end ]
%x_.i = getelementptr inbounds %"class.tesseract::ConCompPt"* %pt_ptr.046, i32 0, i32 0
br label %for.cond33
for.cond33: ; preds = %for.body35, %for.cond33.preheader
%seg_pt.0 = phi i32 [ %inc43, %for.body35 ], [ 0, %for.cond33.preheader ]
%cmp34 = icmp slt i32 %seg_pt.0, %13
br i1 %cmp34, label %for.body35, label %for.cond33.for.end44_crit_edge
for.cond33.for.end44_crit_edge: ; preds = %for.cond33
%.pre = load i32* %x_.i, align 4
br label %for.end44
for.body35: ; preds = %for.cond33
%arrayidx36 = getelementptr inbounds i32* %call5, i32 %seg_pt.0
%30 = load i32* %arrayidx36, align 4
%31 = load i32* %left_.i, align 4
%add37 = add nsw i32 %31, %30
%32 = load i32* %x_.i, align 4
%cmp39 = icmp sgt i32 %add37, %32
%inc43 = add nsw i32 %seg_pt.0, 1
br i1 %cmp39, label %for.end44, label %for.cond33
for.end44: ; preds = %for.body35, %for.cond33.for.end44_crit_edge
%33 = phi i32 [ %.pre, %for.cond33.for.end44_crit_edge ], [ %32, %for.body35 ]
%arrayidx45 = getelementptr inbounds %"class.tesseract::ConComp"** %18, i32 %seg_pt.0
%34 = load %"class.tesseract::ConComp"** %arrayidx45, align 4
%y_.i = getelementptr inbounds %"class.tesseract::ConCompPt"* %pt_ptr.046, i32 0, i32 1
%35 = load i32* %y_.i, align 4
%call.i31 = call noalias i8* @_Znwj(i32 12)
%36 = bitcast i8* %call.i31 to %"class.tesseract::ConCompPt"*
%x_.i.i.i = bitcast i8* %call.i31 to i32*
store i32 %33, i32* %x_.i.i.i, align 4
%y_.i.i.i = getelementptr inbounds i8* %call.i31, i32 4
%37 = bitcast i8* %y_.i.i.i to i32*
store i32 %35, i32* %37, align 4
%next_pt_.i.i.i = getelementptr inbounds i8* %call.i31, i32 8
%38 = bitcast i8* %next_pt_.i.i.i to %"class.tesseract::ConCompPt"**
store %"class.tesseract::ConCompPt"* null, %"class.tesseract::ConCompPt"** %38, align 4
%cmp.i32 = icmp eq i8* %call.i31, null
br i1 %cmp.i32, label %if.then50, label %if.end.i
if.end.i: ; preds = %for.end44
%head_.i33 = getelementptr inbounds %"class.tesseract::ConComp"* %34, i32 0, i32 8
%39 = load %"class.tesseract::ConCompPt"** %head_.i33, align 4
%cmp2.i = icmp eq %"class.tesseract::ConCompPt"* %39, null
%left_.i34 = getelementptr inbounds %"class.tesseract::ConComp"* %34, i32 0, i32 4
br i1 %cmp2.i, label %if.then3.i, label %if.else.i
if.then3.i: ; preds = %if.end.i
store i32 %33, i32* %left_.i34, align 4
%right_.i35 = getelementptr inbounds %"class.tesseract::ConComp"* %34, i32 0, i32 6
store i32 %33, i32* %right_.i35, align 4
%top_.i36 = getelementptr inbounds %"class.tesseract::ConComp"* %34, i32 0, i32 5
store i32 %35, i32* %top_.i36, align 4
%bottom_.i37 = getelementptr inbounds %"class.tesseract::ConComp"* %34, i32 0, i32 7
store i32 %35, i32* %bottom_.i37, align 4
store %"class.tesseract::ConCompPt"* %36, %"class.tesseract::ConCompPt"** %head_.i33, align 4
br label %if.end33.i
if.else.i: ; preds = %if.end.i
%40 = load i32* %left_.i34, align 4
%cmp6.i = icmp sgt i32 %40, %33
%x..i = select i1 %cmp6.i, i32 %33, i32 %40
store i32 %x..i, i32* %left_.i34, align 4
%top_9.i = getelementptr inbounds %"class.tesseract::ConComp"* %34, i32 0, i32 5
%41 = load i32* %top_9.i, align 4
%cmp10.i = icmp sgt i32 %41, %35
%cond15.i = select i1 %cmp10.i, i32 %35, i32 %41
store i32 %cond15.i, i32* %top_9.i, align 4
%right_17.i = getelementptr inbounds %"class.tesseract::ConComp"* %34, i32 0, i32 6
%42 = load i32* %right_17.i, align 4
%cmp18.i = icmp slt i32 %42, %33
%x.16.i = select i1 %cmp18.i, i32 %33, i32 %42
store i32 %x.16.i, i32* %right_17.i, align 4
%bottom_25.i = getelementptr inbounds %"class.tesseract::ConComp"* %34, i32 0, i32 7
%43 = load i32* %bottom_25.i, align 4
%cmp26.i = icmp slt i32 %43, %35
%cond31.i = select i1 %cmp26.i, i32 %35, i32 %43
store i32 %cond31.i, i32* %bottom_25.i, align 4
br label %if.end33.i
if.end33.i: ; preds = %if.else.i, %if.then3.i
%tail_.i = getelementptr inbounds %"class.tesseract::ConComp"* %34, i32 0, i32 9
%44 = load %"class.tesseract::ConCompPt"** %tail_.i, align 4
%cmp34.i = icmp eq %"class.tesseract::ConCompPt"* %44, null
br i1 %cmp34.i, label %if.end57, label %if.then35.i
if.then35.i: ; preds = %if.end33.i
%next_pt_.i.i38 = getelementptr inbounds %"class.tesseract::ConCompPt"* %44, i32 0, i32 2
store %"class.tesseract::ConCompPt"* %36, %"class.tesseract::ConCompPt"** %next_pt_.i.i38, align 4
br label %if.end57
if.then50: ; preds = %for.end44
%isnull51 = icmp eq i32* %call5, null
br i1 %isnull51, label %delete.notnull55, label %delete.notnull52
delete.notnull52: ; preds = %if.then50
%45 = bitcast i32* %call5 to i8*
call void @_ZdaPv(i8* %45) nounwind
br label %delete.notnull55
delete.notnull55: ; preds = %delete.notnull52, %if.then50
call void @_ZdaPv(i8* %call9) nounwind
br label %return
if.end57: ; preds = %if.then35.i, %if.end33.i
store %"class.tesseract::ConCompPt"* %36, %"class.tesseract::ConCompPt"** %tail_.i, align 4
%pt_cnt_.i39 = getelementptr inbounds %"class.tesseract::ConComp"* %34, i32 0, i32 10
%46 = load i32* %pt_cnt_.i39, align 4
%inc.i40 = add nsw i32 %46, 1
store i32 %inc.i40, i32* %pt_cnt_.i39, align 4
%next_pt_.i = getelementptr inbounds %"class.tesseract::ConCompPt"* %pt_ptr.046, i32 0, i32 2
%pt_ptr.0 = load %"class.tesseract::ConCompPt"** %next_pt_.i, align 4
%cmp32 = icmp eq %"class.tesseract::ConCompPt"* %pt_ptr.0, null
br i1 %cmp32, label %while.end, label %for.cond33.preheader
while.end: ; preds = %if.end57, %for.end
%isnull59 = icmp eq i32* %call5, null
br i1 %isnull59, label %delete.end61, label %delete.notnull60
delete.notnull60: ; preds = %while.end
%47 = bitcast i32* %call5 to i8*
call void @_ZdaPv(i8* %47) nounwind
br label %delete.end61
delete.end61: ; preds = %delete.notnull60, %while.end
store i32 %add, i32* %concomp_cnt, align 4
br label %return
return: ; preds = %delete.end61, %delete.notnull55, %delete.notnull25, %delete.notnull13, %if.then11, %if.end4, %if.end, %entry
%retval.0 = phi %"class.tesseract::ConComp"** [ %18, %delete.end61 ], [ null, %entry ], [ null, %if.end4 ], [ null, %delete.notnull13 ], [ null, %if.then11 ], [ null, %delete.notnull25 ], [ null, %delete.notnull55 ], [ null, %if.end ]
ret %"class.tesseract::ConComp"** %retval.0
}
Andy ideas? This issue did not show up in earlier versions of emscripten and must, hence, be related to a recent change.
Thanks, Soeren
The issue here is that toNiceIdent has naming collisions. I thought clang didn't emit stuff that could cause that for us, but looks like that was wrong. It isn't trivial to fix this, we would need to decide on a name conversion approach, and would need to modify some JS library entries if the new name conversions differ from before.
Can you suggest a temporary workaround which might help me getting the project to compile? Like by changing the source code, e.g. splitting the functions where this issue pops up? Or renaming some variables?
The commit I pushed, 9b16e85, lets you see in what function it happens. I'm not sure how to prevent clang from generating such names though. But splitting up the function into parts would decrease the risk, definitely.
Don't know if that is related, but I retried building the stack with llvm-lto switched on. The build still fails on duplicate variable names. However, interestingly at another function. It's unclear to me if that is to be expected with the way this optimization works but may be interesting to note.
I'm also getting this error when trying to compile emscripten-kate without inlining (-s INLINING_LIMIT=50), but am not getting the "cannot have duplicate variable names" error. Using incoming, b8aa8067c6c8aecba50bca190d6f6fbfb93d1f86
@ssj-gz can you give full steps to reproduce using that project? Hopefully as simple as possible ;)
Hi Alon,
You can either follow the monster recipe here (not very GDC-friendly ;)) or you can download and extract his pre-built bitcode and other gubbins (~40MB download) :
http://vps2.etotheipiplusone.com:30176/redmine/emscripten-qt-examples/kate-emscripten-bitcode.tar.bz2
and run
${EMSCRIPTEN_ROOT_PATH}/emcc kate.bc -O2 --closure 0 --pre-js pre-qt.js --embed-file qt-fonts --pre-js kate-share-applications-pre.js --pre-js kate-share-apps-pre.js --pre-js kate-share-config-pre.js --pre-js kate-share-kde4-pre.js --pre-js kate-share-mime-pre.js --pre-js kate-share-icons-pre.js -s TOTAL_MEMORY=80000000 -s INLINING_LIMIT=50 -o kate.js
Sorry it's so huge :/
Hi,
I've a similar problem, emscripten reports "unknown [load] impl: native" during the Javascript code generation. Here is the llvm bitcode file used : http://www.compilgames.net/code/embug/main.bc
You should be able to reproduce the bug by simply launching "emcc main.bc -o test.html". Here is the log displayed in the console on my computer ( Windows 7 64 bits ) : http://www.compilgames.net/code/embug/Log.txt
I'm using master branch ( https://github.com/kripken/emscripten/commit/a8e4801c7d38033fff760ea26a4579aa324e303e ).
I pushed a fix to incoming that resolves the issue in @4ian 's testcase, I hope it fixes @ssj-gz 's as well. However it will not resolve the unrelated matter of variable name collisions that was the first problem we saw in this issue.
Fixes mine, thanks (apart from the collisions, as you mention!)
Ok, next is to work on the collisions. Can one of you that are seeing this issue perhaps create a minimal testcase (or several) for me to test on?
I've spent a rather embarrassing amount of time trying to figure out how to get a small, reproducible test case, but am so far coming up blank :/ I'll give you the information I have so far.
In Kate, it exclusively occurs in Qt's generated "moc" files, which have a parameter called, in the source, "_c" - bit naughty, as I think this is a reserved name in C/C++ (?). In llvm, this becomes "%_c".
Now, llvm will, under circumstances I'm still investigating, generate a local called "%.c", and this is where llvm has difficulty. This seem quite rare: I see only 20 or so occurrences of "%.c" in the huge wadge of code that comprises Kate. That this only occurs for me when inlining is enabled is presumably a fluke: it just so happens that llvm occasionally inlines a function that contains one of these elusive "%.c"'s into a function with a parameter named "_c".
No standalone testcase yet, but here are the C++ source and the -O3, inlined .ll version of it:
https://gist.github.com/anonymous/5294207
https://gist.github.com/anonymous/5294243
Someone on #llvm hinted that llvm will sometimes create a new variable called %
a) there is a variable called
Still haven't pinned down a way of triggering c) at will, though :/
Damn, that was hard work. Anyway, here is a testcase that illustrates the problem (without doing naughty stuff like using "_c" as a name!)
https://gist.github.com/anonymous/5295536
Sorry for the spam ;)
Thanks, much easier to work with a testcase. Ok, I started a branch 923_var_collisions with the basic setup we need: Refactor all uses of LLVM identifiers, to go through toNiceIdent (we had hardcoded results), and changes toNiceIdent to distingish . from _. This fails on a lot of tests, so will need more work. Would be great if someone here wants to hack on it too, I have a lot of on my plate right now.
This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.