[clang] [CIR] Emit inbounds/inrange for vtable address points in initializers (PR #227520)

via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 29 16:59:29 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clangir

Author: Bruno Cardoso Lopes (bcardosolopes)

<details>
<summary>Changes</summary>

c68a4ca2a920 (https://github.com/llvm/llvm-project/pull/226904) lowers a GEP in a global initializer directly to a constant expression. The IRBuilder path it replaced went through TargetFolder, which infers inbounds (and then nuw) for in-range offsets from a global. CIR never emitted any flags for #cir.global_view, so it had only been getting them from that inference, and 7 CIR tests started failing.

Classic codegen emits no flags on a plain address constant, but it does emit `inbounds inrange(...)` for vtable address points (VTT entries and the vptr of a constant-initialized object). Emit the same in CIR:

- Add an `address_point` flag to #cir.global_view, spelled `#cir.global_view<@<!-- -->vtable, [vtable index, slot], address_point>`.
- Set it where CIRGen builds VTT entries and constant vptrs, and keep it when CIRGen and CXXABILowering rebuild the attribute.
- When lowering to LLVM, make an address point `inbounds`, with an `inrange` covering the one vtable in the group that it points into. The bounds come from the vtable global's type, so they also work when the vtable is only declared.

VTT and vptr initializers now match classic codegen. Tests that check plain address constants now expect no flags, which is also what classic codegen emits.

---
Full diff: https://github.com/llvm/llvm-project/pull/227520.diff


15 Files Affected:

- (modified) clang/include/clang/CIR/Dialect/IR/CIRAttrs.td (+14-6) 
- (modified) clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp (+3-3) 
- (modified) clang/lib/CIR/CodeGen/CIRGenModule.cpp (+6-2) 
- (modified) clang/lib/CIR/CodeGen/CIRGenVTables.cpp (+4-2) 
- (modified) clang/lib/CIR/Dialect/IR/CIRAttrs.cpp (+18) 
- (modified) clang/lib/CIR/Dialect/Transforms/CXXABILowering.cpp (+3-2) 
- (modified) clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp (+24-3) 
- (modified) clang/test/CIR/CodeGen/constexpr-ptr-offset.cpp (+1-1) 
- (modified) clang/test/CIR/CodeGen/global-ptr-init.cpp (+14-4) 
- (modified) clang/test/CIR/CodeGen/globals.cpp (+1-1) 
- (modified) clang/test/CIR/CodeGen/self-ref-temporaries.cpp (+2-2) 
- (modified) clang/test/CIR/CodeGen/vtt.cpp (+14-14) 
- (modified) clang/test/CIR/CodeGenCXX/base-layout.cpp (+2-2) 
- (modified) clang/test/CIR/CodeGenCXX/vtable-linkage.cpp (+2-2) 
- (added) clang/test/CIR/IR/global-view-address-point.cir (+35) 


``````````diff
The server is unavailable at this time. Please wait a few minutes before you try again.
``````````

</details>


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


More information about the cfe-commits mailing list