[clang] [clang][CodeGen] Additional fixes for #114062 (PR #128166)
Alex Voicu via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 26 06:11:13 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())
----------------
AlexVlx wrote:
> The C++17 thing is slowly but surely spreading to be the canonical way to do this (needs A && A->hasStructRetAttr())
Oh, that's cool to hear, I'll rewrite it then, cheers.
https://github.com/llvm/llvm-project/pull/128166
More information about the cfe-commits
mailing list