================ @@ -16644,7 +16644,32 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy, if (Action == AA_Passing_CFAudited) { DiagKind = diag::err_arc_typecheck_convert_incompatible_pointer; } else if (getLangOpts().CPlusPlus) { - DiagKind = diag::err_typecheck_convert_incompatible_pointer; + DiagKind = [this, &SrcType, &DstType] { + const VariableArrayType *SrcTypeVLA = nullptr, *DstTypeVLA = nullptr; + if (const PointerType *P = SrcType->getAs<PointerType>()) + SrcTypeVLA = Context.getAsVariableArrayType(P->getPointeeType()); + if (const PointerType *P = DstType->getAs<PointerType>()) + DstTypeVLA = Context.getAsVariableArrayType(P->getPointeeType()); + + if (SrcTypeVLA == nullptr || DstTypeVLA == nullptr) + return diag::err_typecheck_convert_incompatible_pointer; + + DeclRefExpr *SrcSizeExpr = nullptr, *DstSizeExpr = nullptr; + if (ImplicitCastExpr *I = + dyn_cast<ImplicitCastExpr>(SrcTypeVLA->getSizeExpr())) + SrcSizeExpr = dyn_cast<DeclRefExpr>(I->getSubExpr()); + if (ImplicitCastExpr *I = + dyn_cast<ImplicitCastExpr>(DstTypeVLA->getSizeExpr())) + DstSizeExpr = dyn_cast<DeclRefExpr>(I->getSubExpr()); ---------------- AaronBallman wrote:
For this, I would do: ``` auto GetSizeDeclRef = [](const VariableArrayType *VAT) -> const DeclRefExpr * { if (const Expr *Size = VAT->getSizeExpr()) return dyn_cast<DeclRefExpr>(Size->IgnoreParenImpCasts()) return nullptr; }; DeclRefExpr *SrcSizeExpr = GetSizeDeclRef(SrcTypeVLA), *DestSizeExpr = GetSizeDeclRef(DestTypeVLA); ``` This will ignore more than just implicit cast expressions, but other types of implicit AST nodes (things like parentheses expressions, etc), so it will catch more situations. https://github.com/llvm/llvm-project/pull/101261 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits