LocalizationChecker.cpp 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. //=- LocalizationChecker.cpp -------------------------------------*- C++ -*-==//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines a set of checks for localizability including:
  10. // 1) A checker that warns about uses of non-localized NSStrings passed to
  11. // UI methods expecting localized strings
  12. // 2) A syntactic checker that warns against the bad practice of
  13. // not including a comment in NSLocalizedString macros.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
  17. #include "clang/AST/Attr.h"
  18. #include "clang/AST/Decl.h"
  19. #include "clang/AST/DeclObjC.h"
  20. #include "clang/AST/RecursiveASTVisitor.h"
  21. #include "clang/AST/StmtVisitor.h"
  22. #include "clang/Lex/Lexer.h"
  23. #include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"
  24. #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
  25. #include "clang/StaticAnalyzer/Core/Checker.h"
  26. #include "clang/StaticAnalyzer/Core/CheckerManager.h"
  27. #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
  28. #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
  29. #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
  30. #include "llvm/Support/Unicode.h"
  31. using namespace clang;
  32. using namespace ento;
  33. namespace {
  34. struct LocalizedState {
  35. private:
  36. enum Kind { NonLocalized, Localized } K;
  37. LocalizedState(Kind InK) : K(InK) {}
  38. public:
  39. bool isLocalized() const { return K == Localized; }
  40. bool isNonLocalized() const { return K == NonLocalized; }
  41. static LocalizedState getLocalized() { return LocalizedState(Localized); }
  42. static LocalizedState getNonLocalized() {
  43. return LocalizedState(NonLocalized);
  44. }
  45. // Overload the == operator
  46. bool operator==(const LocalizedState &X) const { return K == X.K; }
  47. // LLVMs equivalent of a hash function
  48. void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(K); }
  49. };
  50. class NonLocalizedStringChecker
  51. : public Checker<check::PreCall, check::PostCall, check::PreObjCMessage,
  52. check::PostObjCMessage,
  53. check::PostStmt<ObjCStringLiteral>> {
  54. mutable std::unique_ptr<BugType> BT;
  55. // Methods that require a localized string
  56. mutable llvm::DenseMap<const IdentifierInfo *,
  57. llvm::DenseMap<Selector, uint8_t>> UIMethods;
  58. // Methods that return a localized string
  59. mutable llvm::SmallSet<std::pair<const IdentifierInfo *, Selector>, 12> LSM;
  60. // C Functions that return a localized string
  61. mutable llvm::SmallSet<const IdentifierInfo *, 5> LSF;
  62. void initUIMethods(ASTContext &Ctx) const;
  63. void initLocStringsMethods(ASTContext &Ctx) const;
  64. bool hasNonLocalizedState(SVal S, CheckerContext &C) const;
  65. bool hasLocalizedState(SVal S, CheckerContext &C) const;
  66. void setNonLocalizedState(SVal S, CheckerContext &C) const;
  67. void setLocalizedState(SVal S, CheckerContext &C) const;
  68. bool isAnnotatedAsReturningLocalized(const Decl *D) const;
  69. bool isAnnotatedAsTakingLocalized(const Decl *D) const;
  70. void reportLocalizationError(SVal S, const CallEvent &M, CheckerContext &C,
  71. int argumentNumber = 0) const;
  72. int getLocalizedArgumentForSelector(const IdentifierInfo *Receiver,
  73. Selector S) const;
  74. public:
  75. NonLocalizedStringChecker();
  76. // When this parameter is set to true, the checker assumes all
  77. // methods that return NSStrings are unlocalized. Thus, more false
  78. // positives will be reported.
  79. DefaultBool IsAggressive;
  80. void checkPreObjCMessage(const ObjCMethodCall &msg, CheckerContext &C) const;
  81. void checkPostObjCMessage(const ObjCMethodCall &msg, CheckerContext &C) const;
  82. void checkPostStmt(const ObjCStringLiteral *SL, CheckerContext &C) const;
  83. void checkPreCall(const CallEvent &Call, CheckerContext &C) const;
  84. void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
  85. };
  86. } // end anonymous namespace
  87. REGISTER_MAP_WITH_PROGRAMSTATE(LocalizedMemMap, const MemRegion *,
  88. LocalizedState)
  89. NonLocalizedStringChecker::NonLocalizedStringChecker() {
  90. BT.reset(new BugType(this, "Unlocalizable string",
  91. "Localizability Issue (Apple)"));
  92. }
  93. namespace {
  94. class NonLocalizedStringBRVisitor final : public BugReporterVisitor {
  95. const MemRegion *NonLocalizedString;
  96. bool Satisfied;
  97. public:
  98. NonLocalizedStringBRVisitor(const MemRegion *NonLocalizedString)
  99. : NonLocalizedString(NonLocalizedString), Satisfied(false) {
  100. assert(NonLocalizedString);
  101. }
  102. std::shared_ptr<PathDiagnosticPiece> VisitNode(const ExplodedNode *Succ,
  103. BugReporterContext &BRC,
  104. BugReport &BR) override;
  105. void Profile(llvm::FoldingSetNodeID &ID) const override {
  106. ID.Add(NonLocalizedString);
  107. }
  108. };
  109. } // End anonymous namespace.
  110. #define NEW_RECEIVER(receiver) \
  111. llvm::DenseMap<Selector, uint8_t> &receiver##M = \
  112. UIMethods.insert({&Ctx.Idents.get(#receiver), \
  113. llvm::DenseMap<Selector, uint8_t>()}) \
  114. .first->second;
  115. #define ADD_NULLARY_METHOD(receiver, method, argument) \
  116. receiver##M.insert( \
  117. {Ctx.Selectors.getNullarySelector(&Ctx.Idents.get(#method)), argument});
  118. #define ADD_UNARY_METHOD(receiver, method, argument) \
  119. receiver##M.insert( \
  120. {Ctx.Selectors.getUnarySelector(&Ctx.Idents.get(#method)), argument});
  121. #define ADD_METHOD(receiver, method_list, count, argument) \
  122. receiver##M.insert({Ctx.Selectors.getSelector(count, method_list), argument});
  123. /// Initializes a list of methods that require a localized string
  124. /// Format: {"ClassName", {{"selectorName:", LocStringArg#}, ...}, ...}
  125. void NonLocalizedStringChecker::initUIMethods(ASTContext &Ctx) const {
  126. if (!UIMethods.empty())
  127. return;
  128. // UI Methods
  129. NEW_RECEIVER(UISearchDisplayController)
  130. ADD_UNARY_METHOD(UISearchDisplayController, setSearchResultsTitle, 0)
  131. NEW_RECEIVER(UITabBarItem)
  132. IdentifierInfo *initWithTitleUITabBarItemTag[] = {
  133. &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("image"),
  134. &Ctx.Idents.get("tag")};
  135. ADD_METHOD(UITabBarItem, initWithTitleUITabBarItemTag, 3, 0)
  136. IdentifierInfo *initWithTitleUITabBarItemImage[] = {
  137. &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("image"),
  138. &Ctx.Idents.get("selectedImage")};
  139. ADD_METHOD(UITabBarItem, initWithTitleUITabBarItemImage, 3, 0)
  140. NEW_RECEIVER(NSDockTile)
  141. ADD_UNARY_METHOD(NSDockTile, setBadgeLabel, 0)
  142. NEW_RECEIVER(NSStatusItem)
  143. ADD_UNARY_METHOD(NSStatusItem, setTitle, 0)
  144. ADD_UNARY_METHOD(NSStatusItem, setToolTip, 0)
  145. NEW_RECEIVER(UITableViewRowAction)
  146. IdentifierInfo *rowActionWithStyleUITableViewRowAction[] = {
  147. &Ctx.Idents.get("rowActionWithStyle"), &Ctx.Idents.get("title"),
  148. &Ctx.Idents.get("handler")};
  149. ADD_METHOD(UITableViewRowAction, rowActionWithStyleUITableViewRowAction, 3, 1)
  150. ADD_UNARY_METHOD(UITableViewRowAction, setTitle, 0)
  151. NEW_RECEIVER(NSBox)
  152. ADD_UNARY_METHOD(NSBox, setTitle, 0)
  153. NEW_RECEIVER(NSButton)
  154. ADD_UNARY_METHOD(NSButton, setTitle, 0)
  155. ADD_UNARY_METHOD(NSButton, setAlternateTitle, 0)
  156. IdentifierInfo *radioButtonWithTitleNSButton[] = {
  157. &Ctx.Idents.get("radioButtonWithTitle"), &Ctx.Idents.get("target"),
  158. &Ctx.Idents.get("action")};
  159. ADD_METHOD(NSButton, radioButtonWithTitleNSButton, 3, 0)
  160. IdentifierInfo *buttonWithTitleNSButtonImage[] = {
  161. &Ctx.Idents.get("buttonWithTitle"), &Ctx.Idents.get("image"),
  162. &Ctx.Idents.get("target"), &Ctx.Idents.get("action")};
  163. ADD_METHOD(NSButton, buttonWithTitleNSButtonImage, 4, 0)
  164. IdentifierInfo *checkboxWithTitleNSButton[] = {
  165. &Ctx.Idents.get("checkboxWithTitle"), &Ctx.Idents.get("target"),
  166. &Ctx.Idents.get("action")};
  167. ADD_METHOD(NSButton, checkboxWithTitleNSButton, 3, 0)
  168. IdentifierInfo *buttonWithTitleNSButtonTarget[] = {
  169. &Ctx.Idents.get("buttonWithTitle"), &Ctx.Idents.get("target"),
  170. &Ctx.Idents.get("action")};
  171. ADD_METHOD(NSButton, buttonWithTitleNSButtonTarget, 3, 0)
  172. NEW_RECEIVER(NSSavePanel)
  173. ADD_UNARY_METHOD(NSSavePanel, setPrompt, 0)
  174. ADD_UNARY_METHOD(NSSavePanel, setTitle, 0)
  175. ADD_UNARY_METHOD(NSSavePanel, setNameFieldLabel, 0)
  176. ADD_UNARY_METHOD(NSSavePanel, setNameFieldStringValue, 0)
  177. ADD_UNARY_METHOD(NSSavePanel, setMessage, 0)
  178. NEW_RECEIVER(UIPrintInfo)
  179. ADD_UNARY_METHOD(UIPrintInfo, setJobName, 0)
  180. NEW_RECEIVER(NSTabViewItem)
  181. ADD_UNARY_METHOD(NSTabViewItem, setLabel, 0)
  182. ADD_UNARY_METHOD(NSTabViewItem, setToolTip, 0)
  183. NEW_RECEIVER(NSBrowser)
  184. IdentifierInfo *setTitleNSBrowser[] = {&Ctx.Idents.get("setTitle"),
  185. &Ctx.Idents.get("ofColumn")};
  186. ADD_METHOD(NSBrowser, setTitleNSBrowser, 2, 0)
  187. NEW_RECEIVER(UIAccessibilityElement)
  188. ADD_UNARY_METHOD(UIAccessibilityElement, setAccessibilityLabel, 0)
  189. ADD_UNARY_METHOD(UIAccessibilityElement, setAccessibilityHint, 0)
  190. ADD_UNARY_METHOD(UIAccessibilityElement, setAccessibilityValue, 0)
  191. NEW_RECEIVER(UIAlertAction)
  192. IdentifierInfo *actionWithTitleUIAlertAction[] = {
  193. &Ctx.Idents.get("actionWithTitle"), &Ctx.Idents.get("style"),
  194. &Ctx.Idents.get("handler")};
  195. ADD_METHOD(UIAlertAction, actionWithTitleUIAlertAction, 3, 0)
  196. NEW_RECEIVER(NSPopUpButton)
  197. ADD_UNARY_METHOD(NSPopUpButton, addItemWithTitle, 0)
  198. IdentifierInfo *insertItemWithTitleNSPopUpButton[] = {
  199. &Ctx.Idents.get("insertItemWithTitle"), &Ctx.Idents.get("atIndex")};
  200. ADD_METHOD(NSPopUpButton, insertItemWithTitleNSPopUpButton, 2, 0)
  201. ADD_UNARY_METHOD(NSPopUpButton, removeItemWithTitle, 0)
  202. ADD_UNARY_METHOD(NSPopUpButton, selectItemWithTitle, 0)
  203. ADD_UNARY_METHOD(NSPopUpButton, setTitle, 0)
  204. NEW_RECEIVER(NSTableViewRowAction)
  205. IdentifierInfo *rowActionWithStyleNSTableViewRowAction[] = {
  206. &Ctx.Idents.get("rowActionWithStyle"), &Ctx.Idents.get("title"),
  207. &Ctx.Idents.get("handler")};
  208. ADD_METHOD(NSTableViewRowAction, rowActionWithStyleNSTableViewRowAction, 3, 1)
  209. ADD_UNARY_METHOD(NSTableViewRowAction, setTitle, 0)
  210. NEW_RECEIVER(NSImage)
  211. ADD_UNARY_METHOD(NSImage, setAccessibilityDescription, 0)
  212. NEW_RECEIVER(NSUserActivity)
  213. ADD_UNARY_METHOD(NSUserActivity, setTitle, 0)
  214. NEW_RECEIVER(NSPathControlItem)
  215. ADD_UNARY_METHOD(NSPathControlItem, setTitle, 0)
  216. NEW_RECEIVER(NSCell)
  217. ADD_UNARY_METHOD(NSCell, initTextCell, 0)
  218. ADD_UNARY_METHOD(NSCell, setTitle, 0)
  219. ADD_UNARY_METHOD(NSCell, setStringValue, 0)
  220. NEW_RECEIVER(NSPathControl)
  221. ADD_UNARY_METHOD(NSPathControl, setPlaceholderString, 0)
  222. NEW_RECEIVER(UIAccessibility)
  223. ADD_UNARY_METHOD(UIAccessibility, setAccessibilityLabel, 0)
  224. ADD_UNARY_METHOD(UIAccessibility, setAccessibilityHint, 0)
  225. ADD_UNARY_METHOD(UIAccessibility, setAccessibilityValue, 0)
  226. NEW_RECEIVER(NSTableColumn)
  227. ADD_UNARY_METHOD(NSTableColumn, setTitle, 0)
  228. ADD_UNARY_METHOD(NSTableColumn, setHeaderToolTip, 0)
  229. NEW_RECEIVER(NSSegmentedControl)
  230. IdentifierInfo *setLabelNSSegmentedControl[] = {
  231. &Ctx.Idents.get("setLabel"), &Ctx.Idents.get("forSegment")};
  232. ADD_METHOD(NSSegmentedControl, setLabelNSSegmentedControl, 2, 0)
  233. IdentifierInfo *setToolTipNSSegmentedControl[] = {
  234. &Ctx.Idents.get("setToolTip"), &Ctx.Idents.get("forSegment")};
  235. ADD_METHOD(NSSegmentedControl, setToolTipNSSegmentedControl, 2, 0)
  236. NEW_RECEIVER(NSButtonCell)
  237. ADD_UNARY_METHOD(NSButtonCell, setTitle, 0)
  238. ADD_UNARY_METHOD(NSButtonCell, setAlternateTitle, 0)
  239. NEW_RECEIVER(NSDatePickerCell)
  240. ADD_UNARY_METHOD(NSDatePickerCell, initTextCell, 0)
  241. NEW_RECEIVER(NSSliderCell)
  242. ADD_UNARY_METHOD(NSSliderCell, setTitle, 0)
  243. NEW_RECEIVER(NSControl)
  244. ADD_UNARY_METHOD(NSControl, setStringValue, 0)
  245. NEW_RECEIVER(NSAccessibility)
  246. ADD_UNARY_METHOD(NSAccessibility, setAccessibilityValueDescription, 0)
  247. ADD_UNARY_METHOD(NSAccessibility, setAccessibilityLabel, 0)
  248. ADD_UNARY_METHOD(NSAccessibility, setAccessibilityTitle, 0)
  249. ADD_UNARY_METHOD(NSAccessibility, setAccessibilityPlaceholderValue, 0)
  250. ADD_UNARY_METHOD(NSAccessibility, setAccessibilityHelp, 0)
  251. NEW_RECEIVER(NSMatrix)
  252. IdentifierInfo *setToolTipNSMatrix[] = {&Ctx.Idents.get("setToolTip"),
  253. &Ctx.Idents.get("forCell")};
  254. ADD_METHOD(NSMatrix, setToolTipNSMatrix, 2, 0)
  255. NEW_RECEIVER(NSPrintPanel)
  256. ADD_UNARY_METHOD(NSPrintPanel, setDefaultButtonTitle, 0)
  257. NEW_RECEIVER(UILocalNotification)
  258. ADD_UNARY_METHOD(UILocalNotification, setAlertBody, 0)
  259. ADD_UNARY_METHOD(UILocalNotification, setAlertAction, 0)
  260. ADD_UNARY_METHOD(UILocalNotification, setAlertTitle, 0)
  261. NEW_RECEIVER(NSSlider)
  262. ADD_UNARY_METHOD(NSSlider, setTitle, 0)
  263. NEW_RECEIVER(UIMenuItem)
  264. IdentifierInfo *initWithTitleUIMenuItem[] = {&Ctx.Idents.get("initWithTitle"),
  265. &Ctx.Idents.get("action")};
  266. ADD_METHOD(UIMenuItem, initWithTitleUIMenuItem, 2, 0)
  267. ADD_UNARY_METHOD(UIMenuItem, setTitle, 0)
  268. NEW_RECEIVER(UIAlertController)
  269. IdentifierInfo *alertControllerWithTitleUIAlertController[] = {
  270. &Ctx.Idents.get("alertControllerWithTitle"), &Ctx.Idents.get("message"),
  271. &Ctx.Idents.get("preferredStyle")};
  272. ADD_METHOD(UIAlertController, alertControllerWithTitleUIAlertController, 3, 1)
  273. ADD_UNARY_METHOD(UIAlertController, setTitle, 0)
  274. ADD_UNARY_METHOD(UIAlertController, setMessage, 0)
  275. NEW_RECEIVER(UIApplicationShortcutItem)
  276. IdentifierInfo *initWithTypeUIApplicationShortcutItemIcon[] = {
  277. &Ctx.Idents.get("initWithType"), &Ctx.Idents.get("localizedTitle"),
  278. &Ctx.Idents.get("localizedSubtitle"), &Ctx.Idents.get("icon"),
  279. &Ctx.Idents.get("userInfo")};
  280. ADD_METHOD(UIApplicationShortcutItem,
  281. initWithTypeUIApplicationShortcutItemIcon, 5, 1)
  282. IdentifierInfo *initWithTypeUIApplicationShortcutItem[] = {
  283. &Ctx.Idents.get("initWithType"), &Ctx.Idents.get("localizedTitle")};
  284. ADD_METHOD(UIApplicationShortcutItem, initWithTypeUIApplicationShortcutItem,
  285. 2, 1)
  286. NEW_RECEIVER(UIActionSheet)
  287. IdentifierInfo *initWithTitleUIActionSheet[] = {
  288. &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("delegate"),
  289. &Ctx.Idents.get("cancelButtonTitle"),
  290. &Ctx.Idents.get("destructiveButtonTitle"),
  291. &Ctx.Idents.get("otherButtonTitles")};
  292. ADD_METHOD(UIActionSheet, initWithTitleUIActionSheet, 5, 0)
  293. ADD_UNARY_METHOD(UIActionSheet, addButtonWithTitle, 0)
  294. ADD_UNARY_METHOD(UIActionSheet, setTitle, 0)
  295. NEW_RECEIVER(UIAccessibilityCustomAction)
  296. IdentifierInfo *initWithNameUIAccessibilityCustomAction[] = {
  297. &Ctx.Idents.get("initWithName"), &Ctx.Idents.get("target"),
  298. &Ctx.Idents.get("selector")};
  299. ADD_METHOD(UIAccessibilityCustomAction,
  300. initWithNameUIAccessibilityCustomAction, 3, 0)
  301. ADD_UNARY_METHOD(UIAccessibilityCustomAction, setName, 0)
  302. NEW_RECEIVER(UISearchBar)
  303. ADD_UNARY_METHOD(UISearchBar, setText, 0)
  304. ADD_UNARY_METHOD(UISearchBar, setPrompt, 0)
  305. ADD_UNARY_METHOD(UISearchBar, setPlaceholder, 0)
  306. NEW_RECEIVER(UIBarItem)
  307. ADD_UNARY_METHOD(UIBarItem, setTitle, 0)
  308. NEW_RECEIVER(UITextView)
  309. ADD_UNARY_METHOD(UITextView, setText, 0)
  310. NEW_RECEIVER(NSView)
  311. ADD_UNARY_METHOD(NSView, setToolTip, 0)
  312. NEW_RECEIVER(NSTextField)
  313. ADD_UNARY_METHOD(NSTextField, setPlaceholderString, 0)
  314. ADD_UNARY_METHOD(NSTextField, textFieldWithString, 0)
  315. ADD_UNARY_METHOD(NSTextField, wrappingLabelWithString, 0)
  316. ADD_UNARY_METHOD(NSTextField, labelWithString, 0)
  317. NEW_RECEIVER(NSAttributedString)
  318. ADD_UNARY_METHOD(NSAttributedString, initWithString, 0)
  319. IdentifierInfo *initWithStringNSAttributedString[] = {
  320. &Ctx.Idents.get("initWithString"), &Ctx.Idents.get("attributes")};
  321. ADD_METHOD(NSAttributedString, initWithStringNSAttributedString, 2, 0)
  322. NEW_RECEIVER(NSText)
  323. ADD_UNARY_METHOD(NSText, setString, 0)
  324. NEW_RECEIVER(UIKeyCommand)
  325. IdentifierInfo *keyCommandWithInputUIKeyCommand[] = {
  326. &Ctx.Idents.get("keyCommandWithInput"), &Ctx.Idents.get("modifierFlags"),
  327. &Ctx.Idents.get("action"), &Ctx.Idents.get("discoverabilityTitle")};
  328. ADD_METHOD(UIKeyCommand, keyCommandWithInputUIKeyCommand, 4, 3)
  329. ADD_UNARY_METHOD(UIKeyCommand, setDiscoverabilityTitle, 0)
  330. NEW_RECEIVER(UILabel)
  331. ADD_UNARY_METHOD(UILabel, setText, 0)
  332. NEW_RECEIVER(NSAlert)
  333. IdentifierInfo *alertWithMessageTextNSAlert[] = {
  334. &Ctx.Idents.get("alertWithMessageText"), &Ctx.Idents.get("defaultButton"),
  335. &Ctx.Idents.get("alternateButton"), &Ctx.Idents.get("otherButton"),
  336. &Ctx.Idents.get("informativeTextWithFormat")};
  337. ADD_METHOD(NSAlert, alertWithMessageTextNSAlert, 5, 0)
  338. ADD_UNARY_METHOD(NSAlert, addButtonWithTitle, 0)
  339. ADD_UNARY_METHOD(NSAlert, setMessageText, 0)
  340. ADD_UNARY_METHOD(NSAlert, setInformativeText, 0)
  341. ADD_UNARY_METHOD(NSAlert, setHelpAnchor, 0)
  342. NEW_RECEIVER(UIMutableApplicationShortcutItem)
  343. ADD_UNARY_METHOD(UIMutableApplicationShortcutItem, setLocalizedTitle, 0)
  344. ADD_UNARY_METHOD(UIMutableApplicationShortcutItem, setLocalizedSubtitle, 0)
  345. NEW_RECEIVER(UIButton)
  346. IdentifierInfo *setTitleUIButton[] = {&Ctx.Idents.get("setTitle"),
  347. &Ctx.Idents.get("forState")};
  348. ADD_METHOD(UIButton, setTitleUIButton, 2, 0)
  349. NEW_RECEIVER(NSWindow)
  350. ADD_UNARY_METHOD(NSWindow, setTitle, 0)
  351. IdentifierInfo *minFrameWidthWithTitleNSWindow[] = {
  352. &Ctx.Idents.get("minFrameWidthWithTitle"), &Ctx.Idents.get("styleMask")};
  353. ADD_METHOD(NSWindow, minFrameWidthWithTitleNSWindow, 2, 0)
  354. ADD_UNARY_METHOD(NSWindow, setMiniwindowTitle, 0)
  355. NEW_RECEIVER(NSPathCell)
  356. ADD_UNARY_METHOD(NSPathCell, setPlaceholderString, 0)
  357. NEW_RECEIVER(UIDocumentMenuViewController)
  358. IdentifierInfo *addOptionWithTitleUIDocumentMenuViewController[] = {
  359. &Ctx.Idents.get("addOptionWithTitle"), &Ctx.Idents.get("image"),
  360. &Ctx.Idents.get("order"), &Ctx.Idents.get("handler")};
  361. ADD_METHOD(UIDocumentMenuViewController,
  362. addOptionWithTitleUIDocumentMenuViewController, 4, 0)
  363. NEW_RECEIVER(UINavigationItem)
  364. ADD_UNARY_METHOD(UINavigationItem, initWithTitle, 0)
  365. ADD_UNARY_METHOD(UINavigationItem, setTitle, 0)
  366. ADD_UNARY_METHOD(UINavigationItem, setPrompt, 0)
  367. NEW_RECEIVER(UIAlertView)
  368. IdentifierInfo *initWithTitleUIAlertView[] = {
  369. &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("message"),
  370. &Ctx.Idents.get("delegate"), &Ctx.Idents.get("cancelButtonTitle"),
  371. &Ctx.Idents.get("otherButtonTitles")};
  372. ADD_METHOD(UIAlertView, initWithTitleUIAlertView, 5, 0)
  373. ADD_UNARY_METHOD(UIAlertView, addButtonWithTitle, 0)
  374. ADD_UNARY_METHOD(UIAlertView, setTitle, 0)
  375. ADD_UNARY_METHOD(UIAlertView, setMessage, 0)
  376. NEW_RECEIVER(NSFormCell)
  377. ADD_UNARY_METHOD(NSFormCell, initTextCell, 0)
  378. ADD_UNARY_METHOD(NSFormCell, setTitle, 0)
  379. ADD_UNARY_METHOD(NSFormCell, setPlaceholderString, 0)
  380. NEW_RECEIVER(NSUserNotification)
  381. ADD_UNARY_METHOD(NSUserNotification, setTitle, 0)
  382. ADD_UNARY_METHOD(NSUserNotification, setSubtitle, 0)
  383. ADD_UNARY_METHOD(NSUserNotification, setInformativeText, 0)
  384. ADD_UNARY_METHOD(NSUserNotification, setActionButtonTitle, 0)
  385. ADD_UNARY_METHOD(NSUserNotification, setOtherButtonTitle, 0)
  386. ADD_UNARY_METHOD(NSUserNotification, setResponsePlaceholder, 0)
  387. NEW_RECEIVER(NSToolbarItem)
  388. ADD_UNARY_METHOD(NSToolbarItem, setLabel, 0)
  389. ADD_UNARY_METHOD(NSToolbarItem, setPaletteLabel, 0)
  390. ADD_UNARY_METHOD(NSToolbarItem, setToolTip, 0)
  391. NEW_RECEIVER(NSProgress)
  392. ADD_UNARY_METHOD(NSProgress, setLocalizedDescription, 0)
  393. ADD_UNARY_METHOD(NSProgress, setLocalizedAdditionalDescription, 0)
  394. NEW_RECEIVER(NSSegmentedCell)
  395. IdentifierInfo *setLabelNSSegmentedCell[] = {&Ctx.Idents.get("setLabel"),
  396. &Ctx.Idents.get("forSegment")};
  397. ADD_METHOD(NSSegmentedCell, setLabelNSSegmentedCell, 2, 0)
  398. IdentifierInfo *setToolTipNSSegmentedCell[] = {&Ctx.Idents.get("setToolTip"),
  399. &Ctx.Idents.get("forSegment")};
  400. ADD_METHOD(NSSegmentedCell, setToolTipNSSegmentedCell, 2, 0)
  401. NEW_RECEIVER(NSUndoManager)
  402. ADD_UNARY_METHOD(NSUndoManager, setActionName, 0)
  403. ADD_UNARY_METHOD(NSUndoManager, undoMenuTitleForUndoActionName, 0)
  404. ADD_UNARY_METHOD(NSUndoManager, redoMenuTitleForUndoActionName, 0)
  405. NEW_RECEIVER(NSMenuItem)
  406. IdentifierInfo *initWithTitleNSMenuItem[] = {
  407. &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("action"),
  408. &Ctx.Idents.get("keyEquivalent")};
  409. ADD_METHOD(NSMenuItem, initWithTitleNSMenuItem, 3, 0)
  410. ADD_UNARY_METHOD(NSMenuItem, setTitle, 0)
  411. ADD_UNARY_METHOD(NSMenuItem, setToolTip, 0)
  412. NEW_RECEIVER(NSPopUpButtonCell)
  413. IdentifierInfo *initTextCellNSPopUpButtonCell[] = {
  414. &Ctx.Idents.get("initTextCell"), &Ctx.Idents.get("pullsDown")};
  415. ADD_METHOD(NSPopUpButtonCell, initTextCellNSPopUpButtonCell, 2, 0)
  416. ADD_UNARY_METHOD(NSPopUpButtonCell, addItemWithTitle, 0)
  417. IdentifierInfo *insertItemWithTitleNSPopUpButtonCell[] = {
  418. &Ctx.Idents.get("insertItemWithTitle"), &Ctx.Idents.get("atIndex")};
  419. ADD_METHOD(NSPopUpButtonCell, insertItemWithTitleNSPopUpButtonCell, 2, 0)
  420. ADD_UNARY_METHOD(NSPopUpButtonCell, removeItemWithTitle, 0)
  421. ADD_UNARY_METHOD(NSPopUpButtonCell, selectItemWithTitle, 0)
  422. ADD_UNARY_METHOD(NSPopUpButtonCell, setTitle, 0)
  423. NEW_RECEIVER(NSViewController)
  424. ADD_UNARY_METHOD(NSViewController, setTitle, 0)
  425. NEW_RECEIVER(NSMenu)
  426. ADD_UNARY_METHOD(NSMenu, initWithTitle, 0)
  427. IdentifierInfo *insertItemWithTitleNSMenu[] = {
  428. &Ctx.Idents.get("insertItemWithTitle"), &Ctx.Idents.get("action"),
  429. &Ctx.Idents.get("keyEquivalent"), &Ctx.Idents.get("atIndex")};
  430. ADD_METHOD(NSMenu, insertItemWithTitleNSMenu, 4, 0)
  431. IdentifierInfo *addItemWithTitleNSMenu[] = {
  432. &Ctx.Idents.get("addItemWithTitle"), &Ctx.Idents.get("action"),
  433. &Ctx.Idents.get("keyEquivalent")};
  434. ADD_METHOD(NSMenu, addItemWithTitleNSMenu, 3, 0)
  435. ADD_UNARY_METHOD(NSMenu, setTitle, 0)
  436. NEW_RECEIVER(UIMutableUserNotificationAction)
  437. ADD_UNARY_METHOD(UIMutableUserNotificationAction, setTitle, 0)
  438. NEW_RECEIVER(NSForm)
  439. ADD_UNARY_METHOD(NSForm, addEntry, 0)
  440. IdentifierInfo *insertEntryNSForm[] = {&Ctx.Idents.get("insertEntry"),
  441. &Ctx.Idents.get("atIndex")};
  442. ADD_METHOD(NSForm, insertEntryNSForm, 2, 0)
  443. NEW_RECEIVER(NSTextFieldCell)
  444. ADD_UNARY_METHOD(NSTextFieldCell, setPlaceholderString, 0)
  445. NEW_RECEIVER(NSUserNotificationAction)
  446. IdentifierInfo *actionWithIdentifierNSUserNotificationAction[] = {
  447. &Ctx.Idents.get("actionWithIdentifier"), &Ctx.Idents.get("title")};
  448. ADD_METHOD(NSUserNotificationAction,
  449. actionWithIdentifierNSUserNotificationAction, 2, 1)
  450. NEW_RECEIVER(UITextField)
  451. ADD_UNARY_METHOD(UITextField, setText, 0)
  452. ADD_UNARY_METHOD(UITextField, setPlaceholder, 0)
  453. NEW_RECEIVER(UIBarButtonItem)
  454. IdentifierInfo *initWithTitleUIBarButtonItem[] = {
  455. &Ctx.Idents.get("initWithTitle"), &Ctx.Idents.get("style"),
  456. &Ctx.Idents.get("target"), &Ctx.Idents.get("action")};
  457. ADD_METHOD(UIBarButtonItem, initWithTitleUIBarButtonItem, 4, 0)
  458. NEW_RECEIVER(UIViewController)
  459. ADD_UNARY_METHOD(UIViewController, setTitle, 0)
  460. NEW_RECEIVER(UISegmentedControl)
  461. IdentifierInfo *insertSegmentWithTitleUISegmentedControl[] = {
  462. &Ctx.Idents.get("insertSegmentWithTitle"), &Ctx.Idents.get("atIndex"),
  463. &Ctx.Idents.get("animated")};
  464. ADD_METHOD(UISegmentedControl, insertSegmentWithTitleUISegmentedControl, 3, 0)
  465. IdentifierInfo *setTitleUISegmentedControl[] = {
  466. &Ctx.Idents.get("setTitle"), &Ctx.Idents.get("forSegmentAtIndex")};
  467. ADD_METHOD(UISegmentedControl, setTitleUISegmentedControl, 2, 0)
  468. NEW_RECEIVER(NSAccessibilityCustomRotorItemResult)
  469. IdentifierInfo
  470. *initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult[] = {
  471. &Ctx.Idents.get("initWithItemLoadingToken"),
  472. &Ctx.Idents.get("customLabel")};
  473. ADD_METHOD(NSAccessibilityCustomRotorItemResult,
  474. initWithItemLoadingTokenNSAccessibilityCustomRotorItemResult, 2, 1)
  475. ADD_UNARY_METHOD(NSAccessibilityCustomRotorItemResult, setCustomLabel, 0)
  476. NEW_RECEIVER(UIContextualAction)
  477. IdentifierInfo *contextualActionWithStyleUIContextualAction[] = {
  478. &Ctx.Idents.get("contextualActionWithStyle"), &Ctx.Idents.get("title"),
  479. &Ctx.Idents.get("handler")};
  480. ADD_METHOD(UIContextualAction, contextualActionWithStyleUIContextualAction, 3,
  481. 1)
  482. ADD_UNARY_METHOD(UIContextualAction, setTitle, 0)
  483. NEW_RECEIVER(NSAccessibilityCustomRotor)
  484. IdentifierInfo *initWithLabelNSAccessibilityCustomRotor[] = {
  485. &Ctx.Idents.get("initWithLabel"), &Ctx.Idents.get("itemSearchDelegate")};
  486. ADD_METHOD(NSAccessibilityCustomRotor,
  487. initWithLabelNSAccessibilityCustomRotor, 2, 0)
  488. ADD_UNARY_METHOD(NSAccessibilityCustomRotor, setLabel, 0)
  489. NEW_RECEIVER(NSWindowTab)
  490. ADD_UNARY_METHOD(NSWindowTab, setTitle, 0)
  491. ADD_UNARY_METHOD(NSWindowTab, setToolTip, 0)
  492. NEW_RECEIVER(NSAccessibilityCustomAction)
  493. IdentifierInfo *initWithNameNSAccessibilityCustomAction[] = {
  494. &Ctx.Idents.get("initWithName"), &Ctx.Idents.get("handler")};
  495. ADD_METHOD(NSAccessibilityCustomAction,
  496. initWithNameNSAccessibilityCustomAction, 2, 0)
  497. IdentifierInfo *initWithNameTargetNSAccessibilityCustomAction[] = {
  498. &Ctx.Idents.get("initWithName"), &Ctx.Idents.get("target"),
  499. &Ctx.Idents.get("selector")};
  500. ADD_METHOD(NSAccessibilityCustomAction,
  501. initWithNameTargetNSAccessibilityCustomAction, 3, 0)
  502. ADD_UNARY_METHOD(NSAccessibilityCustomAction, setName, 0)
  503. }
  504. #define LSF_INSERT(function_name) LSF.insert(&Ctx.Idents.get(function_name));
  505. #define LSM_INSERT_NULLARY(receiver, method_name) \
  506. LSM.insert({&Ctx.Idents.get(receiver), Ctx.Selectors.getNullarySelector( \
  507. &Ctx.Idents.get(method_name))});
  508. #define LSM_INSERT_UNARY(receiver, method_name) \
  509. LSM.insert({&Ctx.Idents.get(receiver), \
  510. Ctx.Selectors.getUnarySelector(&Ctx.Idents.get(method_name))});
  511. #define LSM_INSERT_SELECTOR(receiver, method_list, arguments) \
  512. LSM.insert({&Ctx.Idents.get(receiver), \
  513. Ctx.Selectors.getSelector(arguments, method_list)});
  514. /// Initializes a list of methods and C functions that return a localized string
  515. void NonLocalizedStringChecker::initLocStringsMethods(ASTContext &Ctx) const {
  516. if (!LSM.empty())
  517. return;
  518. IdentifierInfo *LocalizedStringMacro[] = {
  519. &Ctx.Idents.get("localizedStringForKey"), &Ctx.Idents.get("value"),
  520. &Ctx.Idents.get("table")};
  521. LSM_INSERT_SELECTOR("NSBundle", LocalizedStringMacro, 3)
  522. LSM_INSERT_UNARY("NSDateFormatter", "stringFromDate")
  523. IdentifierInfo *LocalizedStringFromDate[] = {
  524. &Ctx.Idents.get("localizedStringFromDate"), &Ctx.Idents.get("dateStyle"),
  525. &Ctx.Idents.get("timeStyle")};
  526. LSM_INSERT_SELECTOR("NSDateFormatter", LocalizedStringFromDate, 3)
  527. LSM_INSERT_UNARY("NSNumberFormatter", "stringFromNumber")
  528. LSM_INSERT_NULLARY("UITextField", "text")
  529. LSM_INSERT_NULLARY("UITextView", "text")
  530. LSM_INSERT_NULLARY("UILabel", "text")
  531. LSF_INSERT("CFDateFormatterCreateStringWithDate");
  532. LSF_INSERT("CFDateFormatterCreateStringWithAbsoluteTime");
  533. LSF_INSERT("CFNumberFormatterCreateStringWithNumber");
  534. }
  535. /// Checks to see if the method / function declaration includes
  536. /// __attribute__((annotate("returns_localized_nsstring")))
  537. bool NonLocalizedStringChecker::isAnnotatedAsReturningLocalized(
  538. const Decl *D) const {
  539. if (!D)
  540. return false;
  541. return std::any_of(
  542. D->specific_attr_begin<AnnotateAttr>(),
  543. D->specific_attr_end<AnnotateAttr>(), [](const AnnotateAttr *Ann) {
  544. return Ann->getAnnotation() == "returns_localized_nsstring";
  545. });
  546. }
  547. /// Checks to see if the method / function declaration includes
  548. /// __attribute__((annotate("takes_localized_nsstring")))
  549. bool NonLocalizedStringChecker::isAnnotatedAsTakingLocalized(
  550. const Decl *D) const {
  551. if (!D)
  552. return false;
  553. return std::any_of(
  554. D->specific_attr_begin<AnnotateAttr>(),
  555. D->specific_attr_end<AnnotateAttr>(), [](const AnnotateAttr *Ann) {
  556. return Ann->getAnnotation() == "takes_localized_nsstring";
  557. });
  558. }
  559. /// Returns true if the given SVal is marked as Localized in the program state
  560. bool NonLocalizedStringChecker::hasLocalizedState(SVal S,
  561. CheckerContext &C) const {
  562. const MemRegion *mt = S.getAsRegion();
  563. if (mt) {
  564. const LocalizedState *LS = C.getState()->get<LocalizedMemMap>(mt);
  565. if (LS && LS->isLocalized())
  566. return true;
  567. }
  568. return false;
  569. }
  570. /// Returns true if the given SVal is marked as NonLocalized in the program
  571. /// state
  572. bool NonLocalizedStringChecker::hasNonLocalizedState(SVal S,
  573. CheckerContext &C) const {
  574. const MemRegion *mt = S.getAsRegion();
  575. if (mt) {
  576. const LocalizedState *LS = C.getState()->get<LocalizedMemMap>(mt);
  577. if (LS && LS->isNonLocalized())
  578. return true;
  579. }
  580. return false;
  581. }
  582. /// Marks the given SVal as Localized in the program state
  583. void NonLocalizedStringChecker::setLocalizedState(const SVal S,
  584. CheckerContext &C) const {
  585. const MemRegion *mt = S.getAsRegion();
  586. if (mt) {
  587. ProgramStateRef State =
  588. C.getState()->set<LocalizedMemMap>(mt, LocalizedState::getLocalized());
  589. C.addTransition(State);
  590. }
  591. }
  592. /// Marks the given SVal as NonLocalized in the program state
  593. void NonLocalizedStringChecker::setNonLocalizedState(const SVal S,
  594. CheckerContext &C) const {
  595. const MemRegion *mt = S.getAsRegion();
  596. if (mt) {
  597. ProgramStateRef State = C.getState()->set<LocalizedMemMap>(
  598. mt, LocalizedState::getNonLocalized());
  599. C.addTransition(State);
  600. }
  601. }
  602. static bool isDebuggingName(std::string name) {
  603. return StringRef(name).lower().find("debug") != StringRef::npos;
  604. }
  605. /// Returns true when, heuristically, the analyzer may be analyzing debugging
  606. /// code. We use this to suppress localization diagnostics in un-localized user
  607. /// interfaces that are only used for debugging and are therefore not user
  608. /// facing.
  609. static bool isDebuggingContext(CheckerContext &C) {
  610. const Decl *D = C.getCurrentAnalysisDeclContext()->getDecl();
  611. if (!D)
  612. return false;
  613. if (auto *ND = dyn_cast<NamedDecl>(D)) {
  614. if (isDebuggingName(ND->getNameAsString()))
  615. return true;
  616. }
  617. const DeclContext *DC = D->getDeclContext();
  618. if (auto *CD = dyn_cast<ObjCContainerDecl>(DC)) {
  619. if (isDebuggingName(CD->getNameAsString()))
  620. return true;
  621. }
  622. return false;
  623. }
  624. /// Reports a localization error for the passed in method call and SVal
  625. void NonLocalizedStringChecker::reportLocalizationError(
  626. SVal S, const CallEvent &M, CheckerContext &C, int argumentNumber) const {
  627. // Don't warn about localization errors in classes and methods that
  628. // may be debug code.
  629. if (isDebuggingContext(C))
  630. return;
  631. ExplodedNode *ErrNode = C.getPredecessor();
  632. static CheckerProgramPointTag Tag("NonLocalizedStringChecker",
  633. "UnlocalizedString");
  634. ErrNode = C.addTransition(C.getState(), C.getPredecessor(), &Tag);
  635. if (!ErrNode)
  636. return;
  637. // Generate the bug report.
  638. std::unique_ptr<BugReport> R(new BugReport(
  639. *BT, "User-facing text should use localized string macro", ErrNode));
  640. if (argumentNumber) {
  641. R->addRange(M.getArgExpr(argumentNumber - 1)->getSourceRange());
  642. } else {
  643. R->addRange(M.getSourceRange());
  644. }
  645. R->markInteresting(S);
  646. const MemRegion *StringRegion = S.getAsRegion();
  647. if (StringRegion)
  648. R->addVisitor(llvm::make_unique<NonLocalizedStringBRVisitor>(StringRegion));
  649. C.emitReport(std::move(R));
  650. }
  651. /// Returns the argument number requiring localized string if it exists
  652. /// otherwise, returns -1
  653. int NonLocalizedStringChecker::getLocalizedArgumentForSelector(
  654. const IdentifierInfo *Receiver, Selector S) const {
  655. auto method = UIMethods.find(Receiver);
  656. if (method == UIMethods.end())
  657. return -1;
  658. auto argumentIterator = method->getSecond().find(S);
  659. if (argumentIterator == method->getSecond().end())
  660. return -1;
  661. int argumentNumber = argumentIterator->getSecond();
  662. return argumentNumber;
  663. }
  664. /// Check if the string being passed in has NonLocalized state
  665. void NonLocalizedStringChecker::checkPreObjCMessage(const ObjCMethodCall &msg,
  666. CheckerContext &C) const {
  667. initUIMethods(C.getASTContext());
  668. const ObjCInterfaceDecl *OD = msg.getReceiverInterface();
  669. if (!OD)
  670. return;
  671. const IdentifierInfo *odInfo = OD->getIdentifier();
  672. Selector S = msg.getSelector();
  673. std::string SelectorString = S.getAsString();
  674. StringRef SelectorName = SelectorString;
  675. assert(!SelectorName.empty());
  676. if (odInfo->isStr("NSString")) {
  677. // Handle the case where the receiver is an NSString
  678. // These special NSString methods draw to the screen
  679. if (!(SelectorName.startswith("drawAtPoint") ||
  680. SelectorName.startswith("drawInRect") ||
  681. SelectorName.startswith("drawWithRect")))
  682. return;
  683. SVal svTitle = msg.getReceiverSVal();
  684. bool isNonLocalized = hasNonLocalizedState(svTitle, C);
  685. if (isNonLocalized) {
  686. reportLocalizationError(svTitle, msg, C);
  687. }
  688. }
  689. int argumentNumber = getLocalizedArgumentForSelector(odInfo, S);
  690. // Go up each hierarchy of superclasses and their protocols
  691. while (argumentNumber < 0 && OD->getSuperClass() != nullptr) {
  692. for (const auto *P : OD->all_referenced_protocols()) {
  693. argumentNumber = getLocalizedArgumentForSelector(P->getIdentifier(), S);
  694. if (argumentNumber >= 0)
  695. break;
  696. }
  697. if (argumentNumber < 0) {
  698. OD = OD->getSuperClass();
  699. argumentNumber = getLocalizedArgumentForSelector(OD->getIdentifier(), S);
  700. }
  701. }
  702. if (argumentNumber < 0) { // There was no match in UIMethods
  703. if (const Decl *D = msg.getDecl()) {
  704. if (const ObjCMethodDecl *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
  705. auto formals = OMD->parameters();
  706. for (unsigned i = 0, ei = formals.size(); i != ei; ++i) {
  707. if (isAnnotatedAsTakingLocalized(formals[i])) {
  708. argumentNumber = i;
  709. break;
  710. }
  711. }
  712. }
  713. }
  714. }
  715. if (argumentNumber < 0) // Still no match
  716. return;
  717. SVal svTitle = msg.getArgSVal(argumentNumber);
  718. if (const ObjCStringRegion *SR =
  719. dyn_cast_or_null<ObjCStringRegion>(svTitle.getAsRegion())) {
  720. StringRef stringValue =
  721. SR->getObjCStringLiteral()->getString()->getString();
  722. if ((stringValue.trim().size() == 0 && stringValue.size() > 0) ||
  723. stringValue.empty())
  724. return;
  725. if (!IsAggressive && llvm::sys::unicode::columnWidthUTF8(stringValue) < 2)
  726. return;
  727. }
  728. bool isNonLocalized = hasNonLocalizedState(svTitle, C);
  729. if (isNonLocalized) {
  730. reportLocalizationError(svTitle, msg, C, argumentNumber + 1);
  731. }
  732. }
  733. void NonLocalizedStringChecker::checkPreCall(const CallEvent &Call,
  734. CheckerContext &C) const {
  735. const Decl *D = Call.getDecl();
  736. if (D && isa<FunctionDecl>(D)) {
  737. const FunctionDecl *FD = dyn_cast<FunctionDecl>(D);
  738. auto formals = FD->parameters();
  739. for (unsigned i = 0,
  740. ei = std::min(unsigned(formals.size()), Call.getNumArgs());
  741. i != ei; ++i) {
  742. if (isAnnotatedAsTakingLocalized(formals[i])) {
  743. auto actual = Call.getArgSVal(i);
  744. if (hasNonLocalizedState(actual, C)) {
  745. reportLocalizationError(actual, Call, C, i + 1);
  746. }
  747. }
  748. }
  749. }
  750. }
  751. static inline bool isNSStringType(QualType T, ASTContext &Ctx) {
  752. const ObjCObjectPointerType *PT = T->getAs<ObjCObjectPointerType>();
  753. if (!PT)
  754. return false;
  755. ObjCInterfaceDecl *Cls = PT->getObjectType()->getInterface();
  756. if (!Cls)
  757. return false;
  758. IdentifierInfo *ClsName = Cls->getIdentifier();
  759. // FIXME: Should we walk the chain of classes?
  760. return ClsName == &Ctx.Idents.get("NSString") ||
  761. ClsName == &Ctx.Idents.get("NSMutableString");
  762. }
  763. /// Marks a string being returned by any call as localized
  764. /// if it is in LocStringFunctions (LSF) or the function is annotated.
  765. /// Otherwise, we mark it as NonLocalized (Aggressive) or
  766. /// NonLocalized only if it is not backed by a SymRegion (Non-Aggressive),
  767. /// basically leaving only string literals as NonLocalized.
  768. void NonLocalizedStringChecker::checkPostCall(const CallEvent &Call,
  769. CheckerContext &C) const {
  770. initLocStringsMethods(C.getASTContext());
  771. if (!Call.getOriginExpr())
  772. return;
  773. // Anything that takes in a localized NSString as an argument
  774. // and returns an NSString will be assumed to be returning a
  775. // localized NSString. (Counter: Incorrectly combining two LocalizedStrings)
  776. const QualType RT = Call.getResultType();
  777. if (isNSStringType(RT, C.getASTContext())) {
  778. for (unsigned i = 0; i < Call.getNumArgs(); ++i) {
  779. SVal argValue = Call.getArgSVal(i);
  780. if (hasLocalizedState(argValue, C)) {
  781. SVal sv = Call.getReturnValue();
  782. setLocalizedState(sv, C);
  783. return;
  784. }
  785. }
  786. }
  787. const Decl *D = Call.getDecl();
  788. if (!D)
  789. return;
  790. const IdentifierInfo *Identifier = Call.getCalleeIdentifier();
  791. SVal sv = Call.getReturnValue();
  792. if (isAnnotatedAsReturningLocalized(D) || LSF.count(Identifier) != 0) {
  793. setLocalizedState(sv, C);
  794. } else if (isNSStringType(RT, C.getASTContext()) &&
  795. !hasLocalizedState(sv, C)) {
  796. if (IsAggressive) {
  797. setNonLocalizedState(sv, C);
  798. } else {
  799. const SymbolicRegion *SymReg =
  800. dyn_cast_or_null<SymbolicRegion>(sv.getAsRegion());
  801. if (!SymReg)
  802. setNonLocalizedState(sv, C);
  803. }
  804. }
  805. }
  806. /// Marks a string being returned by an ObjC method as localized
  807. /// if it is in LocStringMethods or the method is annotated
  808. void NonLocalizedStringChecker::checkPostObjCMessage(const ObjCMethodCall &msg,
  809. CheckerContext &C) const {
  810. initLocStringsMethods(C.getASTContext());
  811. if (!msg.isInstanceMessage())
  812. return;
  813. const ObjCInterfaceDecl *OD = msg.getReceiverInterface();
  814. if (!OD)
  815. return;
  816. const IdentifierInfo *odInfo = OD->getIdentifier();
  817. Selector S = msg.getSelector();
  818. std::string SelectorName = S.getAsString();
  819. std::pair<const IdentifierInfo *, Selector> MethodDescription = {odInfo, S};
  820. if (LSM.count(MethodDescription) ||
  821. isAnnotatedAsReturningLocalized(msg.getDecl())) {
  822. SVal sv = msg.getReturnValue();
  823. setLocalizedState(sv, C);
  824. }
  825. }
  826. /// Marks all empty string literals as localized
  827. void NonLocalizedStringChecker::checkPostStmt(const ObjCStringLiteral *SL,
  828. CheckerContext &C) const {
  829. SVal sv = C.getSVal(SL);
  830. setNonLocalizedState(sv, C);
  831. }
  832. std::shared_ptr<PathDiagnosticPiece>
  833. NonLocalizedStringBRVisitor::VisitNode(const ExplodedNode *Succ,
  834. BugReporterContext &BRC, BugReport &BR) {
  835. if (Satisfied)
  836. return nullptr;
  837. Optional<StmtPoint> Point = Succ->getLocation().getAs<StmtPoint>();
  838. if (!Point.hasValue())
  839. return nullptr;
  840. auto *LiteralExpr = dyn_cast<ObjCStringLiteral>(Point->getStmt());
  841. if (!LiteralExpr)
  842. return nullptr;
  843. SVal LiteralSVal = Succ->getSVal(LiteralExpr);
  844. if (LiteralSVal.getAsRegion() != NonLocalizedString)
  845. return nullptr;
  846. Satisfied = true;
  847. PathDiagnosticLocation L =
  848. PathDiagnosticLocation::create(*Point, BRC.getSourceManager());
  849. if (!L.isValid() || !L.asLocation().isValid())
  850. return nullptr;
  851. auto Piece = std::make_shared<PathDiagnosticEventPiece>(
  852. L, "Non-localized string literal here");
  853. Piece->addRange(LiteralExpr->getSourceRange());
  854. return std::move(Piece);
  855. }
  856. namespace {
  857. class EmptyLocalizationContextChecker
  858. : public Checker<check::ASTDecl<ObjCImplementationDecl>> {
  859. // A helper class, which walks the AST
  860. class MethodCrawler : public ConstStmtVisitor<MethodCrawler> {
  861. const ObjCMethodDecl *MD;
  862. BugReporter &BR;
  863. AnalysisManager &Mgr;
  864. const CheckerBase *Checker;
  865. LocationOrAnalysisDeclContext DCtx;
  866. public:
  867. MethodCrawler(const ObjCMethodDecl *InMD, BugReporter &InBR,
  868. const CheckerBase *Checker, AnalysisManager &InMgr,
  869. AnalysisDeclContext *InDCtx)
  870. : MD(InMD), BR(InBR), Mgr(InMgr), Checker(Checker), DCtx(InDCtx) {}
  871. void VisitStmt(const Stmt *S) { VisitChildren(S); }
  872. void VisitObjCMessageExpr(const ObjCMessageExpr *ME);
  873. void reportEmptyContextError(const ObjCMessageExpr *M) const;
  874. void VisitChildren(const Stmt *S) {
  875. for (const Stmt *Child : S->children()) {
  876. if (Child)
  877. this->Visit(Child);
  878. }
  879. }
  880. };
  881. public:
  882. void checkASTDecl(const ObjCImplementationDecl *D, AnalysisManager &Mgr,
  883. BugReporter &BR) const;
  884. };
  885. } // end anonymous namespace
  886. void EmptyLocalizationContextChecker::checkASTDecl(
  887. const ObjCImplementationDecl *D, AnalysisManager &Mgr,
  888. BugReporter &BR) const {
  889. for (const ObjCMethodDecl *M : D->methods()) {
  890. AnalysisDeclContext *DCtx = Mgr.getAnalysisDeclContext(M);
  891. const Stmt *Body = M->getBody();
  892. assert(Body);
  893. MethodCrawler MC(M->getCanonicalDecl(), BR, this, Mgr, DCtx);
  894. MC.VisitStmt(Body);
  895. }
  896. }
  897. /// This check attempts to match these macros, assuming they are defined as
  898. /// follows:
  899. ///
  900. /// #define NSLocalizedString(key, comment) \
  901. /// [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]
  902. /// #define NSLocalizedStringFromTable(key, tbl, comment) \
  903. /// [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]
  904. /// #define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
  905. /// [bundle localizedStringForKey:(key) value:@"" table:(tbl)]
  906. /// #define NSLocalizedStringWithDefaultValue(key, tbl, bundle, val, comment)
  907. ///
  908. /// We cannot use the path sensitive check because the macro argument we are
  909. /// checking for (comment) is not used and thus not present in the AST,
  910. /// so we use Lexer on the original macro call and retrieve the value of
  911. /// the comment. If it's empty or nil, we raise a warning.
  912. void EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr(
  913. const ObjCMessageExpr *ME) {
  914. // FIXME: We may be able to use PPCallbacks to check for empty context
  915. // comments as part of preprocessing and avoid this re-lexing hack.
  916. const ObjCInterfaceDecl *OD = ME->getReceiverInterface();
  917. if (!OD)
  918. return;
  919. const IdentifierInfo *odInfo = OD->getIdentifier();
  920. if (!(odInfo->isStr("NSBundle") &&
  921. ME->getSelector().getAsString() ==
  922. "localizedStringForKey:value:table:")) {
  923. return;
  924. }
  925. SourceRange R = ME->getSourceRange();
  926. if (!R.getBegin().isMacroID())
  927. return;
  928. // getImmediateMacroCallerLoc gets the location of the immediate macro
  929. // caller, one level up the stack toward the initial macro typed into the
  930. // source, so SL should point to the NSLocalizedString macro.
  931. SourceLocation SL =
  932. Mgr.getSourceManager().getImmediateMacroCallerLoc(R.getBegin());
  933. std::pair<FileID, unsigned> SLInfo =
  934. Mgr.getSourceManager().getDecomposedLoc(SL);
  935. SrcMgr::SLocEntry SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);
  936. // If NSLocalizedString macro is wrapped in another macro, we need to
  937. // unwrap the expansion until we get to the NSLocalizedStringMacro.
  938. while (SE.isExpansion()) {
  939. SL = SE.getExpansion().getSpellingLoc();
  940. SLInfo = Mgr.getSourceManager().getDecomposedLoc(SL);
  941. SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);
  942. }
  943. bool Invalid = false;
  944. llvm::MemoryBuffer *BF =
  945. Mgr.getSourceManager().getBuffer(SLInfo.first, SL, &Invalid);
  946. if (Invalid)
  947. return;
  948. Lexer TheLexer(SL, LangOptions(), BF->getBufferStart(),
  949. BF->getBufferStart() + SLInfo.second, BF->getBufferEnd());
  950. Token I;
  951. Token Result; // This will hold the token just before the last ')'
  952. int p_count = 0; // This is for parenthesis matching
  953. while (!TheLexer.LexFromRawLexer(I)) {
  954. if (I.getKind() == tok::l_paren)
  955. ++p_count;
  956. if (I.getKind() == tok::r_paren) {
  957. if (p_count == 1)
  958. break;
  959. --p_count;
  960. }
  961. Result = I;
  962. }
  963. if (isAnyIdentifier(Result.getKind())) {
  964. if (Result.getRawIdentifier().equals("nil")) {
  965. reportEmptyContextError(ME);
  966. return;
  967. }
  968. }
  969. if (!isStringLiteral(Result.getKind()))
  970. return;
  971. StringRef Comment =
  972. StringRef(Result.getLiteralData(), Result.getLength()).trim('"');
  973. if ((Comment.trim().size() == 0 && Comment.size() > 0) || // Is Whitespace
  974. Comment.empty()) {
  975. reportEmptyContextError(ME);
  976. }
  977. }
  978. void EmptyLocalizationContextChecker::MethodCrawler::reportEmptyContextError(
  979. const ObjCMessageExpr *ME) const {
  980. // Generate the bug report.
  981. BR.EmitBasicReport(MD, Checker, "Context Missing",
  982. "Localizability Issue (Apple)",
  983. "Localized string macro should include a non-empty "
  984. "comment for translators",
  985. PathDiagnosticLocation(ME, BR.getSourceManager(), DCtx));
  986. }
  987. namespace {
  988. class PluralMisuseChecker : public Checker<check::ASTCodeBody> {
  989. // A helper class, which walks the AST
  990. class MethodCrawler : public RecursiveASTVisitor<MethodCrawler> {
  991. BugReporter &BR;
  992. const CheckerBase *Checker;
  993. AnalysisDeclContext *AC;
  994. // This functions like a stack. We push on any IfStmt or
  995. // ConditionalOperator that matches the condition
  996. // and pop it off when we leave that statement
  997. llvm::SmallVector<const clang::Stmt *, 8> MatchingStatements;
  998. // This is true when we are the direct-child of a
  999. // matching statement
  1000. bool InMatchingStatement = false;
  1001. public:
  1002. explicit MethodCrawler(BugReporter &InBR, const CheckerBase *Checker,
  1003. AnalysisDeclContext *InAC)
  1004. : BR(InBR), Checker(Checker), AC(InAC) {}
  1005. bool VisitIfStmt(const IfStmt *I);
  1006. bool EndVisitIfStmt(IfStmt *I);
  1007. bool TraverseIfStmt(IfStmt *x);
  1008. bool VisitConditionalOperator(const ConditionalOperator *C);
  1009. bool TraverseConditionalOperator(ConditionalOperator *C);
  1010. bool VisitCallExpr(const CallExpr *CE);
  1011. bool VisitObjCMessageExpr(const ObjCMessageExpr *ME);
  1012. private:
  1013. void reportPluralMisuseError(const Stmt *S) const;
  1014. bool isCheckingPlurality(const Expr *E) const;
  1015. };
  1016. public:
  1017. void checkASTCodeBody(const Decl *D, AnalysisManager &Mgr,
  1018. BugReporter &BR) const {
  1019. MethodCrawler Visitor(BR, this, Mgr.getAnalysisDeclContext(D));
  1020. Visitor.TraverseDecl(const_cast<Decl *>(D));
  1021. }
  1022. };
  1023. } // end anonymous namespace
  1024. // Checks the condition of the IfStmt and returns true if one
  1025. // of the following heuristics are met:
  1026. // 1) The conidtion is a variable with "singular" or "plural" in the name
  1027. // 2) The condition is a binary operator with 1 or 2 on the right-hand side
  1028. bool PluralMisuseChecker::MethodCrawler::isCheckingPlurality(
  1029. const Expr *Condition) const {
  1030. const BinaryOperator *BO = nullptr;
  1031. // Accounts for when a VarDecl represents a BinaryOperator
  1032. if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Condition)) {
  1033. if (const VarDecl *VD = dyn_cast<VarDecl>(DRE->getDecl())) {
  1034. const Expr *InitExpr = VD->getInit();
  1035. if (InitExpr) {
  1036. if (const BinaryOperator *B =
  1037. dyn_cast<BinaryOperator>(InitExpr->IgnoreParenImpCasts())) {
  1038. BO = B;
  1039. }
  1040. }
  1041. if (VD->getName().lower().find("plural") != StringRef::npos ||
  1042. VD->getName().lower().find("singular") != StringRef::npos) {
  1043. return true;
  1044. }
  1045. }
  1046. } else if (const BinaryOperator *B = dyn_cast<BinaryOperator>(Condition)) {
  1047. BO = B;
  1048. }
  1049. if (BO == nullptr)
  1050. return false;
  1051. if (IntegerLiteral *IL = dyn_cast_or_null<IntegerLiteral>(
  1052. BO->getRHS()->IgnoreParenImpCasts())) {
  1053. llvm::APInt Value = IL->getValue();
  1054. if (Value == 1 || Value == 2) {
  1055. return true;
  1056. }
  1057. }
  1058. return false;
  1059. }
  1060. // A CallExpr with "LOC" in its identifier that takes in a string literal
  1061. // has been shown to almost always be a function that returns a localized
  1062. // string. Raise a diagnostic when this is in a statement that matches
  1063. // the condition.
  1064. bool PluralMisuseChecker::MethodCrawler::VisitCallExpr(const CallExpr *CE) {
  1065. if (InMatchingStatement) {
  1066. if (const FunctionDecl *FD = CE->getDirectCallee()) {
  1067. std::string NormalizedName =
  1068. StringRef(FD->getNameInfo().getAsString()).lower();
  1069. if (NormalizedName.find("loc") != std::string::npos) {
  1070. for (const Expr *Arg : CE->arguments()) {
  1071. if (isa<ObjCStringLiteral>(Arg))
  1072. reportPluralMisuseError(CE);
  1073. }
  1074. }
  1075. }
  1076. }
  1077. return true;
  1078. }
  1079. // The other case is for NSLocalizedString which also returns
  1080. // a localized string. It's a macro for the ObjCMessageExpr
  1081. // [NSBundle localizedStringForKey:value:table:] Raise a
  1082. // diagnostic when this is in a statement that matches
  1083. // the condition.
  1084. bool PluralMisuseChecker::MethodCrawler::VisitObjCMessageExpr(
  1085. const ObjCMessageExpr *ME) {
  1086. const ObjCInterfaceDecl *OD = ME->getReceiverInterface();
  1087. if (!OD)
  1088. return true;
  1089. const IdentifierInfo *odInfo = OD->getIdentifier();
  1090. if (odInfo->isStr("NSBundle") &&
  1091. ME->getSelector().getAsString() == "localizedStringForKey:value:table:") {
  1092. if (InMatchingStatement) {
  1093. reportPluralMisuseError(ME);
  1094. }
  1095. }
  1096. return true;
  1097. }
  1098. /// Override TraverseIfStmt so we know when we are done traversing an IfStmt
  1099. bool PluralMisuseChecker::MethodCrawler::TraverseIfStmt(IfStmt *I) {
  1100. RecursiveASTVisitor<MethodCrawler>::TraverseIfStmt(I);
  1101. return EndVisitIfStmt(I);
  1102. }
  1103. // EndVisit callbacks are not provided by the RecursiveASTVisitor
  1104. // so we override TraverseIfStmt and make a call to EndVisitIfStmt
  1105. // after traversing the IfStmt
  1106. bool PluralMisuseChecker::MethodCrawler::EndVisitIfStmt(IfStmt *I) {
  1107. MatchingStatements.pop_back();
  1108. if (!MatchingStatements.empty()) {
  1109. if (MatchingStatements.back() != nullptr) {
  1110. InMatchingStatement = true;
  1111. return true;
  1112. }
  1113. }
  1114. InMatchingStatement = false;
  1115. return true;
  1116. }
  1117. bool PluralMisuseChecker::MethodCrawler::VisitIfStmt(const IfStmt *I) {
  1118. const Expr *Condition = I->getCond()->IgnoreParenImpCasts();
  1119. if (isCheckingPlurality(Condition)) {
  1120. MatchingStatements.push_back(I);
  1121. InMatchingStatement = true;
  1122. } else {
  1123. MatchingStatements.push_back(nullptr);
  1124. InMatchingStatement = false;
  1125. }
  1126. return true;
  1127. }
  1128. // Preliminary support for conditional operators.
  1129. bool PluralMisuseChecker::MethodCrawler::TraverseConditionalOperator(
  1130. ConditionalOperator *C) {
  1131. RecursiveASTVisitor<MethodCrawler>::TraverseConditionalOperator(C);
  1132. MatchingStatements.pop_back();
  1133. if (!MatchingStatements.empty()) {
  1134. if (MatchingStatements.back() != nullptr)
  1135. InMatchingStatement = true;
  1136. else
  1137. InMatchingStatement = false;
  1138. } else {
  1139. InMatchingStatement = false;
  1140. }
  1141. return true;
  1142. }
  1143. bool PluralMisuseChecker::MethodCrawler::VisitConditionalOperator(
  1144. const ConditionalOperator *C) {
  1145. const Expr *Condition = C->getCond()->IgnoreParenImpCasts();
  1146. if (isCheckingPlurality(Condition)) {
  1147. MatchingStatements.push_back(C);
  1148. InMatchingStatement = true;
  1149. } else {
  1150. MatchingStatements.push_back(nullptr);
  1151. InMatchingStatement = false;
  1152. }
  1153. return true;
  1154. }
  1155. void PluralMisuseChecker::MethodCrawler::reportPluralMisuseError(
  1156. const Stmt *S) const {
  1157. // Generate the bug report.
  1158. BR.EmitBasicReport(AC->getDecl(), Checker, "Plural Misuse",
  1159. "Localizability Issue (Apple)",
  1160. "Plural cases are not supported across all languages. "
  1161. "Use a .stringsdict file instead",
  1162. PathDiagnosticLocation(S, BR.getSourceManager(), AC));
  1163. }
  1164. //===----------------------------------------------------------------------===//
  1165. // Checker registration.
  1166. //===----------------------------------------------------------------------===//
  1167. void ento::registerNonLocalizedStringChecker(CheckerManager &mgr) {
  1168. NonLocalizedStringChecker *checker =
  1169. mgr.registerChecker<NonLocalizedStringChecker>();
  1170. checker->IsAggressive =
  1171. mgr.getAnalyzerOptions().getCheckerBooleanOption(
  1172. checker, "AggressiveReport", false);
  1173. }
  1174. bool ento::shouldRegisterNonLocalizedStringChecker(const LangOptions &LO) {
  1175. return true;
  1176. }
  1177. void ento::registerEmptyLocalizationContextChecker(CheckerManager &mgr) {
  1178. mgr.registerChecker<EmptyLocalizationContextChecker>();
  1179. }
  1180. bool ento::shouldRegisterEmptyLocalizationContextChecker(
  1181. const LangOptions &LO) {
  1182. return true;
  1183. }
  1184. void ento::registerPluralMisuseChecker(CheckerManager &mgr) {
  1185. mgr.registerChecker<PluralMisuseChecker>();
  1186. }
  1187. bool ento::shouldRegisterPluralMisuseChecker(const LangOptions &LO) {
  1188. return true;
  1189. }