[Lldb-commits] [PATCH] D153657: Don't allow ValueObject::Cast from a smaller type to a larger

Alex Langford via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Mon Jun 26 11:11:10 PDT 2023


bulbazord added a comment.

In D153657#4449608 <https://reviews.llvm.org/D153657#4449608>, @jingham wrote:

> In D153657#4445292 <https://reviews.llvm.org/D153657#4445292>, @bulbazord wrote:
>
>> I think this patch is probably okay to do, but it does break a supported use case that I'm aware of: One way you can do "object oriented programming" in C is to do exactly what you're trying to prevent. Using the test, you could say that "MyStruct" is the base class and "MyBiggerStruct" would be a derived class. You might have a pointer to a "MyStruct" object, even though you called `malloc(sizeof(MyBiggerStruct))`, and maybe you can perform that cast if you're sure that you actually have a `MyBiggerStruct` object.
>>
>> I know there's not necessarily a good way to support that without also supporting the bug you're trying to fix though. :(
>
> You can't actually cast structures to structures in C.  You can only cast pointers.  So in your underlying code you always have to have pointers around if you are playing these games, and you can cast the pointer to the derived type and then dereference it, which is what you would have had to do in the source language anyway.

Right, this makes sense, that was my disconnect. Thanks for clarifying and helping me understand!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153657/new/

https://reviews.llvm.org/D153657



More information about the lldb-commits mailing list