<div dir="ltr">Ah, LLVM IR isn't really the place to determine how the source was written - the names of those LLVM values aren't always preserved (generally in optimized builds of clang the names will not be generated) - that said, even some LLVM features rely on the names, so it's not totally unusable. You can use "getName()" on the value to get these names and inspect them, etc.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 16, 2021 at 1:42 PM Bella V <<a href="mailto:bellavistaghome@gmail.com">bellavistaghome@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">In my case, for a function having a default statement in switch i could see a BB with label as sw.default is created:<div>switch i32 %0, label %sw.<b>default</b> [<br></div><div>]</div><div>sw.default: br label %sw.epilog<br></div><div><br></div><div>For a non-default switch statement function:</div><div>switch i32 %1, label %sw.epilog [<br></div><div>]</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 16, 2021 at 1:00 PM David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">LLVM IR switch instructions always have a default: <a href="https://llvm.org/docs/LangRef.html#switch-instruction" target="_blank">https://llvm.org/docs/LangRef.html#switch-instruction</a> - that jumps over the body of the switch. (when lowering C code to LLVM IR the default would be put after the loop, and the breaks from any case statements would jump over that default block)</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 16, 2021 at 12:34 PM Bella V via cfe-users <<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:rgb(36,41,46)">Hello All,</span></p><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:rgb(36,41,46)"> </span></p><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:rgb(36,41,46)">I'm trying to find whether SwitchInst has a default statement. I'm
able to iterate through the case values using case_begin
and case_end. If I try to detect default using case_default
which returns an iterator which points to the default case. </span></p><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:rgb(36,41,46)">Code Example:</span></p><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:rgb(36,41,46)">case_default()->getCaseIndex() or case_default()->getSuccessorIndex() returns the same values for both default and non-default switch C code.</span></p><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:rgb(36,41,46)"><br></span></p><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:rgb(36,41,46)">Any suggestions to solve this problem?</span></p><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:Calibri,sans-serif">
</p><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:rgb(36,41,46)"><br></span></p><p class="MsoNormal" style="margin:0cm;font-size:12pt;font-family:Calibri,sans-serif"><span style="font-size:10.5pt;font-family:"Segoe UI",sans-serif;color:rgb(36,41,46)">Regards.</span></p></div>
_______________________________________________<br>
cfe-users mailing list<br>
<a href="mailto:cfe-users@lists.llvm.org" target="_blank">cfe-users@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users</a><br>
</blockquote></div>
</blockquote></div>
</blockquote></div>