[clang] [clang][CodeGen] Additional fixes for #114062 (PR #128166)
Alex Voicu via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 05:07:25 PST 2025
================
@@ -2352,6 +2353,22 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
Value *Src = Visit(const_cast<Expr*>(E));
llvm::Type *SrcTy = Src->getType();
llvm::Type *DstTy = ConvertType(DestTy);
+
+ // FIXME: this is a gross but seemingly necessary workaround for an issue
+ // manifesting when a target uses a non-default AS for indirect sret args,
+ // but the source HLL is generic, wherein a valid C-cast or reinterpret_cast
+ // on the address of a local struct that gets returned by value yields an
+ // invalid bitcast from the a pointer to the IndirectAS to a pointer to the
+ // DefaultAS. We can only do this subversive thing because sret args are
+ // manufactured and them residing in the IndirectAS is a target specific
+ // detail, and doing an AS cast here still retains the semantics the user
+ // expects. It is desirable to remove this iff a better solution is found.
+ if (SrcTy != DstTy && isa<llvm::Argument>(Src) &&
+ cast<llvm::Argument>(Src)->hasStructRetAttr())
+ return CGF.CGM.getTargetCodeGenInfo().performAddrSpaceCast(
+ CGF, Src, E->getType().getAddressSpace(), DestTy.getAddressSpace(),
+ DstTy);
----------------
AlexVlx wrote:
It carries the LLVM AS, not the AST AS. Since this is a target hook, I assume the intention is to allow a target to override this interface and take into account language intended AS mappings, rather than how the values being cast got codegen-ed? For example, it is plausible, if not currently done (?) that `LangAS::Foo` and `LangAS::Bar` are aliases / map to the same target AS etc., so it'd be possible to simply NOP this and return the source.
https://github.com/llvm/llvm-project/pull/128166
More information about the cfe-commits
mailing list