[clang] [llvm] [Loads] Check context instruction for context-sensitive derefability (PR #109277)

Thorsten Schütt via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 19 09:33:52 PDT 2024


================
@@ -104,6 +104,17 @@ static bool isDereferenceableAndAlignedPointer(
     if (CheckForNonNull &&
         !isKnownNonZero(V, SimplifyQuery(DL, DT, AC, CtxI)))
       return false;
+    // When using something like !dereferenceable on a load, the
+    // dereferenceability may only be valid on a specific control-flow path.
+    // If the instruction doesn't dominate the context instruction, we're
+    // asking about dereferenceability under the assumption that the
+    // instruction has been speculated to the point of the context instruction,
+    // in which case we don't know if the dereferenceability info still holds.
+    // We don't bother handling allocas here, as they aren't speculatable
+    // anyway.
+    auto *I = dyn_cast<Instruction>(V);
----------------
tschuett wrote:

```
if (auto *I = dyn_cast<Instruction>(V))
  if (!isa<AllocaInst>(I))
     return CtxI && isValidAssumeForContext(I, CtxI, DT);
```

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


More information about the cfe-commits mailing list