[clang] [analyzer] Match dangling subobjects by their base region in DanglingPtrDeref (PR #211552)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 24 05:53:55 PDT 2026


================
@@ -66,13 +66,21 @@ void DanglingPtrDeref::checkPostCall(const CallEvent &Call,
   }
 }
 
+static std::string getRegionName(const MemRegion *Reg) {
+  // FIXME: Once the checker supports heap allocation, more region kinds
+  // should be handled to produce the correct descriptive name.
+  if (const std::string RegName = Reg->getDescriptiveName(); !RegName.empty())
+    return RegName;
+  return "the region";
----------------
isuckatcs wrote:

Nit:

One way to enforce this pattern is to do something like this:

```suggestion
  // FIXME: Once the checker supports heap allocation, more region kinds
  // should be handled to produce the correct descriptive name.
  if (const std::string RegName = Reg->getDescriptiveName(); !RegName.empty())
    return RegName;
  assert(false && unhandled region);
```


```suggestion
  // FIXME: Once the checker supports heap allocation, more region kinds
  // should be handled to produce the correct descriptive name.
  if (const std::string RegName = Reg->getDescriptiveName(); !RegName.empty())
    return RegName;
  llvm_unreachable("unexpected region");
```

The upside is that you will not forget to add the new region, but the downside is that the CSA is going to crash if you do so.

https://github.com/llvm/llvm-project/pull/211552


More information about the cfe-commits mailing list