32#include "llvm/ADT/STLExtras.h"
33#include "llvm/Support/Unicode.h"
40struct LocalizedState {
42 enum Kind { NonLocalized, Localized } K;
43 LocalizedState(Kind InK) : K(InK) {}
46 bool isLocalized()
const {
return K == Localized; }
47 bool isNonLocalized()
const {
return K == NonLocalized; }
49 static LocalizedState getLocalized() {
return LocalizedState(Localized); }
50 static LocalizedState getNonLocalized() {
51 return LocalizedState(NonLocalized);
55 bool operator==(
const LocalizedState &
X)
const {
return K ==
X.K; }
58 void Profile(llvm::FoldingSetNodeID &ID)
const {
ID.AddInteger(K); }
61class NonLocalizedStringChecker
62 :
public Checker<check::PreCall, check::PostCall, check::PreObjCMessage,
63 check::PostObjCMessage,
64 check::PostStmt<ObjCStringLiteral>> {
66 const BugType BT{
this,
"Unlocalizable string",
67 "Localizability Issue (Apple)"};
70 mutable llvm::DenseMap<
const IdentifierInfo *,
71 llvm::DenseMap<Selector, uint8_t>> UIMethods;
73 mutable llvm::SmallSet<std::pair<const IdentifierInfo *, Selector>, 12> LSM;
75 mutable llvm::SmallPtrSet<const IdentifierInfo *, 5> LSF;
77 void initUIMethods(ASTContext &Ctx)
const;
78 void initLocStringsMethods(ASTContext &Ctx)
const;
80 bool hasNonLocalizedState(SVal S, CheckerContext &
C)
const;
81 bool hasLocalizedState(SVal S, CheckerContext &
C)
const;
82 void setNonLocalizedState(SVal S, CheckerContext &
C)
const;
83 void setLocalizedState(SVal S, CheckerContext &
C)
const;
85 bool isAnnotatedAsReturningLocalized(
const Decl *D)
const;
86 bool isAnnotatedAsTakingLocalized(
const Decl *D)
const;
87 void reportLocalizationError(SVal S,
const CallEvent &M, CheckerContext &
C,
88 int argumentNumber = 0)
const;
90 int getLocalizedArgumentForSelector(
const IdentifierInfo *Receiver,
97 bool IsAggressive =
false;
99 void checkPreObjCMessage(
const ObjCMethodCall &msg, CheckerContext &
C)
const;
100 void checkPostObjCMessage(
const ObjCMethodCall &msg, CheckerContext &
C)
const;
101 void checkPostStmt(
const ObjCStringLiteral *SL, CheckerContext &
C)
const;
102 void checkPreCall(
const CallEvent &
Call, CheckerContext &
C)
const;
103 void checkPostCall(
const CallEvent &
Call, CheckerContext &
C)
const;
118 NonLocalizedStringBRVisitor(
const MemRegion *NonLocalizedString)
119 : NonLocalizedString(NonLocalizedString), Satisfied(
false) {
120 assert(NonLocalizedString);
127 void Profile(llvm::FoldingSetNodeID &ID)
const override {
128 ID.Add(NonLocalizedString);
133#define NEW_RECEIVER(receiver) \
134 llvm::DenseMap<Selector, uint8_t> &receiver##M = \
135 UIMethods[&Ctx.Idents.get(#receiver)];
136#define ADD_NULLARY_METHOD(receiver, method, argument) \
137 receiver##M.insert( \
138 {Ctx.Selectors.getNullarySelector(&Ctx.Idents.get(#method)), argument});
139#define ADD_UNARY_METHOD(receiver, method, argument) \
140 receiver##M.insert( \
141 {Ctx.Selectors.getUnarySelector(&Ctx.Idents.get(#method)), argument});
142#define ADD_METHOD(receiver, method_list, count, argument) \
143 receiver##M.insert({Ctx.Selectors.getSelector(count, method_list), argument});
147void NonLocalizedStringChecker::initUIMethods(
ASTContext &Ctx)
const {
148 if (!UIMethods.empty())
159 ADD_METHOD(UITabBarItem, initWithTitleUITabBarItemTag, 3, 0)
163 ADD_METHOD(UITabBarItem, initWithTitleUITabBarItemImage, 3, 0)
173 const IdentifierInfo *rowActionWithStyleUITableViewRowAction[] = {
176 ADD_METHOD(UITableViewRowAction, rowActionWithStyleUITableViewRowAction, 3, 1)
188 ADD_METHOD(NSButton, radioButtonWithTitleNSButton, 3, 0)
192 ADD_METHOD(NSButton, buttonWithTitleNSButtonImage, 4, 0)
196 ADD_METHOD(NSButton, checkboxWithTitleNSButton, 3, 0)
200 ADD_METHOD(NSButton, buttonWithTitleNSButtonTarget, 3, 0)
219 ADD_METHOD(NSBrowser, setTitleNSBrowser, 2, 0)
230 ADD_METHOD(UIAlertAction, actionWithTitleUIAlertAction, 3, 0)
236 ADD_METHOD(NSPopUpButton, insertItemWithTitleNSPopUpButton, 2, 0)
242 const IdentifierInfo *rowActionWithStyleNSTableViewRowAction[] = {
245 ADD_METHOD(NSTableViewRowAction, rowActionWithStyleNSTableViewRowAction, 3, 1)
277 ADD_METHOD(NSSegmentedControl, setLabelNSSegmentedControl, 2, 0)
280 ADD_METHOD(NSSegmentedControl, setToolTipNSSegmentedControl, 2, 0)
305 ADD_METHOD(NSMatrix, setToolTipNSMatrix, 2, 0)
321 ADD_METHOD(UIMenuItem, initWithTitleUIMenuItem, 2, 0)
325 const IdentifierInfo *alertControllerWithTitleUIAlertController[] = {
328 ADD_METHOD(UIAlertController, alertControllerWithTitleUIAlertController, 3, 1)
333 const IdentifierInfo *initWithTypeUIApplicationShortcutItemIcon[] = {
338 initWithTypeUIApplicationShortcutItemIcon, 5, 1)
341 ADD_METHOD(UIApplicationShortcutItem, initWithTypeUIApplicationShortcutItem,
348 &Ctx.
Idents.
get(
"destructiveButtonTitle"),
350 ADD_METHOD(UIActionSheet, initWithTitleUIActionSheet, 5, 0)
355 const IdentifierInfo *initWithNameUIAccessibilityCustomAction[] = {
359 initWithNameUIAccessibilityCustomAction, 3, 0)
386 ADD_METHOD(NSAttributedString, initWithStringNSAttributedString, 2, 0)
395 ADD_METHOD(UIKeyCommand, keyCommandWithInputUIKeyCommand, 4, 3)
405 &Ctx.
Idents.
get(
"informativeTextWithFormat")};
406 ADD_METHOD(NSAlert, alertWithMessageTextNSAlert, 5, 0)
425 ADD_METHOD(NSWindow, minFrameWidthWithTitleNSWindow, 2, 0)
432 const IdentifierInfo *addOptionWithTitleUIDocumentMenuViewController[] = {
436 addOptionWithTitleUIDocumentMenuViewController, 4, 0)
448 ADD_METHOD(UIAlertView, initWithTitleUIAlertView, 5, 0)
478 ADD_METHOD(NSSegmentedCell, setLabelNSSegmentedCell, 2, 0)
481 ADD_METHOD(NSSegmentedCell, setToolTipNSSegmentedCell, 2, 0)
492 ADD_METHOD(NSMenuItem, initWithTitleNSMenuItem, 3, 0)
499 ADD_METHOD(NSPopUpButtonCell, initTextCellNSPopUpButtonCell, 2, 0)
503 ADD_METHOD(NSPopUpButtonCell, insertItemWithTitleNSPopUpButtonCell, 2, 0)
516 ADD_METHOD(NSMenu, insertItemWithTitleNSMenu, 4, 0)
520 ADD_METHOD(NSMenu, addItemWithTitleNSMenu, 3, 0)
536 const IdentifierInfo *actionWithIdentifierNSUserNotificationAction[] = {
539 actionWithIdentifierNSUserNotificationAction, 2, 1)
549 ADD_METHOD(UIBarButtonItem, initWithTitleUIBarButtonItem, 4, 0)
555 const IdentifierInfo *insertSegmentWithTitleUISegmentedControl[] = {
558 ADD_METHOD(UISegmentedControl, insertSegmentWithTitleUISegmentedControl, 3, 0)
561 ADD_METHOD(UISegmentedControl, setTitleUISegmentedControl, 2, 0)
565 *initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult[] = {
566 &Ctx.
Idents.
get(
"initWithItemLoadingToken"),
568 ADD_METHOD(NSAccessibilityCustomRotorItemResult,
569 initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult, 2, 1)
573 const IdentifierInfo *contextualActionWithStyleUIContextualAction[] = {
576 ADD_METHOD(UIContextualAction, contextualActionWithStyleUIContextualAction, 3,
581 const IdentifierInfo *initWithLabelNSAccessibilityCustomRotor[] = {
584 initWithLabelNSAccessibilityCustomRotor, 2, 0)
592 const IdentifierInfo *initWithNameNSAccessibilityCustomAction[] = {
595 initWithNameNSAccessibilityCustomAction, 2, 0)
596 const IdentifierInfo *initWithNameTargetNSAccessibilityCustomAction[] = {
600 initWithNameTargetNSAccessibilityCustomAction, 3, 0)
604#define LSF_INSERT(function_name) LSF.insert(&Ctx.Idents.get(function_name));
605#define LSM_INSERT_NULLARY(receiver, method_name) \
606 LSM.insert({&Ctx.Idents.get(receiver), Ctx.Selectors.getNullarySelector( \
607 &Ctx.Idents.get(method_name))});
608#define LSM_INSERT_UNARY(receiver, method_name) \
609 LSM.insert({&Ctx.Idents.get(receiver), \
610 Ctx.Selectors.getUnarySelector(&Ctx.Idents.get(method_name))});
611#define LSM_INSERT_SELECTOR(receiver, method_list, arguments) \
612 LSM.insert({&Ctx.Idents.get(receiver), \
613 Ctx.Selectors.getSelector(arguments, method_list)});
616void NonLocalizedStringChecker::initLocStringsMethods(
ASTContext &Ctx)
const {
634 LSF_INSERT(
"CFDateFormatterCreateStringWithDate");
635 LSF_INSERT(
"CFDateFormatterCreateStringWithAbsoluteTime");
636 LSF_INSERT(
"CFNumberFormatterCreateStringWithNumber");
641bool NonLocalizedStringChecker::isAnnotatedAsReturningLocalized(
642 const Decl *D)
const {
647 return Ann->getAnnotation() ==
"returns_localized_nsstring";
653bool NonLocalizedStringChecker::isAnnotatedAsTakingLocalized(
654 const Decl *D)
const {
659 return Ann->getAnnotation() ==
"takes_localized_nsstring";
664bool NonLocalizedStringChecker::hasLocalizedState(SVal S,
665 CheckerContext &
C)
const {
668 const LocalizedState *LS =
C.getState()->get<LocalizedMemMap>(mt);
669 if (LS && LS->isLocalized())
677bool NonLocalizedStringChecker::hasNonLocalizedState(SVal S,
678 CheckerContext &
C)
const {
681 const LocalizedState *LS =
C.getState()->get<LocalizedMemMap>(mt);
682 if (LS && LS->isNonLocalized())
689void NonLocalizedStringChecker::setLocalizedState(
const SVal S,
690 CheckerContext &
C)
const {
694 C.getState()->set<LocalizedMemMap>(mt, LocalizedState::getLocalized());
695 C.addTransition(State);
700void NonLocalizedStringChecker::setNonLocalizedState(
const SVal S,
701 CheckerContext &
C)
const {
705 mt, LocalizedState::getNonLocalized());
706 C.addTransition(State);
712 return StringRef(name).contains_insensitive(
"debug");
720 const Decl *D =
C.getCurrentAnalysisDeclContext()->getDecl();
724 if (
auto *ND = dyn_cast<NamedDecl>(D)) {
731 if (
auto *CD = dyn_cast<ObjCContainerDecl>(DC)) {
741void NonLocalizedStringChecker::reportLocalizationError(
742 SVal S,
const CallEvent &M, CheckerContext &
C,
int argumentNumber)
const {
749 ExplodedNode *ErrNode =
C.generateNonFatalErrorNode();
755 auto R = std::make_unique<PathSensitiveBugReport>(
756 BT,
"User-facing text should use localized string macro", ErrNode);
757 if (argumentNumber) {
762 R->markInteresting(S);
766 R->addVisitor(std::make_unique<NonLocalizedStringBRVisitor>(StringRegion));
768 C.emitReport(std::move(R));
773int NonLocalizedStringChecker::getLocalizedArgumentForSelector(
774 const IdentifierInfo *Receiver, Selector S)
const {
775 auto method = UIMethods.find(Receiver);
777 if (method == UIMethods.end())
780 auto argumentIterator = method->getSecond().find(S);
782 if (argumentIterator == method->getSecond().end())
785 int argumentNumber = argumentIterator->getSecond();
786 return argumentNumber;
790void NonLocalizedStringChecker::checkPreObjCMessage(
const ObjCMethodCall &msg,
791 CheckerContext &
C)
const {
792 initUIMethods(
C.getASTContext());
802 StringRef SelectorName = SelectorString;
803 assert(!SelectorName.empty());
805 if (odInfo->
isStr(
"NSString")) {
809 if (!(SelectorName.starts_with(
"drawAtPoint") ||
810 SelectorName.starts_with(
"drawInRect") ||
811 SelectorName.starts_with(
"drawWithRect")))
816 bool isNonLocalized = hasNonLocalizedState(svTitle,
C);
818 if (isNonLocalized) {
819 reportLocalizationError(svTitle, msg,
C);
823 int argumentNumber = getLocalizedArgumentForSelector(odInfo, S);
825 while (argumentNumber < 0 && OD->getSuperClass() !=
nullptr) {
827 argumentNumber = getLocalizedArgumentForSelector(P->getIdentifier(), S);
828 if (argumentNumber >= 0)
831 if (argumentNumber < 0) {
833 argumentNumber = getLocalizedArgumentForSelector(OD->
getIdentifier(), S);
837 if (argumentNumber < 0) {
838 if (
const Decl *D = msg.
getDecl()) {
839 if (
const ObjCMethodDecl *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
840 for (
auto [Idx, FormalParam] : llvm::enumerate(OMD->parameters())) {
841 if (isAnnotatedAsTakingLocalized(FormalParam)) {
842 argumentNumber = Idx;
850 if (argumentNumber < 0)
853 SVal svTitle = msg.
getArgSVal(argumentNumber);
855 if (
const ObjCStringRegion *SR =
856 dyn_cast_or_null<ObjCStringRegion>(svTitle.
getAsRegion())) {
857 StringRef stringValue =
858 SR->getObjCStringLiteral()->getString()->getString();
859 if ((stringValue.trim().size() == 0 && stringValue.size() > 0) ||
862 if (!IsAggressive && llvm::sys::unicode::columnWidthUTF8(stringValue) < 2)
866 bool isNonLocalized = hasNonLocalizedState(svTitle,
C);
868 if (isNonLocalized) {
869 reportLocalizationError(svTitle, msg,
C, argumentNumber + 1);
873void NonLocalizedStringChecker::checkPreCall(
const CallEvent &
Call,
874 CheckerContext &
C)
const {
875 const auto *FD = dyn_cast_or_null<FunctionDecl>(
Call.getDecl());
879 auto formals = FD->parameters();
880 for (
unsigned i = 0, ei = std::min(
static_cast<unsigned>(formals.size()),
881 Call.getNumArgs()); i != ei; ++i) {
882 if (isAnnotatedAsTakingLocalized(formals[i])) {
883 auto actual =
Call.getArgSVal(i);
884 if (hasNonLocalizedState(actual,
C)) {
885 reportLocalizationError(actual,
Call,
C, i + 1);
904 return ClsName == &Ctx.
Idents.
get(
"NSString") ||
905 ClsName == &Ctx.
Idents.
get(
"NSMutableString");
913void NonLocalizedStringChecker::checkPostCall(
const CallEvent &
Call,
914 CheckerContext &
C)
const {
915 initLocStringsMethods(
C.getASTContext());
917 if (!
Call.getOriginExpr())
923 const QualType RT =
Call.getResultType();
925 for (
unsigned i = 0; i <
Call.getNumArgs(); ++i) {
926 SVal argValue =
Call.getArgSVal(i);
927 if (hasLocalizedState(argValue,
C)) {
928 SVal sv =
Call.getReturnValue();
929 setLocalizedState(sv,
C);
939 const IdentifierInfo *Identifier =
Call.getCalleeIdentifier();
941 SVal sv =
Call.getReturnValue();
942 if (isAnnotatedAsReturningLocalized(D) || LSF.contains(Identifier)) {
943 setLocalizedState(sv,
C);
945 !hasLocalizedState(sv,
C)) {
947 setNonLocalizedState(sv,
C);
949 const SymbolicRegion *SymReg =
950 dyn_cast_or_null<SymbolicRegion>(sv.
getAsRegion());
952 setNonLocalizedState(sv,
C);
959void NonLocalizedStringChecker::checkPostObjCMessage(
const ObjCMethodCall &msg,
960 CheckerContext &
C)
const {
961 initLocStringsMethods(
C.getASTContext());
973 std::pair<const IdentifierInfo *, Selector> MethodDescription = {odInfo, S};
975 if (LSM.count(MethodDescription) ||
976 isAnnotatedAsReturningLocalized(msg.
getDecl())) {
978 setLocalizedState(sv,
C);
983void NonLocalizedStringChecker::checkPostStmt(
const ObjCStringLiteral *SL,
984 CheckerContext &
C)
const {
985 SVal sv =
C.getSVal(SL);
986 setNonLocalizedState(sv,
C);
990NonLocalizedStringBRVisitor::VisitNode(
const ExplodedNode *Succ,
991 BugReporterContext &BRC,
992 PathSensitiveBugReport &BR) {
1000 auto *LiteralExpr = dyn_cast<ObjCStringLiteral>(Point->getStmt());
1004 SVal LiteralSVal = Succ->
getSVal(LiteralExpr);
1005 if (LiteralSVal.
getAsRegion() != NonLocalizedString)
1010 PathDiagnosticLocation L =
1016 auto Piece = std::make_shared<PathDiagnosticEventPiece>(
1017 L,
"Non-localized string literal here");
1018 Piece->addRange(LiteralExpr->getSourceRange());
1020 return std::move(Piece);
1024class EmptyLocalizationContextChecker
1025 :
public Checker<check::ASTDecl<ObjCImplementationDecl>> {
1028 class MethodCrawler :
public ConstStmtVisitor<MethodCrawler> {
1029 const ObjCMethodDecl *MD;
1031 AnalysisManager &Mgr;
1032 const CheckerBase *Checker;
1036 MethodCrawler(
const ObjCMethodDecl *InMD, BugReporter &InBR,
1037 const CheckerBase *Checker, AnalysisManager &InMgr,
1038 AnalysisDeclContext *InDCtx)
1039 : MD(InMD), BR(InBR), Mgr(InMgr), Checker(Checker), DCtx(InDCtx) {}
1041 void VisitStmt(
const Stmt *S) { VisitChildren(S); }
1043 void VisitObjCMessageExpr(
const ObjCMessageExpr *ME);
1045 void reportEmptyContextError(
const ObjCMessageExpr *M)
const;
1047 void VisitChildren(
const Stmt *S) {
1048 for (
const Stmt *Child : S->
children()) {
1056 void checkASTDecl(
const ObjCImplementationDecl *D, AnalysisManager &Mgr,
1057 BugReporter &BR)
const;
1061void EmptyLocalizationContextChecker::checkASTDecl(
1062 const ObjCImplementationDecl *D, AnalysisManager &Mgr,
1063 BugReporter &BR)
const {
1065 for (
const ObjCMethodDecl *M : D->
methods()) {
1068 const Stmt *Body = M->getBody();
1070 assert(M->isSynthesizedAccessorStub());
1074 MethodCrawler MC(M->getCanonicalDecl(), BR,
this, Mgr, DCtx);
1094void EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr(
1095 const ObjCMessageExpr *ME) {
1105 if (!(odInfo->
isStr(
"NSBundle") &&
1107 "localizedStringForKey:value:table:")) {
1112 if (!
R.getBegin().isMacroID())
1132 std::optional<llvm::MemoryBufferRef> BF =
1136 LangOptions LangOpts;
1137 Lexer TheLexer(SL, LangOpts, BF->getBufferStart(),
1138 BF->getBufferStart() + SLInfo.second, BF->getBufferEnd());
1143 while (!TheLexer.LexFromRawLexer(I)) {
1144 if (I.
getKind() == tok::l_paren)
1146 if (I.
getKind() == tok::r_paren) {
1155 if (
Result.getRawIdentifier() ==
"nil") {
1156 reportEmptyContextError(ME);
1165 StringRef(
Result.getLiteralData(),
Result.getLength()).trim(
'"');
1167 if ((Comment.trim().size() == 0 && Comment.size() > 0) ||
1169 reportEmptyContextError(ME);
1173void EmptyLocalizationContextChecker::MethodCrawler::reportEmptyContextError(
1174 const ObjCMessageExpr *ME)
const {
1177 "Localizability Issue (Apple)",
1178 "Localized string macro should include a non-empty "
1179 "comment for translators",
1184class PluralMisuseChecker :
public Checker<check::ASTCodeBody> {
1189 const CheckerBase *Checker;
1190 AnalysisDeclContext *AC;
1195 llvm::SmallVector<const clang::Stmt *, 8> MatchingStatements;
1198 bool InMatchingStatement =
false;
1201 explicit MethodCrawler(BugReporter &InBR,
const CheckerBase *Checker,
1202 AnalysisDeclContext *InAC)
1203 : BR(InBR), Checker(Checker), AC(InAC) {}
1205 bool VisitIfStmt(IfStmt *I)
override;
1206 bool EndVisitIfStmt(IfStmt *I);
1207 bool TraverseIfStmt(IfStmt *x)
override;
1208 bool VisitConditionalOperator(ConditionalOperator *
C)
override;
1209 bool TraverseConditionalOperator(ConditionalOperator *
C)
override;
1210 bool VisitCallExpr(CallExpr *CE)
override;
1211 bool VisitObjCMessageExpr(ObjCMessageExpr *ME)
override;
1214 void reportPluralMisuseError(
const Stmt *S)
const;
1215 bool isCheckingPlurality(
const Expr *E)
const;
1219 void checkASTCodeBody(
const Decl *D, AnalysisManager &Mgr,
1220 BugReporter &BR)
const {
1222 Visitor.TraverseDecl(
const_cast<Decl *
>(D));
1231bool PluralMisuseChecker::MethodCrawler::isCheckingPlurality(
1233 const BinaryOperator *BO =
nullptr;
1235 if (
const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(
Condition)) {
1236 if (
const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
1237 const Expr *InitExpr = VD->getInit();
1239 if (
const BinaryOperator *B =
1244 if (VD->getName().contains_insensitive(
"plural") ||
1245 VD->getName().contains_insensitive(
"singular")) {
1249 }
else if (
const BinaryOperator *B = dyn_cast<BinaryOperator>(
Condition)) {
1256 if (IntegerLiteral *IL = dyn_cast_or_null<IntegerLiteral>(
1258 llvm::APInt
Value = IL->getValue();
1270bool PluralMisuseChecker::MethodCrawler::VisitCallExpr(CallExpr *CE) {
1271 if (InMatchingStatement) {
1273 std::string NormalizedName =
1274 StringRef(FD->getNameInfo().getAsString()).lower();
1275 if (NormalizedName.find(
"loc") != std::string::npos) {
1276 for (
const Expr *Arg : CE->
arguments()) {
1278 reportPluralMisuseError(CE);
1291bool PluralMisuseChecker::MethodCrawler::VisitObjCMessageExpr(
1292 ObjCMessageExpr *ME) {
1299 if (odInfo->
isStr(
"NSBundle") &&
1301 if (InMatchingStatement) {
1302 reportPluralMisuseError(ME);
1309bool PluralMisuseChecker::MethodCrawler::TraverseIfStmt(IfStmt *I) {
1310 DynamicRecursiveASTVisitor::TraverseIfStmt(I);
1311 return EndVisitIfStmt(I);
1317bool PluralMisuseChecker::MethodCrawler::EndVisitIfStmt(IfStmt *I) {
1318 MatchingStatements.pop_back();
1319 if (!MatchingStatements.empty()) {
1320 if (MatchingStatements.back() !=
nullptr) {
1321 InMatchingStatement =
true;
1325 InMatchingStatement =
false;
1329bool PluralMisuseChecker::MethodCrawler::VisitIfStmt(IfStmt *I) {
1335 MatchingStatements.push_back(I);
1336 InMatchingStatement =
true;
1338 MatchingStatements.push_back(
nullptr);
1339 InMatchingStatement =
false;
1346bool PluralMisuseChecker::MethodCrawler::TraverseConditionalOperator(
1347 ConditionalOperator *
C) {
1348 DynamicRecursiveASTVisitor::TraverseConditionalOperator(
C);
1349 MatchingStatements.pop_back();
1350 if (!MatchingStatements.empty()) {
1351 if (MatchingStatements.back() !=
nullptr)
1352 InMatchingStatement =
true;
1354 InMatchingStatement =
false;
1356 InMatchingStatement =
false;
1361bool PluralMisuseChecker::MethodCrawler::VisitConditionalOperator(
1362 ConditionalOperator *
C) {
1363 const Expr *
Condition =
C->getCond()->IgnoreParenImpCasts();
1365 MatchingStatements.push_back(
C);
1366 InMatchingStatement =
true;
1368 MatchingStatements.push_back(
nullptr);
1369 InMatchingStatement =
false;
1374void PluralMisuseChecker::MethodCrawler::reportPluralMisuseError(
1375 const Stmt *S)
const {
1378 "Localizability Issue (Apple)",
1379 "Plural cases are not supported across all languages; "
1380 "use a .stringsdict file instead",
1388void ento::registerNonLocalizedStringChecker(CheckerManager &mgr) {
1389 NonLocalizedStringChecker *checker =
1391 checker->IsAggressive =
1393 checker,
"AggressiveReport");
1396bool ento::shouldRegisterNonLocalizedStringChecker(
const CheckerManager &mgr) {
1400void ento::registerEmptyLocalizationContextChecker(CheckerManager &mgr) {
1404bool ento::shouldRegisterEmptyLocalizationContextChecker(
1405 const CheckerManager &mgr) {
1409void ento::registerPluralMisuseChecker(CheckerManager &mgr) {
1413bool ento::shouldRegisterPluralMisuseChecker(
const CheckerManager &mgr) {
Result
Implement __builtin_bit_cast and related operations.
#define LSM_INSERT_SELECTOR(receiver, method_list, arguments)
#define NEW_RECEIVER(receiver)
#define LSM_INSERT_NULLARY(receiver, method_name)
#define LSF_INSERT(function_name)
#define ADD_UNARY_METHOD(receiver, method, argument)
#define ADD_METHOD(receiver, method_list, count, argument)
#define LSM_INSERT_UNARY(receiver, method_name)
static bool isDebuggingContext(CheckerContext &C)
Returns true when, heuristically, the analyzer may be analyzing debugging code.
static bool isDebuggingName(std::string name)
static bool isNSStringType(QualType T, ASTContext &Ctx)
#define REGISTER_MAP_WITH_PROGRAMSTATE(Name, Key, Value)
Declares an immutable map of type NameTy, suitable for placement into the ProgramState.
Defines the SourceManager interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
FunctionDecl * getDirectCallee()
If the callee is a FunctionDecl, return it. Otherwise return null.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Decl - This represents one declaration (or definition), e.g.
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
DeclContext * getDeclContext()
Expr * IgnoreParenImpCasts() LLVM_READONLY
Skip past any parentheses and implicit casts which might surround this expression until reaching a fi...
One of these records is kept for each identifier that is lexed.
bool isStr(const char(&Str)[StrLen]) const
Return true if this is the identifier for the specified string.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
method_range methods() const
Represents an ObjC class declaration.
all_protocol_range all_referenced_protocols() const
ObjCInterfaceDecl * getSuperClass() const
Selector getSelector() const
ObjCInterfaceDecl * getReceiverInterface() const
Retrieve the Objective-C interface to which this message is being directed, if known.
Represents a pointer to an Objective C object.
const ObjCObjectType * getObjectType() const
Gets the type pointed to by this ObjC pointer.
std::optional< T > getAs() const
Convert to the specified ProgramPoint type, returning std::nullopt if this ProgramPoint is not of the...
A (possibly-)qualified type.
std::string getAsString() const
Derive the full selector name (e.g.
bool isValid() const
Return true if this is a valid SourceLocation object.
FileIDAndOffset getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
SourceLocation getImmediateMacroCallerLoc(SourceLocation Loc) const
Gets the location of the immediate macro caller, one level up the stack toward the initial macro type...
std::optional< llvm::MemoryBufferRef > getBufferOrNone(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
SourceLocation getSpellingLoc() const
const ExpansionInfo & getExpansion() const
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
tok::TokenKind getKind() const
const T * getAs() const
Member-template getAs<specific type>'.
AnalysisDeclContext * getAnalysisDeclContext(const Decl *D)
SourceManager & getSourceManager() override
const SourceManager & getSourceManager() const
BugReporterVisitors are used to add custom diagnostics along a path.
virtual void Profile(llvm::FoldingSetNodeID &ID) const =0
virtual PathDiagnosticPieceRef VisitNode(const ExplodedNode *Succ, BugReporterContext &BRC, PathSensitiveBugReport &BR)=0
Return a diagnostic piece which should be associated with the given node.
const SourceManager & getSourceManager()
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerFrontend *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges={}, ArrayRef< FixItHint > Fixits={})
virtual SVal getArgSVal(unsigned Index) const
Returns the value of a given argument at the time of the call.
virtual const Expr * getArgExpr(unsigned Index) const
Returns the expression associated with a given argument.
SVal getReturnValue() const
Returns the return value of the call.
virtual SourceRange getSourceRange() const
Returns a source range for the entire call, suitable for outputting in diagnostics.
const AnalyzerOptions & getAnalyzerOptions() const
CHECKER * registerChecker(AT &&...Args)
Register a single-part checker (derived from Checker): construct its singleton instance,...
Simple checker classes that implement one frontend (i.e.
SVal getSVal(const Expr *E) const
Get the value of an arbitrary expression at this node.
ProgramPoint getLocation() const
getLocation - Returns the edge associated with the given node.
MemRegion - The root abstract class for all memory regions.
const ObjCMethodDecl * getDecl() const override
Returns the declaration of the function or method that will be called.
bool isInstanceMessage() const
SVal getReceiverSVal() const
Returns the value of the receiver at the time of this call.
const ObjCInterfaceDecl * getReceiverInterface() const
Get the interface for the receiver.
Selector getSelector() const
FullSourceLoc asLocation() const
static PathDiagnosticLocation create(const Decl *D, const SourceManager &SM)
Create a location corresponding to the given declaration.
const MemRegion * getAsRegion() const
llvm::PointerUnion< const StackFrame *, AnalysisDeclContext * > StackFrameOrAnalysisDeclContext
IntrusiveRefCntPtr< const ProgramState > ProgramStateRef
std::shared_ptr< PathDiagnosticPiece > PathDiagnosticPieceRef
std::variant< struct RequiresDecl, struct HeaderDecl, struct UmbrellaDirDecl, struct ModuleDecl, struct ExcludeDecl, struct ExportDecl, struct ExportAsDecl, struct ExternModuleDecl, struct UseDecl, struct LinkDecl, struct ConfigMacrosDecl, struct ConflictDecl > Decl
All declarations that can appear in a module declaration.
bool isStringLiteral(TokenKind K)
Return true if this is a C or C++ string-literal (or C++11 user-defined-string-literal) token.
bool isAnyIdentifier(TokenKind K)
Return true if this is a raw identifier or an identifier kind.
Top level wrappers for InstallAPI frontend operations.
bool isa(CodeGen::Address addr)
std::pair< FileID, unsigned > FileIDAndOffset
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
DynamicRecursiveASTVisitorBase< false > DynamicRecursiveASTVisitor