From a651c4099d3875dd1a1ef6556ee71c915ae72b29 Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Mon, 26 Mar 2012 18:18:39 +0000 Subject: [PATCH] [analyzer] Malloc: Allow a pointer to escape through OSAtomicEnqueue. llvm-svn: 153453 --- clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp | 3 ++- clang/test/Analysis/malloc.mm | 11 +++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp index 5eca9178ad91..7b9adb7c157d 100644 --- a/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp @@ -1257,7 +1257,8 @@ bool MallocChecker::doesNotFreeMemory(const CallOrObjCMessage *Call, // this would be to implement a pointer escapes callback. if (FName == "CVPixelBufferCreateWithBytes" || FName == "CGBitmapContextCreateWithData" || - FName == "CVPixelBufferCreateWithPlanarBytes") { + FName == "CVPixelBufferCreateWithPlanarBytes" || + FName == "OSAtomicEnqueue") { return false; } diff --git a/clang/test/Analysis/malloc.mm b/clang/test/Analysis/malloc.mm index 4cb2cfa328a9..fe14edeedd1c 100644 --- a/clang/test/Analysis/malloc.mm +++ b/clang/test/Analysis/malloc.mm @@ -106,3 +106,14 @@ void testBlocks() { myBlock(3); } +// Test that we handle pointer escaping through OSAtomicEnqueue. +typedef volatile struct { + void *opaque1; + long opaque2; +} OSQueueHead; +void OSAtomicEnqueue( OSQueueHead *__list, void *__new, size_t __offset) __attribute__((weak_import)); +static inline void radar11111210(OSQueueHead *pool) { + void *newItem = malloc(4); + OSAtomicEnqueue(pool, newItem, 4); +} +