Skip to content

Commit 8a71390

Browse files
[InferAttrs] Mark errnomem-setting libcalls as such
Mark C standard library functions that set `errno` as such, as included in the POSIX specification. Likewise, while deducing function attributes, determine whether a memory access affects errno memory.
1 parent 54d3ac9 commit 8a71390

File tree

3 files changed

+190
-109
lines changed

3 files changed

+190
-109
lines changed

llvm/lib/Transforms/IPO/FunctionAttrs.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ static void addLocAccess(MemoryEffects &ME, const MemoryLocation &Loc,
128128
ME |= MemoryEffects::argMemOnly(MR);
129129
return;
130130
}
131+
// TODO: This should be refined to use upcoming Loc.TBAAErrno for errno
132+
// memory, rather than manually inspecting the underlying object.
133+
if (isa<CallInst>(UO)) {
134+
auto *Callee = cast<CallInst>(UO)->getCalledFunction();
135+
if (Callee && Callee->getName() == "__errno_location") {
136+
ME |= MemoryEffects::errnoMemOnly(MR);
137+
return;
138+
}
139+
}
131140

132141
// If it's not an identified object, it might be an argument.
133142
if (!isIdentifiedObject(UO))
@@ -210,6 +219,9 @@ checkFunctionMemoryAccess(Function &F, bool ThisBody, AAResults &AAR,
210219
if (isa<PseudoProbeInst>(I))
211220
continue;
212221

222+
// Merge callee's memory effects into caller's ones, including
223+
// inaccessible and errno memory, but excluding argument memory, which is
224+
// handled separately.
213225
ME |= CallME.getWithoutLoc(IRMemLocation::ArgMem);
214226

215227
// If the call accesses captured memory (currently part of "other") and

0 commit comments

Comments
 (0)