[cfe-dev] [Analyzer] How to register a trait for a custom data structure?

Torry Chen via cfe-dev cfe-dev at lists.llvm.org
Fri Jun 21 23:05:29 PDT 2019


Thank you! I move on with multiple simple-value traits for now.

On Fri, 21 Jun 2019 at 20:13, Artem Dergachev <noqnoqneo at gmail.com> wrote:

> Mmm, yep, looks annoying. Defining ProgramStatePartialTrait for your
> structure isn't hard (there are a lot of examples in ProgramStateTrait.h)
> but it essentially requires your structure to be representable as a void*.
> Which means that you anyway have to make a manager/factory object to
> allocate your structures on the heap and manage memory. And at this point
> you no longer need to specialize ProgramStatePartialTrait because you might
> as well put a raw pointer into the trait.
>
> This whole facility was designed in order to encapsulate the knowledge
> about what does the trait actually mean within the checker. Ironically,
> these days we believe that such encapsulation is more harmful than useful,
> but we didn't get rid of it yet.
>
> Also you can make multiple traits: one for each field of your structure.
> This isn't very object-oriented, but will do the trick as long as all you
> need to do is to store a multiple items. You can also make a getter/setter
> function to assemble your structure from multiple traits and disassemble it
> back into traits.
>
>
> On 6/21/19 5:42 PM, Torry Chen via cfe-dev wrote:
>
> I'm writing a checker and would like to associate program states with a
> custom data structure, e.g. "struct MyData {...}". When trying
> REGISTER_TRAIT_WITH_PROGRAMSTATE it doesn't seem to support custom data
> types. It's a single value so I don't want to use LIST or SET.
>
> Are there other simple ways to register a single compound value with
> program state?
>
> _______________________________________________
> cfe-dev mailing listcfe-dev at lists.llvm.orghttps://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190621/caaf071b/attachment.html>


More information about the cfe-dev mailing list