[PATCH] D108712: Avoid nullptr dereferencing of 'SubExpr'; NFC

Sindhu Chittireddy via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 25 10:24:52 PDT 2021


schittir created this revision.
schittir added reviewers: aaron.ballman, erichkeane.
schittir added a project: clang.
schittir requested review of this revision.
Herald added a subscriber: cfe-commits.

Avoid nullptr dereferencing of 'Constraint'; NFC

Klocwork static code analysis exposed this bug:
Pointer 'SubExpr' returned from call to getSubExpr() function 
which may return NULL from 'cast_or_null<Expr>(Operand)', 
which will be dereferenced in the statement following it

Add an assert on SubExpr to avoid nullptr dereferencing


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108712

Files:
  clang/lib/CodeGen/MicrosoftCXXABI.cpp


Index: clang/lib/CodeGen/MicrosoftCXXABI.cpp
===================================================================
--- clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -4348,6 +4348,7 @@
 
 void MicrosoftCXXABI::emitThrow(CodeGenFunction &CGF, const CXXThrowExpr *E) {
   const Expr *SubExpr = E->getSubExpr();
+  assert(SubExpr && "SubExpr cannot be null");
   QualType ThrowType = SubExpr->getType();
   // The exception object lives on the stack and it's address is passed to the
   // runtime function.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108712.368675.patch
Type: text/x-patch
Size: 539 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210825/62ad6663/attachment.bin>


More information about the cfe-commits mailing list