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

via cfe-commits cfe-commits at lists.llvm.org
Tue May 23 07:26:08 PDT 2023


Author: Manna, Soumi
Date: 2023-05-23T07:25:21-07:00
New Revision: cc6a6c48d4bb498717950ae482167102d25bf821

URL: https://github.com/llvm/llvm-project/commit/cc6a6c48d4bb498717950ae482167102d25bf821
DIFF: https://github.com/llvm/llvm-project/commit/cc6a6c48d4bb498717950ae482167102d25bf821.diff

LOG: [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

Added: 
    

Modified: 
    clang/lib/CodeGen/CGExpr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 736f3e8bf2d1..2c219d6e8411 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -4102,6 +4102,7 @@ LValue CodeGenFunction::EmitOMPArraySectionExpr(const OMPArraySectionExpr *E,
         }
       } else {
         auto *CAT = C.getAsConstantArrayType(ArrayTy);
+        assert(CAT && "unexpected type for array initializer");
         ConstLength = CAT->getSize();
       }
       if (Length) {


        


More information about the cfe-commits mailing list