[clang] [clang][CodeGen] Additional fixes for #114062 (PR #128166)
Matt Arsenault via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 04:23:59 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())
----------------
arsenm wrote:
dyn_cast?
https://github.com/llvm/llvm-project/pull/128166
More information about the cfe-commits
mailing list