Skip to content

Commit 6331dc1

Browse files
committed
ObjCARC: Don't increment or dereference end() when scanning args
When there's only one argument and it doesn't match one of the known functions, return ARCInstKind::CallOrUser rather than falling through to the two argument case. The old behaviour both incremented past and dereferenced end(). llvm-svn: 278881
1 parent ec083b5 commit 6331dc1

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

llvm/lib/Analysis/ObjCARCInstKind.cpp

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -96,43 +96,47 @@ ARCInstKind llvm::objcarc::GetFunctionClass(const Function *F) {
9696

9797
// One argument.
9898
const Argument *A0 = &*AI++;
99-
if (AI == AE)
99+
if (AI == AE) {
100100
// Argument is a pointer.
101-
if (PointerType *PTy = dyn_cast<PointerType>(A0->getType())) {
102-
Type *ETy = PTy->getElementType();
103-
// Argument is i8*.
104-
if (ETy->isIntegerTy(8))
101+
PointerType *PTy = dyn_cast<PointerType>(A0->getType());
102+
if (!PTy)
103+
return ARCInstKind::CallOrUser;
104+
105+
Type *ETy = PTy->getElementType();
106+
// Argument is i8*.
107+
if (ETy->isIntegerTy(8))
108+
return StringSwitch<ARCInstKind>(F->getName())
109+
.Case("objc_retain", ARCInstKind::Retain)
110+
.Case("objc_retainAutoreleasedReturnValue", ARCInstKind::RetainRV)
111+
.Case("objc_unsafeClaimAutoreleasedReturnValue", ARCInstKind::ClaimRV)
112+
.Case("objc_retainBlock", ARCInstKind::RetainBlock)
113+
.Case("objc_release", ARCInstKind::Release)
114+
.Case("objc_autorelease", ARCInstKind::Autorelease)
115+
.Case("objc_autoreleaseReturnValue", ARCInstKind::AutoreleaseRV)
116+
.Case("objc_autoreleasePoolPop", ARCInstKind::AutoreleasepoolPop)
117+
.Case("objc_retainedObject", ARCInstKind::NoopCast)
118+
.Case("objc_unretainedObject", ARCInstKind::NoopCast)
119+
.Case("objc_unretainedPointer", ARCInstKind::NoopCast)
120+
.Case("objc_retain_autorelease", ARCInstKind::FusedRetainAutorelease)
121+
.Case("objc_retainAutorelease", ARCInstKind::FusedRetainAutorelease)
122+
.Case("objc_retainAutoreleaseReturnValue",
123+
ARCInstKind::FusedRetainAutoreleaseRV)
124+
.Case("objc_sync_enter", ARCInstKind::User)
125+
.Case("objc_sync_exit", ARCInstKind::User)
126+
.Default(ARCInstKind::CallOrUser);
127+
128+
// Argument is i8**
129+
if (PointerType *Pte = dyn_cast<PointerType>(ETy))
130+
if (Pte->getElementType()->isIntegerTy(8))
105131
return StringSwitch<ARCInstKind>(F->getName())
106-
.Case("objc_retain", ARCInstKind::Retain)
107-
.Case("objc_retainAutoreleasedReturnValue", ARCInstKind::RetainRV)
108-
.Case("objc_unsafeClaimAutoreleasedReturnValue",
109-
ARCInstKind::ClaimRV)
110-
.Case("objc_retainBlock", ARCInstKind::RetainBlock)
111-
.Case("objc_release", ARCInstKind::Release)
112-
.Case("objc_autorelease", ARCInstKind::Autorelease)
113-
.Case("objc_autoreleaseReturnValue", ARCInstKind::AutoreleaseRV)
114-
.Case("objc_autoreleasePoolPop", ARCInstKind::AutoreleasepoolPop)
115-
.Case("objc_retainedObject", ARCInstKind::NoopCast)
116-
.Case("objc_unretainedObject", ARCInstKind::NoopCast)
117-
.Case("objc_unretainedPointer", ARCInstKind::NoopCast)
118-
.Case("objc_retain_autorelease",
119-
ARCInstKind::FusedRetainAutorelease)
120-
.Case("objc_retainAutorelease", ARCInstKind::FusedRetainAutorelease)
121-
.Case("objc_retainAutoreleaseReturnValue",
122-
ARCInstKind::FusedRetainAutoreleaseRV)
123-
.Case("objc_sync_enter", ARCInstKind::User)
124-
.Case("objc_sync_exit", ARCInstKind::User)
132+
.Case("objc_loadWeakRetained", ARCInstKind::LoadWeakRetained)
133+
.Case("objc_loadWeak", ARCInstKind::LoadWeak)
134+
.Case("objc_destroyWeak", ARCInstKind::DestroyWeak)
125135
.Default(ARCInstKind::CallOrUser);
126136

127-
// Argument is i8**
128-
if (PointerType *Pte = dyn_cast<PointerType>(ETy))
129-
if (Pte->getElementType()->isIntegerTy(8))
130-
return StringSwitch<ARCInstKind>(F->getName())
131-
.Case("objc_loadWeakRetained", ARCInstKind::LoadWeakRetained)
132-
.Case("objc_loadWeak", ARCInstKind::LoadWeak)
133-
.Case("objc_destroyWeak", ARCInstKind::DestroyWeak)
134-
.Default(ARCInstKind::CallOrUser);
135-
}
137+
// Anything else with one argument.
138+
return ARCInstKind::CallOrUser;
139+
}
136140

137141
// Two arguments, first is i8**.
138142
const Argument *A1 = &*AI++;

0 commit comments

Comments
 (0)