[Mlir-commits] [clang] [llvm] [mlir] [IR][ModRef] Introduce `errno` memory location (PR #120783)

Nikita Popov llvmlistbot at llvm.org
Thu Feb 6 08:17:21 PST 2025


================
@@ -126,8 +126,21 @@ static void addLocAccess(MemoryEffects &ME, const MemoryLocation &Loc,
     return;
   if (isa<Argument>(UO)) {
     ME |= MemoryEffects::argMemOnly(MR);
+    if (Loc.Size <= LocationSize::precise(sizeof(int)))
+      ME |= MemoryEffects::errnoMemOnly(MR);
     return;
   }
+  if (isa<CallInst>(UO)) {
+    static constexpr auto ErrnoFnNames = {"__errno_location", "_errno",
+                                          "__errno", "___errno"};
+    auto *Callee = cast<CallInst>(UO)->getCalledFunction();
+    if (Callee && llvm::any_of(ErrnoFnNames, [&](const auto Fn) {
+          return Fn == Callee->getName();
+        })) {
+      ME |= MemoryEffects::errnoMemOnly(MR);
+      return;
+    }
+  }
----------------
nikic wrote:

Note that the bit you actually *want* to modify the the code a few lines below that uses IRMemLocation::Other. That one should not include Errno as well.

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


More information about the Mlir-commits mailing list