[llvm] [llubi] Add support for exposed provenance (PR #200596)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 03:25:21 PDT 2026
================
@@ -612,6 +615,96 @@ Pointer Context::deriveFromMemoryObject(IntrusiveRefCntPtr<MemoryObject> Obj) {
Obj->getAddress()));
}
+void Context::exposeProvenance(Provenance &Prov) {
+ if (Prov.Wildcard)
+ return;
+ MemoryObject *Obj = Prov.getMemoryObject();
+ if (!Obj)
+ return;
+ uint64_t Address = Obj->getAddress();
+ ExposedProvenanceSet &Set = ExposedProvenances[Address];
+ if (Set.Set.insert(&Prov).second) {
+ Set.List.emplace_back(&Prov);
+ Set.GenerationList.push_back(++ExposedProvenanceSetGeneration);
+ }
+}
+
+MemoryObject *
+Context::checkProvenance(const Pointer &Ptr,
+ function_ref<bool(const Provenance &)> Check,
+ unsigned AS, bool HasSideEffect) {
+ auto &Prov = Ptr.provenance();
+ if (!Check(Prov))
+ return nullptr;
+ // Early return for concrete provenances.
+ if (!Prov.Wildcard)
+ return Prov.Obj.get();
+
+ MemoryObject *MO = nullptr;
+ APInt TempMask;
+ APInt *Mask = HasSideEffect ? &Prov.Wildcard->ActiveMask : &TempMask;
+ SmallVector<IntrusiveRefCntPtr<Provenance>> *List = nullptr;
+ if (Prov.Wildcard->ActiveMask.isZero()) {
+ // The memory object hasn't been determined.
+ uint64_t Addr = Ptr.address().getLimitedValue();
+ auto Iter = ExposedProvenances.upper_bound(Addr);
+ if (Iter == ExposedProvenances.begin())
+ return nullptr;
+ auto &[BaseAddress, Set] = *std::prev(Iter);
+ auto &Obj = MemoryObjects.at(BaseAddress);
+ if (Obj->getAddressSpace() != AS || !Obj->inBounds(Ptr.address()))
----------------
nikic wrote:
Did these AS checks get moved from somewhere or are they new? It's possible for address spaces to alias... (Though equality check is fine for now.)
https://github.com/llvm/llvm-project/pull/200596
More information about the llvm-commits
mailing list