[clang] [analyzer] Fix note for member reference (PR #68691)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 12 04:56:01 PDT 2023


================
@@ -132,6 +132,18 @@ const Expr *bugreporter::getDerefExpr(const Stmt *S) {
     }
     // Pattern match for a few useful cases: a[0], p->f, *p etc.
     else if (const auto *ME = dyn_cast<MemberExpr>(E)) {
+      // This handles the case when the dereferencing of a member reference
+      // happens. This is needed, because the ast for dereferencing of a
+      // member reference looks like the following:
+      // |-MemberExpr
+      //  `-DeclRefExpr
+      // This branch without the special case just takes out the DeclRefExpr
+      // of the struct, class or union.
+      // This is wrong, because this DeclRefExpr will be passed
+      // to the bug reporting and the notes will refer to wrong variable
+      // (the struct instead of the member).
----------------
DonatNagyE wrote:

```suggestion
      // Without this special case the notes would refer to the whole object
      // (struct, class or union variable) instead of just the relevant member.

```

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


More information about the cfe-commits mailing list