Repository navigation
[GlobalsAA] Handle self-referencing stores in AnalyzeUsesOfPointer - #213631
antoniofrighetto merged 2 commits into
Conversation
Correctly recognize that a global address does escape when it is stored into itself. Such globals were previously incorrectly marked as non-address-taken. Fixes: llvm#213232.
|
@llvm/pr-subscribers-llvm-analysis Author: Antonio Frighetto (antoniofrighetto) ChangesCorrectly recognize that a global address does escape when it is stored into itself. Such globals were previously incorrectly marked as non-address-taken. Fixes: #213232. Full diff: https://github.com/llvm/llvm-project/pull/213631.diff 2 Files Affected:
diff --git a/llvm/lib/Analysis/GlobalsModRef.cpp b/llvm/lib/Analysis/GlobalsModRef.cpp
index 1a0ae25b2b6b3..6471cc0d52cbd 100644
--- a/llvm/lib/Analysis/GlobalsModRef.cpp
+++ b/llvm/lib/Analysis/GlobalsModRef.cpp
@@ -328,7 +328,8 @@ bool GlobalsAAResult::AnalyzeUsesOfPointer(Value *V,
if (Readers)
Readers->insert(LI->getParent()->getParent());
} else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
- if (V == SI->getOperand(1)) {
+ // Check the pointer operand use of the store.
+ if (&U == &SI->getOperandUse(1)) {
if (Writers)
Writers->insert(SI->getParent()->getParent());
} else if (SI->getOperand(1) != OkayStoreDest) {
diff --git a/llvm/test/Analysis/GlobalsModRef/self-addresstaken.ll b/llvm/test/Analysis/GlobalsModRef/self-addresstaken.ll
new file mode 100644
index 0000000000000..57fd8259f6790
--- /dev/null
+++ b/llvm/test/Analysis/GlobalsModRef/self-addresstaken.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -passes='require<globals-aa>,aa-eval' -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
+
+; Ensure @g is correctly marked as address taken when it is stored into itself.
+
+@g = internal global ptr null
+
+; CHECK-LABEL: self_addresstaken
+; CHECK: MayAlias: ptr* %p, ptr* @g
+
+define ptr @self_addresstaken() {
+ store ptr @g, ptr @g, align 8
+ %p = load ptr, ptr @g, align 8
+ store ptr null, ptr %p, align 8
+ %q = load ptr, ptr @g, align 8
+ ret ptr %q
+}
|
efriedma-quic
left a comment
There was a problem hiding this comment.
LGTM
(I guess the introduction of opaque pointers broke this, since before that it was impossible for both operands of a store to be identical.)
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/55/builds/31362 Here is the relevant piece of the build log for the reference |
…lvm#213631) Correctly recognize that a global address does escape when it is stored into itself. Such globals were previously incorrectly marked as non-address-taken. Fixes: llvm#213232.
Correctly recognize that a global address does escape when it is stored into itself. Such globals were previously incorrectly marked as non-address-taken.
Fixes: #213232.