[PATCH] D127105: [analyzer] Fix null pointer deref in CastValueChecker

Balázs Benics via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 7 03:56:39 PDT 2022


steakhal added a comment.

Likely related to https://github.com/llvm/llvm-project/issues/55715. Mention this in the summary as `Fixes #55715`.



================
Comment at: clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp:168
-            CastToTy->getAsCXXRecordDecl()->getNameAsString() :
-            CastToTy->getPointeeCXXRecordDecl()->getNameAsString();
           Out << ' ' << ((CastToTyVec.size() == 1) ? "not" :
----------------
So this was null, right?  Which caused the crash.


================
Comment at: clang/test/Analysis/cast-value-notes.cpp:306
+
+// don't crash
+namespace llvm {
----------------
It's good to know which line exactly caused the crash. Put this note right there.


================
Comment at: clang/test/Analysis/cast-value-notes.cpp:309-310
+template <typename, typename a> void isa(a &);
+template <typename> class PointerUnion {
+public:
+  template <typename> void b() { isa<int>(*this); }
----------------



================
Comment at: clang/test/Analysis/cast-value-notes.cpp:311
+public:
+  template <typename> void b() { isa<int>(*this); }
+};
----------------
This gotta be the `getAs<T>`. Please try to reconstruct the 'feel' of it; like return a `T*` instead of `void` etc.


================
Comment at: clang/test/Analysis/cast-value-state-dump.cpp:26
   if (dyn_cast_or_null<Square>(S)) {
-    // expected-note at -1 {{Assuming 'S' is not a 'Square'}}
+    // expected-note at -1 {{Assuming 'S' is not a 'const class clang::Square *'}}
     // expected-note at -2 {{Taking false branch}}
----------------
IDK, I see the motivation, but we don't need the full name of these in most cases.
I find it more disturbing than helpful. I would instead stick to the shorter form.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127105/new/

https://reviews.llvm.org/D127105



More information about the cfe-commits mailing list