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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Nathan Ridge via cfe-dev
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 list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Analyzer] How to register a trait for a custom data structure?

Nathan Ridge via cfe-dev
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 list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: [Analyzer] How to register a trait for a custom data structure?

Nathan Ridge via cfe-dev
Thank you! I move on with multiple simple-value traits for now.

On Fri, 21 Jun 2019 at 20:13, Artem Dergachev <[hidden email]> 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 list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev