[clang] [clang][bytecode] Fix crash on __builtin_align_up with one-past-end pointers (PR #178652)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 31 08:19:49 PST 2026


================
@@ -240,5 +240,11 @@ static_assert(!__builtin_is_aligned(static_cast<unsigned long>(7), static_cast<s
 static_assert(!__builtin_is_aligned(static_cast<signed long>(7), static_cast<unsigned short>(4)), "");
 static_assert(!__builtin_is_aligned(static_cast<unsigned short>(7), static_cast<signed long>(4)), "");
 
+// Check that one-past-end pointers don't crash (GH#178647).
+// Use a runtime context to test codegen path where the crash originally occurred.
+char *test_one_past_end_align() {
+  return __builtin_align_up(&align32array[128], 4);
+}
----------------
keinflue wrote:

It seems Clang currently doesn't diagnose it at all, but this should fail to be a constant expression because it attempts to dereference a one-past-the-object pointer.

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


More information about the cfe-commits mailing list