Skip to content

Commit bbcd919

Browse files
committed
Fix the debug assertion failure when self is implicitly captured.
1 parent 1a98751 commit bbcd919

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ class RawPtrRefLocalVarsChecker
324324

325325
bool shouldSkipVarDecl(const VarDecl *V) const {
326326
assert(V);
327+
if (isa<ImplicitParamDecl>(V))
328+
return true;
327329
return BR->getSourceManager().isInSystemHeader(V->getLocation());
328330
}
329331

clang/test/Analysis/Checkers/WebKit/objc-mock-types.h

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
2-
typedef const void * CFTypeRef;
1+
@class NSString;
2+
@class NSArray;
3+
@class NSMutableArray;
4+
#define CF_BRIDGED_TYPE(T) __attribute__((objc_bridge(T)))
5+
typedef CF_BRIDGED_TYPE(id) void * CFTypeRef;
36
typedef signed long CFIndex;
47
typedef const struct __CFAllocator * CFAllocatorRef;
5-
typedef const struct __CFString * CFStringRef;
6-
typedef const struct __CFArray * CFArrayRef;
7-
typedef struct __CFArray * CFMutableArrayRef;
8+
typedef const struct CF_BRIDGED_TYPE(NSString) __CFString * CFStringRef;
9+
typedef const struct CF_BRIDGED_TYPE(NSArray) __CFArray * CFArrayRef;
10+
typedef struct CF_BRIDGED_TYPE(NSMutableArray) __CFArray * CFMutableArrayRef;
811
extern const CFAllocatorRef kCFAllocatorDefault;
912
CFMutableArrayRef CFArrayCreateMutable(CFAllocatorRef allocator, CFIndex capacity);
1013
extern void CFArrayAppendValue(CFMutableArrayRef theArray, const void *value);
@@ -48,29 +51,9 @@ template <typename T> struct RemovePointer<T*> {
4851
typedef T Type;
4952
};
5053

51-
template <typename T> struct IsPointer {
52-
static constexpr bool value = false;
53-
};
54-
55-
template <typename T> struct IsPointer<T*> {
56-
static constexpr bool value = true;
57-
};
58-
59-
template <typename T, bool isPointer> struct PtrTypeToCFOrObjC {
60-
using PtrType = T;
61-
};
62-
63-
template <typename T> struct PtrTypeToCFOrObjC<T, true> {
64-
using PtrType = T;
65-
};
66-
67-
template <typename T> struct PtrTypeToCFOrObjC<T, false> {
68-
using PtrType = T*;
69-
};
70-
7154
template <typename T> struct RetainPtr {
72-
// using ValueType = typename RemovePointer<T>::Type;
73-
using PtrType = typename PtrTypeToCFOrObjC<T, IsPointer<T>::value>::PtrType;
55+
using ValueType = typename RemovePointer<T>::Type;
56+
using PtrType = ValueType*;
7457
PtrType t;
7558

7659
RetainPtr() : t(nullptr) { }

clang/test/Analysis/Checkers/WebKit/unretained-local-vars.mm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,3 +358,16 @@ void bar() {
358358
CFMutableArrayRef cf = cfSingleton();
359359
}
360360
}
361+
362+
bool doMoreWorkOpaque(OtherObj*);
363+
364+
@implementation OtherObj
365+
- (instancetype)init {
366+
self = [super init];
367+
return self;
368+
}
369+
370+
- (void)doMoreWork:(OtherObj *)other {
371+
doMoreWorkOpaque(other);
372+
}
373+
@end

0 commit comments

Comments
 (0)