[clang] [CIR] Support pointer-to-int global initializers (PR #220643)
Kunal Dubey via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 15 05:52:52 PDT 2026
xakep8 wrote:
> The results look right here, but it isn't clear to me how we are getting there. Can you elaborate on that?
```cpp
int x;
unsigned long gx = (unsigned long)&x;
```
Here the base of x is int so tryEmitBase gives us `#cir.global_view<@x>` then in tryEmit we retag that to `#cir.global_view<@x> : !u64i` similarly for offset adjustment like for arrays we get `#cir.global_view<@arr, [2 : i32]> : !u64i`.
Then lowering CIR to LLVM emits
```llvm
llvm.mlir.global external @gx() : i64 {
%0 = llvm.mlir.addressof @x : !llvm.ptr
%1 = llvm.ptrtoint %0 : !llvm.ptr to i64
llvm.return %1 : i64
}
```
and the final IR is
```IR
@x = global i32 0, align 4
@gx = global i64 ptrtoint (ptr @x to i64), align 8
```
https://github.com/llvm/llvm-project/pull/220643
More information about the cfe-commits
mailing list