<div dir="ltr"><div>So, that means that &&(Label) operator, which is defined in C++, is also not supported currently in LLVM. I thought I could obtain address of basic block indirectly through this small hack but it does not seem to work.</div>

<div> </div>
<div>Actually, I tried to make folloing dummy C++ code which uses this operator:</div>
<div><br><em>int main(int argc,char** argv)<br>{<br>        int x;<br>        int y;<br>L1:     printf("Hello\n");<br>L2:     printf("World\n");</em></div>
<div><em>        if(atoi(argv[1]) == 1)<br>                <strong>x = &&L1;<br></strong>        else</em></div>
<div><em>               <strong> x = &&L2;</strong></em></div>
<div><em>        y = x + 10;<br>        return y;<br>}</em></div>
<div><em><br> </em></div>
<div><strong>( The above code is not correct as we cast from pointer to interger and also not an example of good programming but would anyways compile correctly in GCC)</strong></div>
<div> </div>
<div>If I use llvmgcc, I get:</div>
<div><br>@.str = internal constant [6 x i8] c"Hello\00"          <br>@.str1 = internal constant [6 x i8] c"World\00"        </div>
<div> </div>
<div><em>define i32 @main(i32 %argc, i8** %argv) nounwind  {<br><br>entry:  %"alloca point" = bitcast i32 0 to i32          <br>        br label %L1</em></div>
<div><em>L1:             ; preds = %indirectgoto, %indirectgoto, %entry<br>        %tmp1 = call i32 @puts( i8* getelementptr ([6 x i8]* @.str, i32 0, i32<br>        br label %L2</em></div>
<div><em>L2:             ; preds = %indirectgoto, %L1<br>        %tmp2 = call i32 @puts( i8* getelementptr ([6 x i8]* @.str1, i32 0, i32<br>        %tmp4 = getelementptr i8** %argv, i32 1     <br>        %tmp5 = load i8** %tmp4, align 4                <br>
        %tmp6 = call i32 @atoi( i8* %tmp5 ) nounwind            <br>        %tmp7 = icmp eq i32 %tmp6, 1            <br>        %tmp78 = zext i1 %tmp7 to i8            <br>        %toBool = icmp ne i8 %tmp78, 0          <br>
        br i1 %toBool, label %bb, label %bb9<br>       <br>bb:             ; preds = %L2<br>       <strong> ptrtoint i8* inttoptr (i32 1 to i8*) to i32</strong>            <br>        br label %bb10</em></div>
<div><em>bb9:            ; preds = %L2<br>       <strong> ptrtoint i8* inttoptr (i32 2 to i8*) to i32</strong>             <br>        br label %bb10<br>        <br>bb10:           ; preds = %bb9, %bb<br>        %x.0 = phi i32 [ 2, %bb9 ], [ 1, %bb ]        <br>
        %tmp12 = add i32 %x.0, 10              <br>        br label %return<br>       <br>return:        <br>         ret i32 %tmp12</em></div>
<div><em></em> </div>
<div><em>indirectgoto:           ; No predecessors!<br>        switch i32 undef, label %L1 [<br>                 i32 1, label %L1<br>                 i32 2, label %L2<br>        ]<br>}</em></div>
<div><em>declare i32 @puts(i8*)</em></div>
<div><em>declare i32 @atoi(i8*)<br></em></div>
<div><em></em> </div>
<div>The instruction marked in BOLD should correspond to each other but LLVM code does not seem to capture the logic represented in corresponding C Code. So, should we take care to avoid such kind of label operators in code.</div>

<div> </div>
<div>Kapil</div>
<div> </div>
<div> </div>
<div> </div>
<div>On Thu, Jul 24, 2008 at 2:47 AM, Chris Lattner <<a href="mailto:clattner@apple.com">clattner@apple.com</a>> wrote:<br></div>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
<div class="Ih2E3d"><br>On Jul 23, 2008, at 8:47 PM, kapil anand wrote:<br><br>><br>> Specifically, I need a way to represent indirect branch instruction<br>> (in binary) as an equivalent LLVM instruction. With switch<br>
> instruction , I would have to list all the possible targets and then<br>> initialize the corresponding instruction. I was just thinking<br>> whether it might be possible to have some kind of indirect branch<br>
> where label is a "variable" and not an explicit label present in<br>> module.<br>><br></div>No, and there never will be a way.  In the future, we will probably<br>extend the CFG to better model the GCC "address of label + indirect<br>
goto" extension.  However, even with that, all the possible<br>destinations of an indirect goto must be explicitly known.<br><br>Without knowing the CFG, the compiler cannot do any useful<br>optimization.  Eli is right, you probably want lots of tail calls or<br>
something.<br><font color="#888888"><br>-Chris<br></font>
<div>
<div></div>
<div class="Wj3C7c">_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu/" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></div></div></blockquote><br></div>