[clang] [Clang] Be less strict about diagnosing null pointer dereference. (PR #149648)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 19 08:00:21 PDT 2025


================
@@ -9346,9 +9346,12 @@ bool LValueExprEvaluator::VisitUnaryDeref(const UnaryOperator *E) {
   // [C++26][expr.unary.op]
   // If the operand points to an object or function, the result
   // denotes that object or function; otherwise, the behavior is undefined.
-  return Success &&
-         (!E->getType().getNonReferenceType()->isObjectType() ||
-          findCompleteObject(Info, E, AK_Dereference, Result, E->getType()));
+  // Because &(*(type*)0) is a common pattern, we do not fail the evaluation
+  // immediately.
+  if (!Success || !E->getType().getNonReferenceType()->isObjectType())
+    return Success;
+  return !!findCompleteObject(Info, E, AK_Dereference, Result, E->getType()) ||
----------------
tbaederr wrote:

Do we really prefer `!!` over `(bool)`? Or is this to avoid using a C cast?

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


More information about the cfe-commits mailing list