[all-commits] [llvm/llvm-project] cc6a6c: [NFC][Clang] Fix Coverity bug with dereference nul...

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


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

  Changed paths:
    M clang/lib/CodeGen/CGExpr.cpp

  Log Message:
  -----------
  [NFC][Clang] Fix Coverity bug with dereference null return value in clang::CodeGen::CodeGenFunction::EmitOMPArraySectionExpr()

Reported by Coverity:

Inside  "CGExpr.cpp" file, in clang::CodeGen::CodeGenFunction::EmitOMPArraySectionExpr(clang::OMPArraySectionExpr const *, bool): Return value of function which returns null is dereferenced without checking.

    } else {
  	//returned_null: getAsConstantArrayType returns nullptr (checked 83 out of 95 times).
  	// var_assigned: Assigning: CAT = nullptr return value from getAsConstantArrayType.
      auto *CAT = C.getAsConstantArrayType(ArrayTy);
  	//identity_transfer: Member function call CAT->getSize() returns an offset off CAT (this).

     // Dereference null return value (NULL_RETURNS)
     //dereference: Dereferencing a pointer that might be nullptr CAT->getSize() when calling APInt.
     ConstLength = CAT->getSize();
    }

This patch adds an assert to resolve the bug.

Reviewed By: erichkeane

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




More information about the All-commits mailing list