This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by Manna on May 22 2023, 12:16 PM.

Details

Summary

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.

Diff Detail

Event Timeline

Manna created this revision.May 22 2023, 12:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 22 2023, 12:16 PM
Manna requested review of this revision.May 22 2023, 12:16 PM
Manna set the repository for this revision to rG LLVM Github Monorepo.
Herald added a project: Restricted Project. · View Herald TranscriptMay 22 2023, 12:16 PM
erichkeane accepted this revision.May 22 2023, 12:21 PM
This revision is now accepted and ready to land.May 22 2023, 12:21 PM

Thank you @erichkeane for reviews!