[clang] de15979 - Assert pointer cannot be null; NFC

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 26 04:00:30 PDT 2021


Author: Sindhu Chittireddy
Date: 2021-08-26T06:58:56-04:00
New Revision: de15979bc32d761c9b5071fb7d28d7c04ebbfaf3

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

LOG: Assert pointer cannot be null; NFC

Klocwork static code analysis exposed this concern:
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 make it clear this pointer cannot be null.

Added: 
    

Modified: 
    clang/lib/CodeGen/MicrosoftCXXABI.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/MicrosoftCXXABI.cpp b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
index 990648b131fe..6522ea58c27c 100644
--- a/clang/lib/CodeGen/MicrosoftCXXABI.cpp
+++ b/clang/lib/CodeGen/MicrosoftCXXABI.cpp
@@ -4348,6 +4348,7 @@ llvm::GlobalVariable *MicrosoftCXXABI::getThrowInfo(QualType T) {
 
 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.


        


More information about the cfe-commits mailing list