Timm =?utf-8?q?Bäder?= <[email protected]>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/[email protected]>


================
@@ -324,14 +348,33 @@ std::optional<uint64_t> Context::evaluateStrlen(State 
&Parent, const Expr *E) {
   std::optional<uint64_t> Result;
   auto PtrRes = C.interpretAsPointer(E, [&](InterpState &S, CodePtr OpPC,
                                             const Pointer &Ptr) {
-    if (!Ptr.isBlockPointer())
+    if (!Ptr.isReadablePointerType())
       return false;
 
+    if (Ptr.isPastEnd())
+      return false;
+
+    if (Ptr.isStringPointer()) {
+      const auto *Lit = Ptr.asStringPointer().getLiteral();
+      int64_t Off = Ptr.getByteOffset();
+      if (Off < 0)
+        return false;
+
+      unsigned Length = 0;
+      for (uint64_t I = Off; I != Lit->getLength(); ++I) {
+        if (Lit->getCodeUnit(I) == 0)
+          break;
+        ++Length;
+      }
+      Result = Length;
+      return true;
+    }
----------------
cor3ntin wrote:

We do that in a bunch of places, at some point it might be nice to do it in 
StringLiteral directly

https://github.com/llvm/llvm-project/pull/216736
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to