[all-commits] [llvm/llvm-project] 171199: [Clang][CodeGen] Do not set inbounds flag for stru...

Yingwei Zheng via All-commits all-commits at lists.llvm.org
Thu Apr 10 18:04:44 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 1711996805c506f5717193aaeedf3752dfdd900d
      https://github.com/llvm/llvm-project/commit/1711996805c506f5717193aaeedf3752dfdd900d
  Author: Yingwei Zheng <dtcxzyw2333 at gmail.com>
  Date:   2025-04-11 (Fri, 11 Apr 2025)

  Changed paths:
    M clang/docs/ReleaseNotes.rst
    M clang/lib/CodeGen/CGExpr.cpp
    M clang/lib/CodeGen/CodeGenFunction.h
    M clang/test/CodeGen/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.c
    M clang/test/CodeGenCXX/catch-nullptr-and-nonzero-offset-in-offsetof-idiom.cpp

  Log Message:
  -----------
  [Clang][CodeGen] Do not set inbounds flag for struct GEP with null base pointers (#130734)

In the LLVM middle-end we want to fold `gep inbounds null, idx -> null`:
https://alive2.llvm.org/ce/z/5ZkPx-
This pattern is common in real-world programs
(https://github.com/dtcxzyw/llvm-opt-benchmark/pull/55#issuecomment-1870963906).
Generally, it exists in some (actually) unreachable blocks, which is
introduced by JumpThreading.

However, some old-style offsetof macros are still widely used in
real-world C/C++ code (e.g., hwloc/slurm/luajit). To avoid breaking
existing code and inconvenience to downstream users, this patch removes
the inbounds flag from the struct gep if the base pointer is null.



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