[clang] [clang] fix wrong result of pointers comparison between unknown and stack (PR #122404)

Balazs Benics via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 10 00:09:07 PST 2025


================
@@ -952,6 +952,12 @@ SVal SimpleSValBuilder::evalBinOpLL(ProgramStateRef state,
     const MemSpaceRegion *RightMS = RightBase->getMemorySpace();
     const MemSpaceRegion *UnknownMS = MemMgr.getUnknownRegion();
 
+    if (LeftMS != RightMS &&
+        ((isa<UnknownSpaceRegion>(LeftMS) && isa<StackSpaceRegion>(RightMS)) ||
+         (isa<StackSpaceRegion>(LeftMS) && isa<UnknownSpaceRegion>(RightMS)))) {
+      return UnknownVal();
+    }
+
----------------
steakhal wrote:

In the current form, it's likely that the subsequent check could be simplified, that checks something really similar like this one.

Please consider hoisting common subexpressions, and simplifying the subsequent check as well.

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


More information about the cfe-commits mailing list