[clang] [Clang] Fix crash in alignment builtins with null pointers (PR #224549)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 22 05:39:49 PDT 2026


AaronBallman wrote:

> So,
> 
> ```c++
>    _Static_assert(__builtin_is_aligned((void *)33, 32), "");
> ```
> 
> this is supposed to....? Work? Not work?

By my reading of the docs, I think it's not supposed to work?

> This means that arbitrary integer values stored in pointer-type variables must not be passed to these builtins. For those use cases, the builtins can still be used, but the operation must be performed on the pointer cast to uintptr_t.

This isn't stored in a pointer-type variable but I think it's a morally equivalent case.

> ```c++
>    _Static_assert(__builtin_is_aligned((void *)32, 32), "");
> ```
> 
> this works, but isn't the alignment of both of those pointers the same? Are we really supposed to treat an integer casted to a pointer just like an integer?

I don't think so, but I'm not confident in that answer.

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


More information about the cfe-commits mailing list