Skip to content

Commit b01012b

Browse files
committed
[analyzer] LocalizationChecker: Fix a crash on synthesized accessor stubs.
The checker was trying to analyze the body of every method in Objective-C @implementation clause but the sythesized accessor stubs that were introduced into it by 2073dd2 have no bodies.
1 parent 2b3f207 commit b01012b

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,10 @@ void EmptyLocalizationContextChecker::checkASTDecl(
10771077
AnalysisDeclContext *DCtx = Mgr.getAnalysisDeclContext(M);
10781078

10791079
const Stmt *Body = M->getBody();
1080-
assert(Body);
1080+
if (!Body) {
1081+
assert(M->isSynthesizedAccessorStub());
1082+
continue;
1083+
}
10811084

10821085
MethodCrawler MC(M->getCanonicalDecl(), BR, this, Mgr, DCtx);
10831086
MC.VisitStmt(Body);

clang/test/Analysis/localization-aggressive.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,11 @@ - (void)testTakesLocalizedString {
293293
takesLocalizedString(@"not localized"); // expected-warning {{User-facing text should use localized string macro}}
294294
}
295295
@end
296+
297+
@interface SynthesizedAccessors : NSObject
298+
@property (assign) NSObject *obj;
299+
@end
300+
301+
@implementation SynthesizedAccessors
302+
// no-crash
303+
@end

0 commit comments

Comments
 (0)