Skip to content

Commit 56d0a16

Browse files
Doug Wyattcjappl
Doug Wyatt
authored andcommitted
- Detect ObjC @throw and @catch, diagnose identically to their C++ counterparts.
- Tweak test cases.
1 parent 03aefdb commit 56d0a16

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3487,6 +3487,18 @@ class Analyzer {
34873487
return Proceed;
34883488
}
34893489

3490+
bool VisitObjCAtThrowStmt(ObjCAtThrowStmt *Throw) {
3491+
diagnoseLanguageConstruct(FunctionEffect::FE_ExcludeThrow,
3492+
DiagnosticID::Throws, Throw->getThrowLoc());
3493+
return Proceed;
3494+
}
3495+
3496+
bool VisitObjCAtCatchStmt(ObjCAtCatchStmt *Catch) {
3497+
diagnoseLanguageConstruct(FunctionEffect::FE_ExcludeCatch,
3498+
DiagnosticID::Catches, Catch->getAtCatchLoc());
3499+
return Proceed;
3500+
}
3501+
34903502
bool VisitObjCMessageExpr(ObjCMessageExpr *Msg) {
34913503
diagnoseLanguageConstruct(FunctionEffect::FE_ExcludeObjCMessageSend,
34923504
DiagnosticID::CallsObjC, Msg->getBeginLoc());

clang/test/Sema/attr-nonblocking-constraints.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cc1 -fsyntax-only -fblocks -fcxx-exceptions -verify %s
22
// These are in a separate file because errors (e.g. incompatible attributes) currently prevent
3-
// the AnalysisBasedWarnings pass from running at all.
3+
// the FXAnalysis pass from running at all.
44

55
// This diagnostic is re-enabled and exercised in isolation later in this file.
66
#pragma clang diagnostic ignored "-Wperf-constraint-implies-noexcept"
@@ -9,7 +9,8 @@
99

1010
void nl1() [[clang::nonblocking]]
1111
{
12-
auto* pInt = new int; // expected-warning {{'nonblocking' function must not allocate or deallocate memory}}
12+
int *pInt = new int; // expected-warning {{'nonblocking' function must not allocate or deallocate memory}}
13+
delete pInt; // expected-warning {{'nonblocking' function must not allocate or deallocate memory}}
1314
}
1415

1516
void nl2() [[clang::nonblocking]]
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -fblocks -fcxx-exceptions -verify %s
1+
// RUN: %clang_cc1 -fsyntax-only -fblocks -fcxx-exceptions -fobjc-exceptions -verify %s
22

33
#pragma clang diagnostic ignored "-Wperf-constraint-implies-noexcept"
44

@@ -7,13 +7,20 @@ @interface OCClass
77
- (void)method;
88
@end
99

10-
void nl14(OCClass *oc) [[clang::nonblocking]] {
10+
void nb1(OCClass *oc) [[clang::nonblocking]] {
1111
[oc method]; // expected-warning {{'nonblocking' function must not access an ObjC method or property}}
1212
}
13-
void nl15(OCClass *oc) {
13+
void nb2(OCClass *oc) {
1414
[oc method]; // expected-note {{function cannot be inferred 'nonblocking' because it accesses an ObjC method or property}}
1515
}
16-
void nl16(OCClass *oc) [[clang::nonblocking]] {
17-
nl15(oc); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function 'nl15'}}
16+
void nb3(OCClass *oc) [[clang::nonblocking]] {
17+
nb2(oc); // expected-warning {{'nonblocking' function must not call non-'nonblocking' function 'nb2'}}
1818
}
1919

20+
void nb4() [[clang::nonblocking]] {
21+
@try {
22+
@throw @"foo"; // expected-warning {{'nonblocking' function must not throw or catch exceptions}}
23+
}
24+
@catch (...) { // expected-warning {{'nonblocking' function must not throw or catch exceptions}}
25+
}
26+
}

0 commit comments

Comments
 (0)