[clang] [Clang SA]: add support for mismatched ownership_returns+ownership_takes calls for custom allocation classes (PR #98941)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 17 11:25:35 PDT 2024


================
@@ -1490,7 +1532,7 @@ ProgramStateRef MallocChecker::ProcessZeroAllocCheck(
       return State;
     }
   } else
-    llvm_unreachable("not a CallExpr or CXXNewExpr");
+    assert(false && "not a CallExpr or CXXNewExpr");
----------------
steakhal wrote:

```suggestion
  } else {
    assert(false && "not a CallExpr or CXXNewExpr");
    return nullptr;
  }
```
Just to be on the safe side and we have a NDEBUG build (with assertions disabled), let's avoid undefined behavior by safely backing off.

The same principle should apply to all the other cases when previously we had an `llvm_unreachable`.
This is what I wanted to imply by `assert and return`.

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


More information about the cfe-commits mailing list