[llvm] [BasicAA][TLI] Local-linkage or non-thread-local globals may not alias errno (PR #170290)
Antonio Frighetto via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 2 09:33:07 PST 2025
================
@@ -1870,8 +1870,24 @@ AliasResult BasicAAResult::aliasErrno(const MemoryLocation &Loc,
Loc.Size.getValue().getKnownMinValue() * 8 > TLI.getIntSize())
return AliasResult::NoAlias;
- if (isIdentifiedFunctionLocal(getUnderlyingObject(Loc.Ptr)))
+ const Value *Object = getUnderlyingObject(Loc.Ptr);
+ if (isIdentifiedFunctionLocal(Object))
return AliasResult::NoAlias;
+
+ if (auto *GV = dyn_cast<GlobalVariable>(Object)) {
+ // Errno cannot alias internal/private globals.
+ if (GV->hasLocalLinkage())
+ return AliasResult::NoAlias;
+
+ // Neither can it alias external globals which are known not to represent
+ // errno.
+ if (GV->hasExternalLinkage() && !TLI.mayBeErrnoGlobal(GV))
+ return AliasResult::NoAlias;
+
+ // A non-thread-local global cannot alias a thread-local errno.
+ if (!GV->isThreadLocal() && TLI.isErrnoThreadLocal())
----------------
antoniofrighetto wrote:
Sure thing. I wonder though if it is still reasonable to keep it separate and have IsErrnoThreadLocal.
https://github.com/llvm/llvm-project/pull/170290
More information about the llvm-commits
mailing list