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