[clang] [clang][CodeGen] Fix casting 'AddrLabelExpr' to a differernt addrspace (PR #237887)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 4 13:54:33 PST 2026
================
@@ -582,7 +582,9 @@ class ScalarExprEmitter
Value *VisitUnaryExprOrTypeTraitExpr(const UnaryExprOrTypeTraitExpr *E);
Value *VisitAddrLabelExpr(const AddrLabelExpr *E) {
llvm::Value *V = CGF.GetAddrOfLabel(E->getLabel());
- return Builder.CreateBitCast(V, ConvertType(E->getType()));
+ // For some targets (such as AVR), code and data have different addrspaces.
+ return Builder.CreatePointerBitCastOrAddrSpaceCast(
----------------
efriedma-quic wrote:
I think there's an underlying LLVM IR issue with indirectbr: LangRef says blockaddress constants have to be in the address-space of the function, and the operand of indirectbr has to be a blockaddress constant. But it doesn't actually state the indirectbr has to be in the right address-space, and Verifier::visitIndirectBrInst() doesn't check the address-space of the operand.
On a target like AVR where program and data pointers have the same representation, you might be able to get away with using the wrong address-space for the operand to indirectbr; we don't have any checks in LLVM IR, and the difference goes away once we hit SelectionDAG. But we really should be converting the operand to indirectbr to the correct address-space.
https://github.com/llvm/llvm-project/pull/237887
More information about the cfe-commits
mailing list