[llvm] Delete the incorrect assert that assumes size of `APFloat` is the same as `IEEEFloat`. (PR #111780)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 9 20:23:16 PDT 2024


dtcxzyw wrote:

> > > > not all the members of APFloat is IEEE.
> > > 
> > > 
> > > Oh I see. Do you add a new impl whose size is larger than `detail::IEEEFloat`?
> > 
> > 
> > If so, at least we can assert `sizeof(APFloat) == sizeof(APFloat::Storage)`.
> 
> That's an interesting idea, but needs care to get it to work because if the assert is APFloat it won't compile because APFloat isn't complete until after the closing brace. It can't go outside `APFloat` because `Storage` is private. Nor can the assert go in `IEEEFloat`.
> 
> We could add a new `friend class APFloarChecker` to `APFloat` and do the check in that new class. Something like this:
> 
> ```
> lass APFloat {
>   union S {
>     int i;
>     long l;
>   } s;
>   friend class APFloatChecker;
> };
> 
> class APFloatChecker {
>   static_assert(sizeof(APFloat) == sizeof(APFloat::S));
> };
> ```
> 
> `APFloatChecker` wouldn't need to go in the `.h`, where the assertion is evaluated every time the file is processed. It could go in the `.cpp`, where it will be evaluated once per build.

Make sense to me.

https://github.com/llvm/llvm-project/pull/111780


More information about the llvm-commits mailing list