Skip to content

Commit b50d847

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. (cherry picked from commit b01012b)
1 parent b4ddc3a commit b50d847

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
@@ -1078,7 +1078,10 @@ void EmptyLocalizationContextChecker::checkASTDecl(
10781078
AnalysisDeclContext *DCtx = Mgr.getAnalysisDeclContext(M);
10791079

10801080
const Stmt *Body = M->getBody();
1081-
assert(Body);
1081+
if (!Body) {
1082+
assert(M->isSynthesizedAccessorStub());
1083+
continue;
1084+
}
10821085

10831086
MethodCrawler MC(M->getCanonicalDecl(), BR, this, Mgr, DCtx);
10841087
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)