Skip to content

Commit 895c356

Browse files
vitalybukayuxuanchen1997
authored andcommitted
Revert "[PatternMatch] Fix issue of stale reference in new m_{I,F,}Cmp matchers" (#99062)
Summary: Reverts #98866 It's still use-after-scope. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251755
1 parent 40e0387 commit 895c356

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

llvm/include/llvm/IR/PatternMatch.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,27 +1550,23 @@ template <typename T> inline Exact_match<T> m_Exact(const T &SubPattern) {
15501550
template <typename LHS_t, typename RHS_t, typename Class, typename PredicateTy,
15511551
bool Commutable = false>
15521552
struct CmpClass_match {
1553-
PredicateTy *Predicate;
1553+
PredicateTy &Predicate;
15541554
LHS_t L;
15551555
RHS_t R;
15561556

15571557
// The evaluation order is always stable, regardless of Commutability.
15581558
// The LHS is always matched first.
15591559
CmpClass_match(PredicateTy &Pred, const LHS_t &LHS, const RHS_t &RHS)
1560-
: Predicate(&Pred), L(LHS), R(RHS) {}
1561-
CmpClass_match(const LHS_t &LHS, const RHS_t &RHS)
1562-
: Predicate(nullptr), L(LHS), R(RHS) {}
1560+
: Predicate(Pred), L(LHS), R(RHS) {}
15631561

15641562
template <typename OpTy> bool match(OpTy *V) {
15651563
if (auto *I = dyn_cast<Class>(V)) {
15661564
if (L.match(I->getOperand(0)) && R.match(I->getOperand(1))) {
1567-
if (Predicate)
1568-
*Predicate = I->getPredicate();
1565+
Predicate = I->getPredicate();
15691566
return true;
15701567
} else if (Commutable && L.match(I->getOperand(1)) &&
15711568
R.match(I->getOperand(0))) {
1572-
if (Predicate)
1573-
*Predicate = I->getSwappedPredicate();
1569+
Predicate = I->getSwappedPredicate();
15741570
return true;
15751571
}
15761572
}
@@ -1599,19 +1595,22 @@ m_FCmp(FCmpInst::Predicate &Pred, const LHS &L, const RHS &R) {
15991595
template <typename LHS, typename RHS>
16001596
inline CmpClass_match<LHS, RHS, CmpInst, CmpInst::Predicate>
16011597
m_Cmp(const LHS &L, const RHS &R) {
1602-
return CmpClass_match<LHS, RHS, CmpInst, CmpInst::Predicate>(L, R);
1598+
CmpInst::Predicate Unused;
1599+
return CmpClass_match<LHS, RHS, CmpInst, CmpInst::Predicate>(Unused, L, R);
16031600
}
16041601

16051602
template <typename LHS, typename RHS>
16061603
inline CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate>
16071604
m_ICmp(const LHS &L, const RHS &R) {
1608-
return CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate>(L, R);
1605+
ICmpInst::Predicate Unused;
1606+
return CmpClass_match<LHS, RHS, ICmpInst, ICmpInst::Predicate>(Unused, L, R);
16091607
}
16101608

16111609
template <typename LHS, typename RHS>
16121610
inline CmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate>
16131611
m_FCmp(const LHS &L, const RHS &R) {
1614-
return CmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate>(L, R);
1612+
FCmpInst::Predicate Unused;
1613+
return CmpClass_match<LHS, RHS, FCmpInst, FCmpInst::Predicate>(Unused, L, R);
16151614
}
16161615

16171616
// Same as CmpClass, but instead of saving Pred as out output variable, match a

llvm/unittests/IR/PatternMatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,7 +2235,7 @@ typedef ::testing::Types<std::tuple<Value*, Instruction*>,
22352235
MutableConstTestTypes;
22362236
TYPED_TEST_SUITE(MutableConstTest, MutableConstTestTypes, );
22372237

2238-
TYPED_TEST(MutableConstTest, ICmp) {
2238+
TYPED_TEST(MutableConstTest, /* FIXME: UAR bug */ DISABLED_ICmp) {
22392239
auto &IRB = PatternMatchTest::IRB;
22402240

22412241
typedef std::tuple_element_t<0, TypeParam> ValueType;
@@ -2319,7 +2319,7 @@ TYPED_TEST(MutableConstTest, ICmp) {
23192319
.match((InstructionType)IRB.CreateICmp(Pred, L, R)));
23202320
}
23212321

2322-
TYPED_TEST(MutableConstTest, FCmp) {
2322+
TYPED_TEST(MutableConstTest, /* FIXME: UAR bug */ DISABLED_FCmp) {
23232323
auto &IRB = PatternMatchTest::IRB;
23242324

23252325
typedef std::tuple_element_t<0, TypeParam> ValueType;

0 commit comments

Comments
 (0)