================ @@ -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:
That'd nest an extra `if` (maybe a pair of `if`s) unless we use C++17's if statement with initializer stuff (`if (auto A = dyn_cast<llvm::Argument>(Src); A->hasStructRetAttr())`) which I've not seen much of / is a bit surprising for those unaware of the feature? https://github.com/llvm/llvm-project/pull/128166 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits