[clang] [Clang][CodeGen] Loose the cast check when emitting builtins (PR #81669)

Nikita Popov via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 14 05:02:47 PST 2024


nikic wrote:

> I think the right fix is teaching that function about FP <-> INT casts.

The documentation for that function says:
```
  /// Return true if this type could be converted with a lossless BitCast to
  /// type 'Ty'. For example, i8* to i32*. BitCasts are valid for types of the
  /// same size only where no re-interpretation of the bits is done.
```
A cast between float and int sounds like "re-interpretation of the bits" to me. Though the function already allows it if it's a vector of int/float.

TBH I don't really understand what the purpose of this function is. One of the main uses seems to be to restrict what the `returned` attribute can be used for, but in that case we probably should stop accepting casts at all -- these don't really seem useful, and we've had crashes/miscompiles due to allowing them in the past.

For the purposes of this specific change, I think that just dropping the assert is indeed the right thing to do. The cast in the bitcast itself is sufficient.

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


More information about the cfe-commits mailing list