[all-commits] [llvm/llvm-project] 5569bf: [Clang][CodeGen] Preserve alignment information fo...

Yingwei Zheng via All-commits all-commits at lists.llvm.org
Mon Aug 25 05:08:54 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 5569bf26f0097c2d8b088f0a7cf46451da752dea
      https://github.com/llvm/llvm-project/commit/5569bf26f0097c2d8b088f0a7cf46451da752dea
  Author: Yingwei Zheng <dtcxzyw2333 at gmail.com>
  Date:   2025-08-25 (Mon, 25 Aug 2025)

  Changed paths:
    M clang/lib/CodeGen/CGExpr.cpp
    M clang/lib/CodeGen/CGExprScalar.cpp
    M clang/test/CodeGen/packed-arrays.c
    A clang/test/CodeGen/pointer-arithmetic-align.c
    M clang/test/CodeGenCXX/sret_cast_with_nonzero_alloca_as.cpp

  Log Message:
  -----------
  [Clang][CodeGen] Preserve alignment information for pointer arithmetics (#152575)

Previously, the alignment of pointer arithmetics was inferred from the
pointee type, losing the alignment information from its operands:

https://github.com/llvm/llvm-project/blob/503c0908c3450d228debd64baecf41df8f58476e/clang/lib/CodeGen/CGExpr.cpp#L1446-L1449

This patch preserves alignment information for pointer arithmetics `P
+/- C`, to match the behavior of identical array subscript `&P[C]`:
https://godbolt.org/z/xx1hfTrx4.

Closes https://github.com/llvm/llvm-project/issues/152330. Although the
motivating case can be fixed by
https://github.com/llvm/llvm-project/pull/145733, the alignment cannot
be recovered without a dominating memory access with larger alignment.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list