[cfe-users] detect default in SwitchInst

David Blaikie via cfe-users cfe-users at lists.llvm.org
Fri Jul 16 14:18:37 PDT 2021


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.

On Fri, Jul 16, 2021 at 1:42 PM Bella V <bellavistaghome at gmail.com> wrote:

> In my case, for a function having a default statement in switch i could
> see a BB with label as sw.default is created:
> switch i32 %0, label %sw.*default* [
> ]
> sw.default: br label %sw.epilog
>
> For a non-default switch statement function:
> switch i32 %1, label %sw.epilog [
> ]
>
>
>
> On Fri, Jul 16, 2021 at 1:00 PM David Blaikie <dblaikie at gmail.com> wrote:
>
>> LLVM IR switch instructions always have a default:
>> https://llvm.org/docs/LangRef.html#switch-instruction - 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)
>>
>> On Fri, Jul 16, 2021 at 12:34 PM Bella V via cfe-users <
>> cfe-users at lists.llvm.org> wrote:
>>
>>> Hello All,
>>>
>>>
>>>
>>> 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.
>>>
>>> Code Example:
>>>
>>> case_default()->getCaseIndex() or case_default()->getSuccessorIndex()
>>> returns the same values for both default and non-default switch C code.
>>>
>>>
>>> Any suggestions to solve this problem?
>>>
>>>
>>> Regards.
>>> _______________________________________________
>>> cfe-users mailing list
>>> cfe-users at lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20210716/4bf24cb8/attachment-0001.html>


More information about the cfe-users mailing list