[clang] [clang][ByteCode] Fix crash when dereferencing cast to larger type (PR #179030)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 2 00:50:39 PST 2026


================
@@ -947,6 +947,12 @@ std::optional<APValue> Pointer::toRValue(const Context &Ctx,
 
   // Just load primitive types.
   if (OptPrimType T = Ctx.classify(ResultType)) {
+    // Check if the pointer descriptor's primitive type matches what we're
+    // trying to read. This fails when we reinterpret_cast a pointer to a
+    // different type (e.g. *(int**)"").
+    if (const Descriptor *D = getFieldDesc();
+        (D->isPrimitive() || D->isPrimitiveArray()) && D->getPrimType() != *T)
+      return std::nullopt;
----------------
tbaederr wrote:

```suggestion
    if (const Descriptor *D = getFieldDesc();
        (D->isPrimitive() || D->isPrimitiveArray()) && D->getPrimType() != *T)
      return std::nullopt;
```

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


More information about the cfe-commits mailing list