[PATCH] D98622: [-Wcalled-once-parameter] Let escapes overwrite MaybeCalled states
Valeriy Savchenko via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 15 01:03:21 PDT 2021
vsavchenko created this revision.
vsavchenko added a reviewer: NoQ.
Herald added a subscriber: Charusso.
vsavchenko requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This commit makes escapes symmetrical, meaning that having escape
before and after the branching, where parameter is not called on
one of the paths, will have the same effect.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98622
Files:
clang/lib/Analysis/CalledOnceCheck.cpp
clang/test/SemaObjC/warn-called-once.m
Index: clang/test/SemaObjC/warn-called-once.m
===================================================================
--- clang/test/SemaObjC/warn-called-once.m
+++ clang/test/SemaObjC/warn-called-once.m
@@ -1130,4 +1130,32 @@
}
}
+- (void)test_escape_before_branch:(int)cond
+ withCompletion:(void (^)(void))handler {
+ if (cond) {
+ filler();
+ }
+
+ void (^copiedHandler)(void) = ^{
+ handler();
+ };
+
+ if (cond) {
+ // no-warning
+ handler();
+ } else {
+ copiedHandler();
+ }
+}
+
+- (void)test_escape_after_branch:(int)cond
+ withCompletion:(void (^)(void))handler {
+ if (cond) {
+ // no-warning
+ handler();
+ }
+
+ escape(handler);
+}
+
@end
Index: clang/lib/Analysis/CalledOnceCheck.cpp
===================================================================
--- clang/lib/Analysis/CalledOnceCheck.cpp
+++ clang/lib/Analysis/CalledOnceCheck.cpp
@@ -1367,7 +1367,7 @@
if (auto Index = getIndex(Parameter)) {
ParameterStatus &CurrentParamStatus = CurrentState.getStatusFor(*Index);
- if (CurrentParamStatus.getKind() == ParameterStatus::NotCalled) {
+ if (CurrentParamStatus.isErrorStatus()) {
CurrentParamStatus = ParameterStatus::Escaped;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98622.330572.patch
Type: text/x-patch
Size: 1266 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210315/add4e522/attachment.bin>
More information about the cfe-commits
mailing list