llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) <details> <summary>Changes</summary> 1) Return `std::nullopt` instead of `{}`. 2) Rename the new function to evaluate*, it's not a simple getter. --- Full diff: https://github.com/llvm/llvm-project/pull/155351.diff 4 Files Affected: - (modified) clang/include/clang/AST/Expr.h (+1-1) - (modified) clang/lib/AST/Expr.cpp (+5-5) - (modified) clang/lib/AST/ExprConstant.cpp (+2-1) - (modified) clang/lib/Sema/SemaExpr.cpp (+1-1) ``````````diff diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h index d2ffe9c2e7dd3..b27648175a3e9 100644 --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -3268,7 +3268,7 @@ class CallExpr : public Expr { /// Get the total size in bytes allocated by calling a function decorated with /// alloc_size. Returns std::nullopt if the the result cannot be evaluated. std::optional<llvm::APInt> - getBytesReturnedByAllocSizeCall(const ASTContext &Ctx) const; + evaluateBytesReturnedByAllocSizeCall(const ASTContext &Ctx) const; bool isCallToStdMove() const; diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp index 9d1490c2ef834..d84d548acd8ca 100644 --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -3542,14 +3542,14 @@ const AllocSizeAttr *CallExpr::getCalleeAllocSizeAttr() const { } std::optional<llvm::APInt> -CallExpr::getBytesReturnedByAllocSizeCall(const ASTContext &Ctx) const { +CallExpr::evaluateBytesReturnedByAllocSizeCall(const ASTContext &Ctx) const { const AllocSizeAttr *AllocSize = getCalleeAllocSizeAttr(); assert(AllocSize && AllocSize->getElemSizeParam().isValid()); unsigned SizeArgNo = AllocSize->getElemSizeParam().getASTIndex(); unsigned BitsInSizeT = Ctx.getTypeSize(Ctx.getSizeType()); if (getNumArgs() <= SizeArgNo) - return {}; + return std::nullopt; auto EvaluateAsSizeT = [&](const Expr *E, llvm::APSInt &Into) { Expr::EvalResult ExprResult; @@ -3565,7 +3565,7 @@ CallExpr::getBytesReturnedByAllocSizeCall(const ASTContext &Ctx) const { llvm::APSInt SizeOfElem; if (!EvaluateAsSizeT(getArg(SizeArgNo), SizeOfElem)) - return {}; + return std::nullopt; if (!AllocSize->getNumElemsParam().isValid()) return SizeOfElem; @@ -3573,12 +3573,12 @@ CallExpr::getBytesReturnedByAllocSizeCall(const ASTContext &Ctx) const { llvm::APSInt NumberOfElems; unsigned NumArgNo = AllocSize->getNumElemsParam().getASTIndex(); if (!EvaluateAsSizeT(getArg(NumArgNo), NumberOfElems)) - return {}; + return std::nullopt; bool Overflow; llvm::APInt BytesAvailable = SizeOfElem.umul_ov(NumberOfElems, Overflow); if (Overflow) - return {}; + return std::nullopt; return BytesAvailable; } diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index ee0ac4effab0e..0ad5504aeda91 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9466,7 +9466,8 @@ static bool getBytesReturnedByAllocSizeCall(const ASTContext &Ctx, "Can't get the size of a non alloc_size function"); const auto *Base = LVal.getLValueBase().get<const Expr *>(); const CallExpr *CE = tryUnwrapAllocSizeCall(Base); - std::optional<llvm::APInt> Size = CE->getBytesReturnedByAllocSizeCall(Ctx); + std::optional<llvm::APInt> Size = + CE->evaluateBytesReturnedByAllocSizeCall(Ctx); if (!Size) return false; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 6e5cc7837ecc1..779980a405c94 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -7836,7 +7836,7 @@ static void CheckSufficientAllocSize(Sema &S, QualType DestType, if (!CE->getCalleeAllocSizeAttr()) return; std::optional<llvm::APInt> AllocSize = - CE->getBytesReturnedByAllocSizeCall(S.Context); + CE->evaluateBytesReturnedByAllocSizeCall(S.Context); if (!AllocSize) return; auto Size = CharUnits::fromQuantity(AllocSize->getZExtValue()); `````````` </details> https://github.com/llvm/llvm-project/pull/155351 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits