clang 20.0.0git
ObjCAutoreleaseWriteChecker.cpp
Go to the documentation of this file.
1//===- ObjCAutoreleaseWriteChecker.cpp ---------------------------*- C++ -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines ObjCAutoreleaseWriteChecker which warns against writes
10// into autoreleased out parameters which cause crashes.
11// An example of a problematic write is a write to @c error in the example
12// below:
13//
14// - (BOOL) mymethod:(NSError *__autoreleasing *)error list:(NSArray*) list {
15// [list enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
16// NSString *myString = obj;
17// if ([myString isEqualToString:@"error"] && error)
18// *error = [NSError errorWithDomain:@"MyDomain" code:-1];
19// }];
20// return false;
21// }
22//
23// Such code will crash on read from `*error` due to the autorelease pool
24// in `enumerateObjectsUsingBlock` implementation freeing the error object
25// on exit from the function.
26//