LocalizationChecker.cpp 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427
  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. PathDiagnosticPieceRef VisitNode(const ExplodedNode *Succ,
  103. BugReporterContext &BRC,
  104. PathSensitiveBugReport &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. static CheckerProgramPointTag Tag("NonLocalizedStringChecker",
  632. "UnlocalizedString");
  633. ExplodedNode *ErrNode = C.addTransition(C.getState(), C.getPredecessor(), &Tag);
  634. if (!ErrNode)
  635. return;
  636. // Generate the bug report.
  637. auto R = std::make_unique<PathSensitiveBugReport>(
  638. *BT, "User-facing text should use localized string macro", ErrNode);
  639. if (argumentNumber) {
  640. R->addRange(M.getArgExpr(argumentNumber - 1)->getSourceRange());
  641. } else {
  642. R->addRange(M.getSourceRange());
  643. }
  644. R->markInteresting(S);
  645. const MemRegion *StringRegion = S.getAsRegion();
  646. if (StringRegion)
  647. R->addVisitor(std::make_unique<NonLocalizedStringBRVisitor>(StringRegion));
  648. C.emitReport(std::move(R));
  649. }
  650. /// Returns the argument number requiring localized string if it exists
  651. /// otherwise, returns -1
  652. int NonLocalizedStringChecker::getLocalizedArgumentForSelector(
  653. const IdentifierInfo *Receiver, Selector S) const {
  654. auto method = UIMethods.find(Receiver);
  655. if (method == UIMethods.end())
  656. return -1;
  657. auto argumentIterator = method->getSecond().find(S);
  658. if (argumentIterator == method->getSecond().end())
  659. return -1;
  660. int argumentNumber = argumentIterator->getSecond();
  661. return argumentNumber;
  662. }
  663. /// Check if the string being passed in has NonLocalized state
  664. void NonLocalizedStringChecker::checkPreObjCMessage(const ObjCMethodCall &msg,
  665. CheckerContext &C) const {
  666. initUIMethods(C.getASTContext());
  667. const ObjCInterfaceDecl *OD = msg.getReceiverInterface();
  668. if (!OD)
  669. return;
  670. const IdentifierInfo *odInfo = OD->getIdentifier();
  671. Selector S = msg.getSelector();
  672. std::string SelectorString = S.getAsString();
  673. StringRef SelectorName = SelectorString;
  674. assert(!SelectorName.empty());
  675. if (odInfo->isStr("NSString")) {
  676. // Handle the case where the receiver is an NSString
  677. // These special NSString methods draw to the screen
  678. if (!(SelectorName.startswith("drawAtPoint") ||
  679. SelectorName.startswith("drawInRect") ||
  680. SelectorName.startswith("drawWithRect")))
  681. return;
  682. SVal svTitle = msg.getReceiverSVal();
  683. bool isNonLocalized = hasNonLocalizedState(svTitle, C);
  684. if (isNonLocalized) {
  685. reportLocalizationError(svTitle, msg, C);
  686. }
  687. }
  688. int argumentNumber = getLocalizedArgumentForSelector(odInfo, S);
  689. // Go up each hierarchy of superclasses and their protocols
  690. while (argumentNumber < 0 && OD->getSuperClass() != nullptr) {
  691. for (const auto *P : OD->all_referenced_protocols()) {
  692. argumentNumber = getLocalizedArgumentForSelector(P->getIdentifier(), S);
  693. if (argumentNumber >= 0)
  694. break;
  695. }
  696. if (argumentNumber < 0) {
  697. OD = OD->getSuperClass();
  698. argumentNumber = getLocalizedArgumentForSelector(OD->getIdentifier(), S);
  699. }
  700. }
  701. if (argumentNumber < 0) { // There was no match in UIMethods
  702. if (const Decl *D = msg.getDecl()) {
  703. if (const ObjCMethodDecl *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
  704. auto formals = OMD->parameters();
  705. for (unsigned i = 0, ei = formals.size(); i != ei; ++i) {
  706. if (isAnnotatedAsTakingLocalized(formals[i])) {
  707. argumentNumber = i;
  708. break;
  709. }
  710. }
  711. }
  712. }
  713. }
  714. if (argumentNumber < 0) // Still no match
  715. return;
  716. SVal svTitle = msg.getArgSVal(argumentNumber);
  717. if (const ObjCStringRegion *SR =
  718. dyn_cast_or_null<ObjCStringRegion>(svTitle.getAsRegion())) {
  719. StringRef stringValue =
  720. SR->getObjCStringLiteral()->getString()->getString();
  721. if ((stringValue.trim().size() == 0 && stringValue.size() > 0) ||
  722. stringValue.empty())
  723. return;
  724. if (!IsAggressive && llvm::sys::unicode::columnWidthUTF8(stringValue) < 2)
  725. return;
  726. }
  727. bool isNonLocalized = hasNonLocalizedState(svTitle, C);
  728. if (isNonLocalized) {
  729. reportLocalizationError(svTitle, msg, C, argumentNumber + 1);
  730. }
  731. }
  732. void NonLocalizedStringChecker::checkPreCall(const CallEvent &Call,
  733. CheckerContext &C) const {
  734. const auto *FD = dyn_cast_or_null<FunctionDecl>(Call.getDecl());
  735. if (!FD)
  736. return;
  737. auto formals = FD->parameters();
  738. for (unsigned i = 0, ei = std::min(static_cast<unsigned>(formals.size()),
  739. Call.getNumArgs()); i != ei; ++i) {
  740. if (isAnnotatedAsTakingLocalized(formals[i])) {
  741. auto actual = Call.getArgSVal(i);
  742. if (hasNonLocalizedState(actual, C)) {
  743. reportLocalizationError(actual, Call, C, i + 1);
  744. }
  745. }
  746. }
  747. }
  748. static inline bool isNSStringType(QualType T, ASTContext &Ctx) {
  749. const ObjCObjectPointerType *PT = T->getAs<ObjCObjectPointerType>();
  750. if (!PT)
  751. return false;
  752. ObjCInterfaceDecl *Cls = PT->getObjectType()->getInterface();
  753. if (!Cls)
  754. return false;
  755. IdentifierInfo *ClsName = Cls->getIdentifier();
  756. // FIXME: Should we walk the chain of classes?
  757. return ClsName == &Ctx.Idents.get("NSString") ||
  758. ClsName == &Ctx.Idents.get("NSMutableString");
  759. }
  760. /// Marks a string being returned by any call as localized
  761. /// if it is in LocStringFunctions (LSF) or the function is annotated.
  762. /// Otherwise, we mark it as NonLocalized (Aggressive) or
  763. /// NonLocalized only if it is not backed by a SymRegion (Non-Aggressive),
  764. /// basically leaving only string literals as NonLocalized.
  765. void NonLocalizedStringChecker::checkPostCall(const CallEvent &Call,
  766. CheckerContext &C) const {
  767. initLocStringsMethods(C.getASTContext());
  768. if (!Call.getOriginExpr())
  769. return;
  770. // Anything that takes in a localized NSString as an argument
  771. // and returns an NSString will be assumed to be returning a
  772. // localized NSString. (Counter: Incorrectly combining two LocalizedStrings)
  773. const QualType RT = Call.getResultType();
  774. if (isNSStringType(RT, C.getASTContext())) {
  775. for (unsigned i = 0; i < Call.getNumArgs(); ++i) {
  776. SVal argValue = Call.getArgSVal(i);
  777. if (hasLocalizedState(argValue, C)) {
  778. SVal sv = Call.getReturnValue();
  779. setLocalizedState(sv, C);
  780. return;
  781. }
  782. }
  783. }
  784. const Decl *D = Call.getDecl();
  785. if (!D)
  786. return;
  787. const IdentifierInfo *Identifier = Call.getCalleeIdentifier();
  788. SVal sv = Call.getReturnValue();
  789. if (isAnnotatedAsReturningLocalized(D) || LSF.contains(Identifier)) {
  790. setLocalizedState(sv, C);
  791. } else if (isNSStringType(RT, C.getASTContext()) &&
  792. !hasLocalizedState(sv, C)) {
  793. if (IsAggressive) {
  794. setNonLocalizedState(sv, C);
  795. } else {
  796. const SymbolicRegion *SymReg =
  797. dyn_cast_or_null<SymbolicRegion>(sv.getAsRegion());
  798. if (!SymReg)
  799. setNonLocalizedState(sv, C);
  800. }
  801. }
  802. }
  803. /// Marks a string being returned by an ObjC method as localized
  804. /// if it is in LocStringMethods or the method is annotated
  805. void NonLocalizedStringChecker::checkPostObjCMessage(const ObjCMethodCall &msg,
  806. CheckerContext &C) const {
  807. initLocStringsMethods(C.getASTContext());
  808. if (!msg.isInstanceMessage())
  809. return;
  810. const ObjCInterfaceDecl *OD = msg.getReceiverInterface();
  811. if (!OD)
  812. return;
  813. const IdentifierInfo *odInfo = OD->getIdentifier();
  814. Selector S = msg.getSelector();
  815. std::string SelectorName = S.getAsString();
  816. std::pair<const IdentifierInfo *, Selector> MethodDescription = {odInfo, S};
  817. if (LSM.count(MethodDescription) ||
  818. isAnnotatedAsReturningLocalized(msg.getDecl())) {
  819. SVal sv = msg.getReturnValue();
  820. setLocalizedState(sv, C);
  821. }
  822. }
  823. /// Marks all empty string literals as localized
  824. void NonLocalizedStringChecker::checkPostStmt(const ObjCStringLiteral *SL,
  825. CheckerContext &C) const {
  826. SVal sv = C.getSVal(SL);
  827. setNonLocalizedState(sv, C);
  828. }
  829. PathDiagnosticPieceRef
  830. NonLocalizedStringBRVisitor::VisitNode(const ExplodedNode *Succ,
  831. BugReporterContext &BRC,
  832. PathSensitiveBugReport &BR) {
  833. if (Satisfied)
  834. return nullptr;
  835. Optional<StmtPoint> Point = Succ->getLocation().getAs<StmtPoint>();
  836. if (!Point.hasValue())
  837. return nullptr;
  838. auto *LiteralExpr = dyn_cast<ObjCStringLiteral>(Point->getStmt());
  839. if (!LiteralExpr)
  840. return nullptr;
  841. SVal LiteralSVal = Succ->getSVal(LiteralExpr);
  842. if (LiteralSVal.getAsRegion() != NonLocalizedString)
  843. return nullptr;
  844. Satisfied = true;
  845. PathDiagnosticLocation L =
  846. PathDiagnosticLocation::create(*Point, BRC.getSourceManager());
  847. if (!L.isValid() || !L.asLocation().isValid())
  848. return nullptr;
  849. auto Piece = std::make_shared<PathDiagnosticEventPiece>(
  850. L, "Non-localized string literal here");
  851. Piece->addRange(LiteralExpr->getSourceRange());
  852. return std::move(Piece);
  853. }
  854. namespace {
  855. class EmptyLocalizationContextChecker
  856. : public Checker<check::ASTDecl<ObjCImplementationDecl>> {
  857. // A helper class, which walks the AST
  858. class MethodCrawler : public ConstStmtVisitor<MethodCrawler> {
  859. const ObjCMethodDecl *MD;
  860. BugReporter &BR;
  861. AnalysisManager &Mgr;
  862. const CheckerBase *Checker;
  863. LocationOrAnalysisDeclContext DCtx;
  864. public:
  865. MethodCrawler(const ObjCMethodDecl *InMD, BugReporter &InBR,
  866. const CheckerBase *Checker, AnalysisManager &InMgr,
  867. AnalysisDeclContext *InDCtx)
  868. : MD(InMD), BR(InBR), Mgr(InMgr), Checker(Checker), DCtx(InDCtx) {}
  869. void VisitStmt(const Stmt *S) { VisitChildren(S); }
  870. void VisitObjCMessageExpr(const ObjCMessageExpr *ME);
  871. void reportEmptyContextError(const ObjCMessageExpr *M) const;
  872. void VisitChildren(const Stmt *S) {
  873. for (const Stmt *Child : S->children()) {
  874. if (Child)
  875. this->Visit(Child);
  876. }
  877. }
  878. };
  879. public:
  880. void checkASTDecl(const ObjCImplementationDecl *D, AnalysisManager &Mgr,
  881. BugReporter &BR) const;
  882. };
  883. } // end anonymous namespace
  884. void EmptyLocalizationContextChecker::checkASTDecl(
  885. const ObjCImplementationDecl *D, AnalysisManager &Mgr,
  886. BugReporter &BR) const {
  887. for (const ObjCMethodDecl *M : D->methods()) {
  888. AnalysisDeclContext *DCtx = Mgr.getAnalysisDeclContext(M);
  889. const Stmt *Body = M->getBody();
  890. if (!Body) {
  891. assert(M->isSynthesizedAccessorStub());
  892. continue;
  893. }
  894. MethodCrawler MC(M->getCanonicalDecl(), BR, this, Mgr, DCtx);
  895. MC.VisitStmt(Body);
  896. }
  897. }
  898. /// This check attempts to match these macros, assuming they are defined as
  899. /// follows:
  900. ///
  901. /// #define NSLocalizedString(key, comment) \
  902. /// [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]
  903. /// #define NSLocalizedStringFromTable(key, tbl, comment) \
  904. /// [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]
  905. /// #define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \
  906. /// [bundle localizedStringForKey:(key) value:@"" table:(tbl)]
  907. /// #define NSLocalizedStringWithDefaultValue(key, tbl, bundle, val, comment)
  908. ///
  909. /// We cannot use the path sensitive check because the macro argument we are
  910. /// checking for (comment) is not used and thus not present in the AST,
  911. /// so we use Lexer on the original macro call and retrieve the value of
  912. /// the comment. If it's empty or nil, we raise a warning.
  913. void EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr(
  914. const ObjCMessageExpr *ME) {
  915. // FIXME: We may be able to use PPCallbacks to check for empty context
  916. // comments as part of preprocessing and avoid this re-lexing hack.
  917. const ObjCInterfaceDecl *OD = ME->getReceiverInterface();
  918. if (!OD)
  919. return;
  920. const IdentifierInfo *odInfo = OD->getIdentifier();
  921. if (!(odInfo->isStr("NSBundle") &&
  922. ME->getSelector().getAsString() ==
  923. "localizedStringForKey:value:table:")) {
  924. return;
  925. }
  926. SourceRange R = ME->getSourceRange();
  927. if (!R.getBegin().isMacroID())
  928. return;
  929. // getImmediateMacroCallerLoc gets the location of the immediate macro
  930. // caller, one level up the stack toward the initial macro typed into the
  931. // source, so SL should point to the NSLocalizedString macro.
  932. SourceLocation SL =
  933. Mgr.getSourceManager().getImmediateMacroCallerLoc(R.getBegin());
  934. std::pair<FileID, unsigned> SLInfo =
  935. Mgr.getSourceManager().getDecomposedLoc(SL);
  936. SrcMgr::SLocEntry SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);
  937. // If NSLocalizedString macro is wrapped in another macro, we need to
  938. // unwrap the expansion until we get to the NSLocalizedStringMacro.
  939. while (SE.isExpansion()) {
  940. SL = SE.getExpansion().getSpellingLoc();
  941. SLInfo = Mgr.getSourceManager().getDecomposedLoc(SL);
  942. SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);
  943. }
  944. llvm::Optional<llvm::MemoryBufferRef> BF =
  945. Mgr.getSourceManager().getBufferOrNone(SLInfo.first, SL);
  946. if (!BF)
  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();
  1119. if (!Condition)
  1120. return true;
  1121. Condition = Condition->IgnoreParenImpCasts();
  1122. if (isCheckingPlurality(Condition)) {
  1123. MatchingStatements.push_back(I);
  1124. InMatchingStatement = true;
  1125. } else {
  1126. MatchingStatements.push_back(nullptr);
  1127. InMatchingStatement = false;
  1128. }
  1129. return true;
  1130. }
  1131. // Preliminary support for conditional operators.
  1132. bool PluralMisuseChecker::MethodCrawler::TraverseConditionalOperator(
  1133. ConditionalOperator *C) {
  1134. RecursiveASTVisitor<MethodCrawler>::TraverseConditionalOperator(C);
  1135. MatchingStatements.pop_back();
  1136. if (!MatchingStatements.empty()) {
  1137. if (MatchingStatements.back() != nullptr)
  1138. InMatchingStatement = true;
  1139. else
  1140. InMatchingStatement = false;
  1141. } else {
  1142. InMatchingStatement = false;
  1143. }
  1144. return true;
  1145. }
  1146. bool PluralMisuseChecker::MethodCrawler::VisitConditionalOperator(
  1147. const ConditionalOperator *C) {
  1148. const Expr *Condition = C->getCond()->IgnoreParenImpCasts();
  1149. if (isCheckingPlurality(Condition)) {
  1150. MatchingStatements.push_back(C);
  1151. InMatchingStatement = true;
  1152. } else {
  1153. MatchingStatements.push_back(nullptr);
  1154. InMatchingStatement = false;
  1155. }
  1156. return true;
  1157. }
  1158. void PluralMisuseChecker::MethodCrawler::reportPluralMisuseError(
  1159. const Stmt *S) const {
  1160. // Generate the bug report.
  1161. BR.EmitBasicReport(AC->getDecl(), Checker, "Plural Misuse",
  1162. "Localizability Issue (Apple)",
  1163. "Plural cases are not supported across all languages. "
  1164. "Use a .stringsdict file instead",
  1165. PathDiagnosticLocation(S, BR.getSourceManager(), AC));
  1166. }
  1167. //===----------------------------------------------------------------------===//
  1168. // Checker registration.
  1169. //===----------------------------------------------------------------------===//
  1170. void ento::registerNonLocalizedStringChecker(CheckerManager &mgr) {
  1171. NonLocalizedStringChecker *checker =
  1172. mgr.registerChecker<NonLocalizedStringChecker>();
  1173. checker->IsAggressive =
  1174. mgr.getAnalyzerOptions().getCheckerBooleanOption(
  1175. checker, "AggressiveReport");
  1176. }
  1177. bool ento::shouldRegisterNonLocalizedStringChecker(const CheckerManager &mgr) {
  1178. return true;
  1179. }
  1180. void ento::registerEmptyLocalizationContextChecker(CheckerManager &mgr) {
  1181. mgr.registerChecker<EmptyLocalizationContextChecker>();
  1182. }
  1183. bool ento::shouldRegisterEmptyLocalizationContextChecker(
  1184. const CheckerManager &mgr) {
  1185. return true;
  1186. }
  1187. void ento::registerPluralMisuseChecker(CheckerManager &mgr) {
  1188. mgr.registerChecker<PluralMisuseChecker>();
  1189. }
  1190. bool ento::shouldRegisterPluralMisuseChecker(const CheckerManager &mgr) {
  1191. return true;
  1192. }