[all-commits] [llvm/llvm-project] cd1e79: [CIR] Lower constant block addresses for goto
adams381 via All-commits
all-commits at lists.llvm.org
Thu Jun 4 10:31:27 PDT 2026
Branch: refs/heads/users/adams381/cir-computed-goto-blockaddress
Home: https://github.com/llvm/llvm-project
Commit: cd1e799cd4f5313929ef3d52200e03c31b9fe976
https://github.com/llvm/llvm-project/commit/cd1e799cd4f5313929ef3d52200e03c31b9fe976
Author: Adam Smith <adams at nvidia.com>
Date: 2026-06-04 (Thu, 04 Jun 2026)
Changed paths:
M clang/include/clang/CIR/Dialect/IR/CIRAttrs.td
M clang/include/clang/CIR/Dialect/IR/CIROps.td
M clang/lib/CIR/CodeGen/CIRGenExprConstant.cpp
M clang/lib/CIR/CodeGen/CIRGenFunction.cpp
M clang/lib/CIR/CodeGen/CIRGenFunction.h
M clang/lib/CIR/Dialect/IR/CIRDialect.cpp
M clang/lib/CIR/Dialect/Transforms/GotoSolver.cpp
M clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
M clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.h
A clang/test/CIR/CodeGen/goto-address-label-table.c
A clang/test/CIR/IR/global-block-address.cir
Log Message:
-----------
[CIR] Lower constant block addresses for goto
GNU computed-goto code that takes a label's address in a constant
context -- the common static dispatch-table idiom
`static const void *tbl[] = {&&L1, &&L2}; goto *tbl[i];` -- hit
`errorNYI` in `ConstantLValueEmitter::VisitAddrLabelExpr`, and the
follow-on `goto *tbl[i]` then tripped the `indirectGotoBlock`
assertion in `emitIndirectGotoStmt` because the label was never
registered as address-taken. The runtime form (`void *p = &&L;
goto *p;`) already worked; only the constant form was missing.
Label addresses had no constant representation: `cir.block_address`
existed only as an operation, which cannot appear inside a
`#cir.const_array` initializer. Add a `#cir.block_address` constant
attribute and lower it to MLIR's `LLVM::BlockAddressAttr`, reusing the
same `BlockTagOp` resolution the operation form already uses
(threading the pass-owned `LLVMBlockAddressInfo` into the constant
value lowering and the Global/Constant lowering patterns).
CIRGen's `ConstantLValueEmitter::VisitAddrLabelExpr` now emits the
attribute and records the label so `finishIndirectBranch` adds it to
the `cir.indirect_br` successors and the indirect-goto block is
instantiated. Because such labels have no function-local
`BlockAddressOp`, `GotoSolver` was deleting them as unused; it now
also keeps labels referenced by a constant `#cir.block_address`
anywhere in the module.
The lowered LLVM matches classic codegen (a `[N x ptr]` of
`blockaddress` constants plus an `indirectbr`). New test
`goto-address-label-table.c` covers CIR, the CIR-lowered LLVM, and
classic OGCG; `label-values.c` (the runtime form) is unchanged.
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