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