[all-commits] [llvm/llvm-project] 64e9ba: [NFC][CLANG] Fix static code analyzer concerns

smanna12 via All-commits all-commits at lists.llvm.org
Tue May 23 07:42:48 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 64e9ba7048b8fb4ac72bbc72e8861c947d49f3d4
      https://github.com/llvm/llvm-project/commit/64e9ba7048b8fb4ac72bbc72e8861c947d49f3d4
  Author: Manna, Soumi <soumi.manna at intel.com>
  Date:   2023-05-23 (Tue, 23 May 2023)

  Changed paths:
    M clang/lib/AST/ExprConstant.cpp

  Log Message:
  -----------
  [NFC][CLANG] Fix static code analyzer concerns

Reported by Static Code Analyzer Tool, Coverity:

Dereference null return value

Inside "ExprConstant.cpp" file, in <unnamed>::RecordExprEvaluator::VisitCXXStdInitializerListExpr(clang::CXXStdInitializerListExpr const *): Return value of function which returns null is dereferenced without checking.

  bool RecordExprEvaluator::VisitCXXStdInitializerListExpr(
   const CXXStdInitializerListExpr *E) {
       // returned_null: getAsConstantArrayType returns nullptr (checked 81 out of 93 times).
       //var_assigned: Assigning: ArrayType = nullptr return value from getAsConstantArrayType.
    const ConstantArrayType *ArrayType =
       Info.Ctx.getAsConstantArrayType(E->getSubExpr()->getType());
    LValue Array;
    //Condition !EvaluateLValue(E->getSubExpr(), Array, this->Info, false), taking false branch.
    if (!EvaluateLValue(E->getSubExpr(), Array, Info))
     return false;

    // Get a pointer to the first element of the array.

    //Dereference null return value (NULL_RETURNS)
    //dereference: Dereferencing a pointer that might be nullptr ArrayType when calling addArray.
    Array.addArray(Info, E, ArrayType);

This patch adds an assert for unexpected type for array initializer.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D151040




More information about the All-commits mailing list