Skip to content

Commit 930e1fa

Browse files
author
Doug Wyatt
committed
Also diagnose @finally and @synchronized.
1 parent f34e4ac commit 930e1fa

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

clang/lib/Sema/SemaFunctionEffects.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,13 @@ class Analyzer {
11331133
return true;
11341134
}
11351135

1136+
bool VisitObjCAtFinallyStmt(ObjCAtFinallyStmt *Finally) {
1137+
diagnoseLanguageConstruct(FunctionEffect::FE_ExcludeCatch,
1138+
ViolationID::ThrowsOrCatchesExceptions,
1139+
Finally->getAtFinallyLoc());
1140+
return true;
1141+
}
1142+
11361143
bool VisitObjCMessageExpr(ObjCMessageExpr *Msg) {
11371144
diagnoseLanguageConstruct(FunctionEffect::FE_ExcludeObjCMessageSend,
11381145
ViolationID::AccessesObjCMethodOrProperty,
@@ -1150,6 +1157,16 @@ class Analyzer {
11501157
return true;
11511158
}
11521159

1160+
bool VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *Sync) {
1161+
// Under the hood, this calls objc_sync_enter and objc_sync_exit, wrapped
1162+
// in a @try/@finally block. Diagnose this somewhat generically as "ObjC"
1163+
// messaging.
1164+
diagnoseLanguageConstruct(FunctionEffect::FE_ExcludeObjCMessageSend,
1165+
ViolationID::AccessesObjCMethodOrProperty,
1166+
Sync->getBeginLoc());
1167+
return true;
1168+
}
1169+
11531170
bool VisitSEHExceptStmt(SEHExceptStmt *Exc) {
11541171
diagnoseLanguageConstruct(FunctionEffect::FE_ExcludeCatch,
11551172
ViolationID::ThrowsOrCatchesExceptions,

clang/test/SemaObjCXX/attr-nonblocking-constraints.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,17 @@ void nb4() [[clang::nonblocking]] {
2323
}
2424
@catch (...) { // expected-warning {{function with 'nonblocking' attribute must not throw or catch exceptions}}
2525
}
26+
@finally { // expected-warning {{function with 'nonblocking' attribute must not throw or catch exceptions}}
27+
}
2628
}
2729

30+
@class Lock;
31+
extern Lock *someLock;
32+
2833
void nb5() [[clang::nonblocking]] {
2934
@autoreleasepool { // expected-warning {{function with 'nonblocking' attribute must not access ObjC methods or properties}}
3035
}
36+
37+
@synchronized(someLock) { // expected-warning {{function with 'nonblocking' attribute must not access ObjC methods or properties}}
38+
}
3139
}

0 commit comments

Comments
 (0)