diff options
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r-- | clang/lib/AST/ExprConstant.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp index 135e70e96ad..c3e41658c29 100644 --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -5467,8 +5467,9 @@ static bool getBytesReturnedByAllocSizeCall(const ASTContext &Ctx, llvm::APInt &Result) { const AllocSizeAttr *AllocSize = getAllocSizeAttr(Call); - assert(AllocSize && AllocSize->elemSizeParam().isValid()); - unsigned SizeArgNo = AllocSize->elemSizeParam().getASTIndex(); + // alloc_size args are 1-indexed, 0 means not present. + assert(AllocSize && AllocSize->getElemSizeParam() != 0); + unsigned SizeArgNo = AllocSize->getElemSizeParam() - 1; unsigned BitsInSizeT = Ctx.getTypeSize(Ctx.getSizeType()); if (Call->getNumArgs() <= SizeArgNo) return false; @@ -5486,13 +5487,14 @@ static bool getBytesReturnedByAllocSizeCall(const ASTContext &Ctx, if (!EvaluateAsSizeT(Call->getArg(SizeArgNo), SizeOfElem)) return false; - if (!AllocSize->numElemsParam().isValid()) { + if (!AllocSize->getNumElemsParam()) { Result = std::move(SizeOfElem); return true; } APSInt NumberOfElems; - unsigned NumArgNo = AllocSize->numElemsParam().getASTIndex(); + // Argument numbers start at 1 + unsigned NumArgNo = AllocSize->getNumElemsParam() - 1; if (!EvaluateAsSizeT(Call->getArg(NumArgNo), NumberOfElems)) return false; |