[Analyzer] Question about casting a symbol to union

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

[Analyzer] Question about casting a symbol to union

Nathan Ridge via cfe-dev
My program has struct to union casting and I'm writing a checker for some of the union types. One issue I noticed is that in checkBind the SVal for the Value part seems to be lost (see sample below). Is this a known issue about casting to union? How can I get the symbol from the union casting assignment (e.g., Val -> conj_$3)?

struct XY {
  uint64_t X;
  uint64_t Y;
};

union Pos {
  struct XY xy;
};

// checkBind: Loc -> xy1, Val -> conj_$3{struct XY, LC1, S12330, #1}
struct xy1 = next_pos(12, 13); // implementation of next_pos is unknown to CSA

// checkBind: Loc -> pos1, Val -> Unknown
union Pos pos1 = (union Pos)next_pos(12, 13);

_______________________________________________
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] Question about casting a symbol to union

Nathan Ridge via cfe-dev
Unions are generally wonky (we even listed them on http://clang-analyzer.llvm.org/open_projects.html) (see also http://lists.llvm.org/pipermail/cfe-dev/2017-March/052881.html).

Additionally, such direct cast from struct rvalue to union rvalue is a GCC extension rather than valid C. It shouldn't be hard to implement, but it's definitely not on the top of my to-do list.

Your questions indicate to me that you're trying to do something weird. I'd much rather try to help with the original problem by recommending the overall solution that'll most likely work.

On 6/26/19 12:42 PM, Torry Chen via cfe-dev wrote:
My program has struct to union casting and I'm writing a checker for some of the union types. One issue I noticed is that in checkBind the SVal for the Value part seems to be lost (see sample below). Is this a known issue about casting to union? How can I get the symbol from the union casting assignment (e.g., Val -> conj_$3)?

struct XY {
  uint64_t X;
  uint64_t Y;
};

union Pos {
  struct XY xy;
};

// checkBind: Loc -> xy1, Val -> conj_$3{struct XY, LC1, S12330, #1}
struct xy1 = next_pos(12, 13); // implementation of next_pos is unknown to CSA

// checkBind: Loc -> pos1, Val -> Unknown
union Pos pos1 = (union Pos)next_pos(12, 13);

_______________________________________________
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