[NFC][CLANG] Fix static code analyzer concerns
authorManna, Soumi <soumi.manna@intel.com>
Fri, 26 May 2023 03:00:19 +0000 (20:00 -0700)
committerManna, Soumi <soumi.manna@intel.com>
Fri, 26 May 2023 03:00:24 +0000 (20:00 -0700)
Reported by Static Code Analyzer Tool:

Inside "CGExprConstant.cpp" file, VisitObjCEncodeExpr() returns null value which is dereferenced without checking.

This patch adds an assert.

Reviewed By: erichkeane

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

clang/lib/CodeGen/CGExprConstant.cpp

index 2fb9722..b0dd598 100644 (file)
@@ -1340,6 +1340,7 @@ public:
     std::string Str;
     CGM.getContext().getObjCEncodingForType(E->getEncodedType(), Str);
     const ConstantArrayType *CAT = CGM.getContext().getAsConstantArrayType(T);
+    assert(CAT && "String data not of constant array type!");
 
     // Resize the string to the right size, adding zeros at the end, or
     // truncating as needed.