Skip to content

Commit 222d3b0

Browse files
authored
[TBAA] Fix the case where a subobject gets accessed at a non-zero offset. (#101485)
1 parent cdd2c06 commit 222d3b0

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -613,12 +613,13 @@ static bool mayBeAccessToSubobjectOf(TBAAStructTagNode BaseTag,
613613
}
614614

615615
if (BaseType.getNode() == SubobjectTag.getBaseType()) {
616-
bool SameMemberAccess = OffsetInBase == SubobjectTag.getOffset();
616+
MayAlias = OffsetInBase == SubobjectTag.getOffset() ||
617+
BaseType.getNode() == BaseTag.getAccessType() ||
618+
SubobjectTag.getBaseType() == SubobjectTag.getAccessType();
617619
if (GenericTag) {
618-
*GenericTag = SameMemberAccess ? SubobjectTag.getNode() :
619-
createAccessTag(CommonType);
620+
*GenericTag =
621+
MayAlias ? SubobjectTag.getNode() : createAccessTag(CommonType);
620622
}
621-
MayAlias = SameMemberAccess;
622623
return true;
623624
}
624625

llvm/test/Analysis/TypeBasedAliasAnalysis/aggregates.ll

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
; Check that TBAA handles access tags with aggregate final access types
77
; correctly.
88

9-
%A = type { i32 } ; struct A { int i; };
9+
%A = type { i32, i32 } ; struct A { int i, j; };
1010
%B = type { %A } ; struct B { A a; };
1111
%C = type { %B } ; struct C { B b; };
1212
%D = type { i16 } ; struct D { short s; };
@@ -105,13 +105,32 @@ entry:
105105
ret i32 %0
106106
}
107107

108+
; A vs. A::j => MayAlias.
109+
; This differs from A vs. A::i case in that the offsets of the final
110+
; accessed objects in A do not match.
111+
define i32 @f7(ptr %i, ptr %a) {
112+
entry:
113+
; CHECK-LABEL: f7
114+
; CHECK: MayAlias: store i32 7, {{.*}} <-> store i32 5,
115+
; OPT-LABEL: f7
116+
; OPT: store i32 5,
117+
; OPT: store i32 7,
118+
; OPT: %[[RET:.*]] = load i32,
119+
; OPT: ret i32 %[[RET]]
120+
store i32 5, ptr %i, align 4, !tbaa !10 ; TAG_A
121+
store i32 7, ptr %a, align 4, !tbaa !16 ; TAG_A_j
122+
%0 = load i32, ptr %i, align 4, !tbaa !10 ; TAG_A
123+
ret i32 %0
124+
}
125+
108126
!0 = !{!"root"}
109127
!1 = !{!0, i64 1, !"char"}
110128
!2 = !{!1, i64 4, !"int"}
111129
!3 = !{!2, !2, i64 0, i64 4} ; TAG_int
112130

113-
!4 = !{!1, i64 4, !"A", !2, i64 0, i64 4}
131+
!4 = !{!1, i64 4, !"A", !2, i64 0, i64 4, !2, i64 4, i64 4}
114132
!5 = !{!4, !2, i64 0, i64 4} ; TAG_A_i
133+
!16 = !{!4, !2, i64 4, i64 4} ; TAG_A_j
115134

116135
!6 = !{!1, i64 4, !"B", !4, i64 0, i64 4}
117136
!7 = !{!6, !4, i64 0, i64 4} ; TAG_B_a

0 commit comments

Comments
 (0)