<div dir="ltr">NP, thanks for the quick fixes!</div><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 7, 2015 at 9:56 PM Anna Zaks <<a href="mailto:ganna@apple.com">ganna@apple.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Sorry about the breakage! I’ve reverted the commit in <span style="font-family:Menlo;font-size:11px">r244394.</span></div><div style="word-wrap:break-word"><div><font face="Menlo"><span style="font-size:11px"><br></span></font></div><div><font face="Menlo"><span style="font-size:11px">Anna.</span></font></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div>On Aug 7, 2015, at 9:08 PM, Chandler Carruth <<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>> wrote:</div><br></blockquote></div></div></div><div style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div dir="ltr">Note that this is still failing on bots even after the windows fix:<div><br></div><div><a href="http://lab.llvm.org:8011/builders/clang-x86_64-ubuntu-gdb-75/builds/24169" target="_blank">http://lab.llvm.org:8011/builders/clang-x86_64-ubuntu-gdb-75/builds/24169</a><br></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Aug 7, 2015 at 6:50 PM Anna Zaks via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: zaks<br>
Date: Fri Aug  7 20:49:26 2015<br>
New Revision: 244389<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=244389&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=244389&view=rev</a><br>
Log:<br>
[analyzer] Add checkers for OS X / iOS localizability issues<br>
<br>
Add checkers that detect code-level localizability issues for OS X / iOS:<br>
 - A path sensitive checker that warns about uses of non-localized<br>
 NSStrings passed to UI methods expecting localized strings.<br>
 - A syntax checker that warns against not including a comment in<br>
 NSLocalizedString macros.<br>
<br>
A patch by Kulpreet Chilana!<br>
<br>
Added:<br>
    cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp<br>
    cfe/trunk/test/Analysis/localization-aggressive.m<br>
    cfe/trunk/test/Analysis/localization.m<br>
Modified:<br>
    cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt<br>
    cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td<br>
<br>
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=244389&r1=244388&r2=244389&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt?rev=244389&r1=244388&r2=244389&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/CMakeLists.txt Fri Aug  7 20:49:26 2015<br>
@@ -39,6 +39,7 @@ add_clang_library(clangStaticAnalyzerChe<br>
   IdenticalExprChecker.cpp<br>
   IvarInvalidationChecker.cpp<br>
   LLVMConventionsChecker.cpp<br>
+  LocalizationChecker.cpp<br>
   MacOSKeychainAPIChecker.cpp<br>
   MacOSXAPIChecker.cpp<br>
   MallocChecker.cpp<br>
<br>
Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td?rev=244389&r1=244388&r2=244389&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td?rev=244389&r1=244388&r2=244389&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td (original)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/Checkers.td Fri Aug  7 20:49:26 2015<br>
@@ -452,6 +452,14 @@ def DirectIvarAssignmentForAnnotatedFunc<br>
   HelpText<"Check for direct assignments to instance variables in the methods annotated with objc_no_direct_instance_variable_assignment">,<br>
   DescFile<"DirectIvarAssignment.cpp">;<br>
<br>
+def NonLocalizedStringChecker : Checker<"NonLocalizedStringChecker">,<br>
+  HelpText<"Warns about uses of non-localized NSStrings passed to UI methods expecting localized NSStrings">,<br>
+  DescFile<"LocalizationChecker.cpp">;<br>
+<br>
+def EmptyLocalizationContextChecker : Checker<"EmptyLocalizationContextChecker">,<br>
+  HelpText<"Check that NSLocalizedString macros include a comment for context">,<br>
+  DescFile<"LocalizationChecker.cpp">;<br>
+<br>
 } // end "alpha.osx.cocoa"<br>
<br>
 let ParentPackage = CoreFoundation in {<br>
<br>
Added: cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp?rev=244389&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp?rev=244389&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp (added)<br>
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp Fri Aug  7 20:49:26 2015<br>
@@ -0,0 +1,559 @@<br>
+//=- LocalizationChecker.cpp -------------------------------------*- C++ -*-==//<br>
+//<br>
+//                     The LLVM Compiler Infrastructure<br>
+//<br>
+// This file is distributed under the University of Illinois Open Source<br>
+// License. See LICENSE.TXT for details.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+//<br>
+//  This file defines a set of checks for localizability including:<br>
+//  1) A checker that warns about uses of non-localized NSStrings passed to<br>
+//     UI methods expecting localized strings<br>
+//  2) A syntactic checker that warns against the bad practice of<br>
+//     not including a comment in NSLocalizedString macros.<br>
+//<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+#include "ClangSACheckers.h"<br>
+#include "SelectorExtras.h"<br>
+#include "clang/AST/Attr.h"<br>
+#include "clang/AST/Decl.h"<br>
+#include "clang/AST/DeclObjC.h"<br>
+#include "clang/StaticAnalyzer/Core/BugReporter/BugReporter.h"<br>
+#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"<br>
+#include "clang/StaticAnalyzer/Core/Checker.h"<br>
+#include "clang/StaticAnalyzer/Core/CheckerManager.h"<br>
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"<br>
+#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"<br>
+#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"<br>
+#include "clang/Lex/Lexer.h"<br>
+#include "clang/AST/RecursiveASTVisitor.h"<br>
+#include "clang/AST/StmtVisitor.h"<br>
+#include "llvm/Support/Unicode.h"<br>
+<br>
+using namespace clang;<br>
+using namespace ento;<br>
+<br>
+namespace {<br>
+struct LocalizedState {<br>
+private:<br>
+  enum Kind { NonLocalized, Localized } K;<br>
+  LocalizedState(Kind InK) : K(InK) {}<br>
+<br>
+public:<br>
+  bool isLocalized() const { return K == Localized; }<br>
+  bool isNonLocalized() const { return K == NonLocalized; }<br>
+<br>
+  static LocalizedState getLocalized() { return LocalizedState(Localized); }<br>
+  static LocalizedState getNonLocalized() {<br>
+    return LocalizedState(NonLocalized);<br>
+  }<br>
+<br>
+  // Overload the == operator<br>
+  bool operator==(const LocalizedState &X) const { return K == X.K; }<br>
+<br>
+  // LLVMs equivalent of a hash function<br>
+  void Profile(llvm::FoldingSetNodeID &ID) const { ID.AddInteger(K); }<br>
+};<br>
+<br>
+class NonLocalizedStringChecker<br>
+    : public Checker<check::PostCall, check::PreObjCMessage,<br>
+                     check::PostObjCMessage,<br>
+                     check::PostStmt<ObjCStringLiteral>> {<br>
+<br>
+  mutable std::unique_ptr<BugType> BT;<br>
+<br>
+  // Methods that require a localized string<br>
+  mutable std::map<StringRef, std::map<StringRef, uint8_t>> UIMethods;<br>
+  // Methods that return a localized string<br>
+  mutable llvm::SmallSet<std::pair<StringRef, StringRef>, 10> LSM;<br>
+  // C Functions that return a localized string<br>
+  mutable llvm::StringMap<char> LSF;<br>
+<br>
+  void initUIMethods(ASTContext &Ctx) const;<br>
+  void initLocStringsMethods(ASTContext &Ctx) const;<br>
+<br>
+  bool hasNonLocalizedState(SVal S, CheckerContext &C) const;<br>
+  bool hasLocalizedState(SVal S, CheckerContext &C) const;<br>
+  void setNonLocalizedState(SVal S, CheckerContext &C) const;<br>
+  void setLocalizedState(SVal S, CheckerContext &C) const;<br>
+<br>
+  bool isAnnotatedAsLocalized(const Decl *D) const;<br>
+  void reportLocalizationError(SVal S, const ObjCMethodCall &M,<br>
+                               CheckerContext &C, int argumentNumber = 0) const;<br>
+<br>
+public:<br>
+  NonLocalizedStringChecker();<br>
+<br>
+  // When this parameter is set to true, the checker assumes all<br>
+  // methods that return NSStrings are unlocalized. Thus, more false<br>
+  // positives will be reported.<br>
+  DefaultBool IsAggressive;<br>
+<br>
+  void checkPreObjCMessage(const ObjCMethodCall &msg, CheckerContext &C) const;<br>
+  void checkPostObjCMessage(const ObjCMethodCall &msg, CheckerContext &C) const;<br>
+  void checkPostStmt(const ObjCStringLiteral *SL, CheckerContext &C) const;<br>
+  void checkPostCall(const CallEvent &Call, CheckerContext &C) const;<br>
+};<br>
+<br>
+} // end anonymous namespace<br>
+<br>
+REGISTER_MAP_WITH_PROGRAMSTATE(LocalizedMemMap, const MemRegion *,<br>
+                               LocalizedState)<br>
+<br>
+NonLocalizedStringChecker::NonLocalizedStringChecker() {<br>
+  BT.reset(new BugType(this, "Unlocalized string", "Localizability Error"));<br>
+}<br>
+<br>
+/// Initializes a list of methods that require a localized string<br>
+/// Format: {"ClassName", {{"selectorName:", LocStringArg#}, ...}, ...}<br>
+void NonLocalizedStringChecker::initUIMethods(ASTContext &Ctx) const {<br>
+  if (!UIMethods.empty())<br>
+    return;<br>
+<br>
+  // TODO: This should eventually be a comprehensive list of UIKit methods<br>
+<br>
+  UIMethods = {{"UILabel", {{"setText:", 0}}},<br>
+               {"UIButton", {{"setText:", 0}}},<br>
+               {"NSButton", {{"setTitle:", 0}}},<br>
+               {"NSButtonCell", {{"setTitle:", 0}}},<br>
+               {"NSMenuItem", {{"setTitle:", 0}}},<br>
+               {"UIAlertAction", {{"actionWithTitle:style:handler:", 0}}},<br>
+               {"UIAlertController",<br>
+                {{"alertControllerWithTitle:message:preferredStyle:", 1}}},<br>
+               {"NSAttributedString",<br>
+                {{"initWithString:", 0}, {"initWithString:attributes:", 0}}}};<br>
+}<br>
+<br>
+/// Initializes a list of methods and C functions that return a localized string<br>
+void NonLocalizedStringChecker::initLocStringsMethods(ASTContext &Ctx) const {<br>
+  if (!LSM.empty())<br>
+    return;<br>
+<br>
+  LSM.insert({"NSBundle", "localizedStringForKey:value:table:"});<br>
+  LSM.insert({"NSDateFormatter", "stringFromDate:"});<br>
+  LSM.insert(<br>
+      {"NSDateFormatter", "localizedStringFromDate:dateStyle:timeStyle:"});<br>
+  LSM.insert({"NSNumberFormatter", "stringFromNumber:"});<br>
+  LSM.insert({"UITextField", "text"});<br>
+  LSM.insert({"UITextView", "text"});<br>
+  LSM.insert({"UILabel", "text"});<br>
+<br>
+  LSF.insert({"CFDateFormatterCreateStringWithDate", '\0'});<br>
+  LSF.insert({"CFDateFormatterCreateStringWithAbsoluteTime", '\0'});<br>
+  LSF.insert({"CFNumberFormatterCreateStringWithNumber", '\0'});<br>
+}<br>
+<br>
+/// Checks to see if the method / function declaration includes<br>
+/// __attribute__((annotate("returns_localized_nsstring")))<br>
+bool NonLocalizedStringChecker::isAnnotatedAsLocalized(const Decl *D) const {<br>
+  return std::any_of(<br>
+      D->specific_attr_begin<AnnotateAttr>(),<br>
+      D->specific_attr_end<AnnotateAttr>(), [](const AnnotateAttr *Ann) {<br>
+        return Ann->getAnnotation() == "returns_localized_nsstring";<br>
+      });<br>
+}<br>
+<br>
+/// Returns true if the given SVal is marked as Localized in the program state<br>
+bool NonLocalizedStringChecker::hasLocalizedState(SVal S,<br>
+                                                  CheckerContext &C) const {<br>
+  const MemRegion *mt = S.getAsRegion();<br>
+  if (mt) {<br>
+    const LocalizedState *LS = C.getState()->get<LocalizedMemMap>(mt);<br>
+    if (LS && LS->isLocalized())<br>
+      return true;<br>
+  }<br>
+  return false;<br>
+}<br>
+<br>
+/// Returns true if the given SVal is marked as NonLocalized in the program<br>
+/// state<br>
+bool NonLocalizedStringChecker::hasNonLocalizedState(SVal S,<br>
+                                                     CheckerContext &C) const {<br>
+  const MemRegion *mt = S.getAsRegion();<br>
+  if (mt) {<br>
+    const LocalizedState *LS = C.getState()->get<LocalizedMemMap>(mt);<br>
+    if (LS && LS->isNonLocalized())<br>
+      return true;<br>
+  }<br>
+  return false;<br>
+}<br>
+<br>
+/// Marks the given SVal as Localized in the program state<br>
+void NonLocalizedStringChecker::setLocalizedState(const SVal S,<br>
+                                                  CheckerContext &C) const {<br>
+  const MemRegion *mt = S.getAsRegion();<br>
+  if (mt) {<br>
+    ProgramStateRef State =<br>
+        C.getState()->set<LocalizedMemMap>(mt, LocalizedState::getLocalized());<br>
+    C.addTransition(State);<br>
+  }<br>
+}<br>
+<br>
+/// Marks the given SVal as NonLocalized in the program state<br>
+void NonLocalizedStringChecker::setNonLocalizedState(const SVal S,<br>
+                                                     CheckerContext &C) const {<br>
+  const MemRegion *mt = S.getAsRegion();<br>
+  if (mt) {<br>
+    ProgramStateRef State = C.getState()->set<LocalizedMemMap>(<br>
+        mt, LocalizedState::getNonLocalized());<br>
+    C.addTransition(State);<br>
+  }<br>
+}<br>
+<br>
+/// Reports a localization error for the passed in method call and SVal<br>
+void NonLocalizedStringChecker::reportLocalizationError(<br>
+    SVal S, const ObjCMethodCall &M, CheckerContext &C,<br>
+    int argumentNumber) const {<br>
+<br>
+  ExplodedNode *ErrNode = C.getPredecessor();<br>
+  static CheckerProgramPointTag Tag("NonLocalizedStringChecker",<br>
+                                    "UnlocalizedString");<br>
+  ErrNode = C.addTransition(C.getState(), C.getPredecessor(), &Tag);<br>
+<br>
+  if (!ErrNode)<br>
+    return;<br>
+<br>
+  // Generate the bug report.<br>
+  std::unique_ptr<BugReport> R(<br>
+      new BugReport(*BT, "String should be localized", ErrNode));<br>
+  if (argumentNumber) {<br>
+    R->addRange(M.getArgExpr(argumentNumber - 1)->getSourceRange());<br>
+  } else {<br>
+    R->addRange(M.getSourceRange());<br>
+  }<br>
+  R->markInteresting(S);<br>
+  C.emitReport(std::move(R));<br>
+}<br>
+<br>
+/// Check if the string being passed in has NonLocalized state<br>
+void NonLocalizedStringChecker::checkPreObjCMessage(const ObjCMethodCall &msg,<br>
+                                                    CheckerContext &C) const {<br>
+  initUIMethods(C.getASTContext());<br>
+<br>
+  const ObjCInterfaceDecl *OD = msg.getReceiverInterface();<br>
+  if (!OD)<br>
+    return;<br>
+  const IdentifierInfo *odInfo = OD->getIdentifier();<br>
+<br>
+  Selector S = msg.getSelector();<br>
+<br>
+  StringRef Name(S.getAsString());<br>
+  assert(!Name.empty());<br>
+<br>
+  auto method = UIMethods.find(odInfo->getName());<br>
+  if (odInfo->isStr("NSString")) {<br>
+    // Handle the case where the receiver is an NSString<br>
+    // These special NSString methods draw to the screen<br>
+<br>
+    if (!(Name.startswith("drawAtPoint") || Name.startswith("drawInRect") ||<br>
+          Name.startswith("drawWithRect")))<br>
+      return;<br>
+<br>
+    SVal svTitle = msg.getReceiverSVal();<br>
+<br>
+    bool isNonLocalized = hasNonLocalizedState(svTitle, C);<br>
+<br>
+    if (isNonLocalized) {<br>
+      reportLocalizationError(svTitle, msg, C);<br>
+    }<br>
+  } else if (method != UIMethods.end()) {<br>
+<br>
+    std::map<StringRef, uint8_t> m = method->second;<br>
+<br>
+    auto argumentIterator = m.find(Name);<br>
+<br>
+    if (argumentIterator == m.end())<br>
+      return;<br>
+<br>
+    int argumentNumber = argumentIterator->second;<br>
+<br>
+    SVal svTitle = msg.getArgSVal(argumentNumber);<br>
+<br>
+    if (const ObjCStringRegion *SR =<br>
+            dyn_cast_or_null<ObjCStringRegion>(svTitle.getAsRegion())) {<br>
+      StringRef stringValue =<br>
+          SR->getObjCStringLiteral()->getString()->getString();<br>
+      if ((stringValue.trim().size() == 0 && stringValue.size() > 0) ||<br>
+          stringValue.empty())<br>
+        return;<br>
+      if (!IsAggressive && llvm::sys::unicode::columnWidthUTF8(stringValue) < 2)<br>
+        return;<br>
+    }<br>
+<br>
+    bool isNonLocalized = hasNonLocalizedState(svTitle, C);<br>
+<br>
+    if (isNonLocalized) {<br>
+      reportLocalizationError(svTitle, msg, C, argumentNumber + 1);<br>
+    }<br>
+  }<br>
+}<br>
+<br>
+static inline bool isNSStringType(QualType T, ASTContext &Ctx) {<br>
+<br>
+  const ObjCObjectPointerType *PT = T->getAs<ObjCObjectPointerType>();<br>
+  if (!PT)<br>
+    return false;<br>
+<br>
+  ObjCInterfaceDecl *Cls = PT->getObjectType()->getInterface();<br>
+  if (!Cls)<br>
+    return false;<br>
+<br>
+  IdentifierInfo *ClsName = Cls->getIdentifier();<br>
+<br>
+  // FIXME: Should we walk the chain of classes?<br>
+  return ClsName == &Ctx.Idents.get("NSString") ||<br>
+         ClsName == &Ctx.Idents.get("NSMutableString");<br>
+}<br>
+<br>
+/// Marks a string being returned by any call as localized<br>
+/// if it is in LocStringFunctions (LSF) or the function is annotated.<br>
+/// Otherwise, we mark it as NonLocalized (Aggressive) or<br>
+/// NonLocalized only if it is not backed by a SymRegion (Non-Aggressive),<br>
+/// basically leaving only string literals as NonLocalized.<br>
+void NonLocalizedStringChecker::checkPostCall(const CallEvent &Call,<br>
+                                              CheckerContext &C) const {<br>
+  initLocStringsMethods(C.getASTContext());<br>
+<br>
+  if (!Call.getOriginExpr())<br>
+    return;<br>
+<br>
+  // Anything that takes in a localized NSString as an argument<br>
+  // and returns an NSString will be assumed to be returning a<br>
+  // localized NSString. (Counter: Incorrectly combining two LocalizedStrings)<br>
+  const QualType RT = Call.getResultType();<br>
+  if (isNSStringType(RT, C.getASTContext())) {<br>
+    for (unsigned i = 0; i < Call.getNumArgs(); ++i) {<br>
+      SVal argValue = Call.getArgSVal(i);<br>
+      if (hasLocalizedState(argValue, C)) {<br>
+        SVal sv = Call.getReturnValue();<br>
+        setLocalizedState(sv, C);<br>
+        return;<br>
+      }<br>
+    }<br>
+  }<br>
+<br>
+  const Decl *D = Call.getDecl();<br>
+  if (!D)<br>
+    return;<br>
+<br>
+  StringRef IdentifierName = C.getCalleeName(D->getAsFunction());<br>
+<br>
+  SVal sv = Call.getReturnValue();<br>
+  if (isAnnotatedAsLocalized(D) || LSF.find(IdentifierName) != LSF.end()) {<br>
+    setLocalizedState(sv, C);<br>
+  } else if (isNSStringType(RT, C.getASTContext()) &&<br>
+             !hasLocalizedState(sv, C)) {<br>
+    if (IsAggressive) {<br>
+      setNonLocalizedState(sv, C);<br>
+    } else {<br>
+      const SymbolicRegion *SymReg =<br>
+          dyn_cast_or_null<SymbolicRegion>(sv.getAsRegion());<br>
+      if (!SymReg)<br>
+        setNonLocalizedState(sv, C);<br>
+    }<br>
+  }<br>
+}<br>
+<br>
+/// Marks a string being returned by an ObjC method as localized<br>
+/// if it is in LocStringMethods or the method is annotated<br>
+void NonLocalizedStringChecker::checkPostObjCMessage(const ObjCMethodCall &msg,<br>
+                                                     CheckerContext &C) const {<br>
+  initLocStringsMethods(C.getASTContext());<br>
+<br>
+  if (!msg.isInstanceMessage())<br>
+    return;<br>
+<br>
+  const ObjCInterfaceDecl *OD = msg.getReceiverInterface();<br>
+  if (!OD)<br>
+    return;<br>
+  const IdentifierInfo *odInfo = OD->getIdentifier();<br>
+<br>
+  StringRef IdentifierName = odInfo->getName();<br>
+<br>
+  Selector S = msg.getSelector();<br>
+  StringRef SelectorName = S.getAsString();<br>
+  assert(!SelectorName.empty());<br>
+<br>
+  std::pair<StringRef, StringRef> MethodDescription = {IdentifierName,<br>
+                                                       SelectorName};<br>
+<br>
+  if (LSM.count(MethodDescription) || isAnnotatedAsLocalized(msg.getDecl())) {<br>
+    SVal sv = msg.getReturnValue();<br>
+    setLocalizedState(sv, C);<br>
+  }<br>
+}<br>
+<br>
+/// Marks all empty string literals as localized<br>
+void NonLocalizedStringChecker::checkPostStmt(const ObjCStringLiteral *SL,<br>
+                                              CheckerContext &C) const {<br>
+  SVal sv = C.getSVal(SL);<br>
+  setNonLocalizedState(sv, C);<br>
+}<br>
+<br>
+namespace {<br>
+class EmptyLocalizationContextChecker<br>
+    : public Checker<check::ASTDecl<ObjCImplementationDecl>> {<br>
+<br>
+  // A helper class, which walks the AST<br>
+  class MethodCrawler : public ConstStmtVisitor<MethodCrawler> {<br>
+    const ObjCMethodDecl *MD;<br>
+    BugReporter &BR;<br>
+    AnalysisManager &Mgr;<br>
+    const CheckerBase *Checker;<br>
+    LocationOrAnalysisDeclContext DCtx;<br>
+<br>
+  public:<br>
+    MethodCrawler(const ObjCMethodDecl *InMD, BugReporter &InBR,<br>
+                  const CheckerBase *Checker, AnalysisManager &InMgr,<br>
+                  AnalysisDeclContext *InDCtx)<br>
+        : MD(InMD), BR(InBR), Mgr(InMgr), Checker(Checker), DCtx(InDCtx) {}<br>
+<br>
+    void VisitStmt(const Stmt *S) { VisitChildren(S); }<br>
+<br>
+    void VisitObjCMessageExpr(const ObjCMessageExpr *ME);<br>
+<br>
+    void reportEmptyContextError(const ObjCMessageExpr *M) const;<br>
+<br>
+    void VisitChildren(const Stmt *S) {<br>
+      for (const Stmt *Child : S->children()) {<br>
+        if (Child)<br>
+          this->Visit(Child);<br>
+      }<br>
+    }<br>
+  };<br>
+<br>
+public:<br>
+  void checkASTDecl(const ObjCImplementationDecl *D, AnalysisManager &Mgr,<br>
+                    BugReporter &BR) const;<br>
+};<br>
+} // end anonymous namespace<br>
+<br>
+void EmptyLocalizationContextChecker::checkASTDecl(<br>
+    const ObjCImplementationDecl *D, AnalysisManager &Mgr,<br>
+    BugReporter &BR) const {<br>
+<br>
+  for (const ObjCMethodDecl *M : D->methods()) {<br>
+    AnalysisDeclContext *DCtx = Mgr.getAnalysisDeclContext(M);<br>
+<br>
+    const Stmt *Body = M->getBody();<br>
+    assert(Body);<br>
+<br>
+    MethodCrawler MC(M->getCanonicalDecl(), BR, this, Mgr, DCtx);<br>
+    MC.VisitStmt(Body);<br>
+  }<br>
+}<br>
+<br>
+/// This check attempts to match these macros, assuming they are defined as<br>
+/// follows:<br>
+///<br>
+/// #define NSLocalizedString(key, comment) \<br>
+/// [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]<br>
+/// #define NSLocalizedStringFromTable(key, tbl, comment) \<br>
+/// [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]<br>
+/// #define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment) \<br>
+/// [bundle localizedStringForKey:(key) value:@"" table:(tbl)]<br>
+/// #define NSLocalizedStringWithDefaultValue(key, tbl, bundle, val, comment)<br>
+///<br>
+/// We cannot use the path sensitive check because the macro argument we are<br>
+/// checking for (comment) is not used and thus not present in the AST,<br>
+/// so we use Lexer on the original macro call and retrieve the value of<br>
+/// the comment. If it's empty or nil, we raise a warning.<br>
+void EmptyLocalizationContextChecker::MethodCrawler::VisitObjCMessageExpr(<br>
+    const ObjCMessageExpr *ME) {<br>
+<br>
+  const ObjCInterfaceDecl *OD = ME->getReceiverInterface();<br>
+  if (!OD)<br>
+    return;<br>
+<br>
+  const IdentifierInfo *odInfo = OD->getIdentifier();<br>
+<br>
+  if (!(odInfo->isStr("NSBundle") ||<br>
+        StringRef(ME->getSelector().getAsString())<br>
+            .equals("localizedStringForKey:value:table:"))) {<br>
+    return;<br>
+  }<br>
+<br>
+  SourceRange R = ME->getSourceRange();<br>
+  if (!R.getBegin().isMacroID())<br>
+    return;<br>
+<br>
+  // getImmediateMacroCallerLoc gets the location of the immediate macro<br>
+  // caller, one level up the stack toward the initial macro typed into the<br>
+  // source, so SL should point to the NSLocalizedString macro.<br>
+  SourceLocation SL =<br>
+      Mgr.getSourceManager().getImmediateMacroCallerLoc(R.getBegin());<br>
+  std::pair<FileID, unsigned> SLInfo =<br>
+      Mgr.getSourceManager().getDecomposedLoc(SL);<br>
+<br>
+  SrcMgr::SLocEntry SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);<br>
+<br>
+  // If NSLocalizedString macro is wrapped in another macro, we need to<br>
+  // unwrap the expansion until we get to the NSLocalizedStringMacro.<br>
+  while (SE.isExpansion()) {<br>
+    SL = SE.getExpansion().getSpellingLoc();<br>
+    SLInfo = Mgr.getSourceManager().getDecomposedLoc(SL);<br>
+    SE = Mgr.getSourceManager().getSLocEntry(SLInfo.first);<br>
+  }<br>
+<br>
+  llvm::MemoryBuffer *BF = SE.getFile().getContentCache()->getRawBuffer();<br>
+  Lexer TheLexer(SL, LangOptions(), BF->getBufferStart(),<br>
+                 BF->getBufferStart() + SLInfo.second, BF->getBufferEnd());<br>
+<br>
+  Token I;<br>
+  Token Result;    // This will hold the token just before the last ')'<br>
+  int p_count = 0; // This is for parenthesis matching<br>
+  while (!TheLexer.LexFromRawLexer(I)) {<br>
+    if (I.getKind() == tok::l_paren)<br>
+      ++p_count;<br>
+    if (I.getKind() == tok::r_paren) {<br>
+      if (p_count == 1)<br>
+        break;<br>
+      --p_count;<br>
+    }<br>
+    Result = I;<br>
+  }<br>
+<br>
+  if (isAnyIdentifier(Result.getKind())) {<br>
+    if (Result.getRawIdentifier().equals("nil")) {<br>
+      reportEmptyContextError(ME);<br>
+      return;<br>
+    }<br>
+  }<br>
+<br>
+  if (!isStringLiteral(Result.getKind()))<br>
+    return;<br>
+<br>
+  StringRef Comment =<br>
+      StringRef(Result.getLiteralData(), Result.getLength()).trim("\"");<br>
+<br>
+  if ((Comment.trim().size() == 0 && Comment.size() > 0) || // Is Whitespace<br>
+      Comment.empty()) {<br>
+    reportEmptyContextError(ME);<br>
+  }<br>
+}<br>
+<br>
+void EmptyLocalizationContextChecker::MethodCrawler::reportEmptyContextError(<br>
+    const ObjCMessageExpr *ME) const {<br>
+  // Generate the bug report.<br>
+  BR.EmitBasicReport(MD, Checker, "Context Missing", "Localizability Error",<br>
+                     "Localized string macro should include a non-empty "<br>
+                     "comment for translators",<br>
+                     PathDiagnosticLocation(ME, BR.getSourceManager(), DCtx));<br>
+}<br>
+<br>
+//===----------------------------------------------------------------------===//<br>
+// Checker registration.<br>
+//===----------------------------------------------------------------------===//<br>
+<br>
+void ento::registerNonLocalizedStringChecker(CheckerManager &mgr) {<br>
+  NonLocalizedStringChecker *checker =<br>
+      mgr.registerChecker<NonLocalizedStringChecker>();<br>
+  checker->IsAggressive =<br>
+      mgr.getAnalyzerOptions().getBooleanOption("AggressiveReport", false);<br>
+}<br>
+<br>
+void ento::registerEmptyLocalizationContextChecker(CheckerManager &mgr) {<br>
+  mgr.registerChecker<EmptyLocalizationContextChecker>();<br>
+}<br>
\ No newline at end of file<br>
<br>
Added: cfe/trunk/test/Analysis/localization-aggressive.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/localization-aggressive.m?rev=244389&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/localization-aggressive.m?rev=244389&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Analysis/localization-aggressive.m (added)<br>
+++ cfe/trunk/test/Analysis/localization-aggressive.m Fri Aug  7 20:49:26 2015<br>
@@ -0,0 +1,243 @@<br>
+// RUN: %clang_cc1 -analyze -fblocks -analyzer-store=region  -analyzer-checker=alpha.osx.cocoa.NonLocalizedStringChecker -analyzer-checker=alpha.osx.cocoa.EmptyLocalizationContextChecker -verify  -analyzer-config AggressiveReport=true %s<br>
+<br>
+// These declarations were reduced using Delta-Debugging from Foundation.h<br>
+// on Mac OS X.<br>
+<br>
+#define nil ((id)0)<br>
+#define NSLocalizedString(key, comment)                                        \<br>
+  [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]<br>
+#define NSLocalizedStringFromTable(key, tbl, comment)                          \<br>
+  [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]<br>
+#define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment)          \<br>
+  [bundle localizedStringForKey:(key) value:@"" table:(tbl)]<br>
+#define NSLocalizedStringWithDefaultValue(key, tbl, bundle, val, comment)      \<br>
+  [bundle localizedStringForKey:(key) value:(val) table:(tbl)]<br>
+#define CGFLOAT_TYPE double<br>
+typedef CGFLOAT_TYPE CGFloat;<br>
+struct CGPoint {<br>
+  CGFloat x;<br>
+  CGFloat y;<br>
+};<br>
+typedef struct CGPoint CGPoint;<br>
+@interface NSObject<br>
++ (id)alloc;<br>
+- (id)init;<br>
+@end<br>
+@class NSDictionary;<br>
+@interface NSString : NSObject<br>
+- (void)drawAtPoint:(CGPoint)point withAttributes:(NSDictionary *)attrs;<br>
++ (instancetype)localizedStringWithFormat:(NSString *)format, ...;<br>
+@end<br>
+@interface NSBundle : NSObject<br>
++ (NSBundle *)mainBundle;<br>
+- (NSString *)localizedStringForKey:(NSString *)key<br>
+                              value:(NSString *)value<br>
+                              table:(NSString *)tableName;<br>
+@end<br>
+@interface UILabel : NSObject<br>
+@property(nullable, nonatomic, copy) NSString *text;<br>
+- (void)accessibilitySetIdentification:(NSString *)ident;<br>
+@end<br>
+@interface TestObject : NSObject<br>
+@property(strong) NSString *text;<br>
+@end<br>
+<br>
+@interface LocalizationTestSuite : NSObject<br>
+NSString *ForceLocalized(NSString *str)<br>
+    __attribute__((annotate("returns_localized_nsstring")));<br>
+CGPoint CGPointMake(CGFloat x, CGFloat y);<br>
+int random();<br>
+// This next one is a made up API<br>
+NSString *CFNumberFormatterCreateStringWithNumber(float x);<br>
++ (NSString *)forceLocalized:(NSString *)str<br>
+    __attribute__((annotate("returns_localized_nsstring")));<br>
+@end<br>
+<br>
+// Test cases begin here<br>
+@implementation LocalizationTestSuite<br>
+<br>
+// A C-Funtion that returns a localized string because it has the<br>
+// "returns_localized_nsstring" annotation<br>
+NSString *ForceLocalized(NSString *str) { return str; }<br>
+// An ObjC method that returns a localized string because it has the<br>
+// "returns_localized_nsstring" annotation<br>
++ (NSString *)forceLocalized:(NSString *)str {<br>
+  return str;<br>
+}<br>
+<br>
+// An ObjC method that returns a localized string<br>
++ (NSString *)unLocalizedStringMethod {<br>
+  return @"UnlocalizedString";<br>
+}<br>
+<br>
+- (void)testLocalizationErrorDetectedOnPathway {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  NSString *bar = NSLocalizedString(@"Hello", @"Comment");<br>
+<br>
+  if (random()) {<br>
+    bar = @"Unlocalized string";<br>
+  }<br>
+<br>
+  [testLabel setText:bar]; // expected-warning {{String should be localized}}<br>
+}<br>
+<br>
+- (void)testLocalizationErrorDetectedOnNSString {<br>
+  NSString *bar = NSLocalizedString(@"Hello", @"Comment");<br>
+<br>
+  if (random()) {<br>
+    bar = @"Unlocalized string";<br>
+  }<br>
+<br>
+  [bar drawAtPoint:CGPointMake(0, 0) withAttributes:nil]; // expected-warning {{String should be localized}}<br>
+}<br>
+<br>
+- (void)testNoLocalizationErrorDetectedFromCFunction {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  NSString *bar = CFNumberFormatterCreateStringWithNumber(1);<br>
+<br>
+  [testLabel setText:bar]; // no-warning<br>
+}<br>
+<br>
+- (void)testAnnotationAddsLocalizedStateForCFunction {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  NSString *bar = NSLocalizedString(@"Hello", @"Comment");<br>
+<br>
+  if (random()) {<br>
+    bar = @"Unlocalized string";<br>
+  }<br>
+<br>
+  [testLabel setText:ForceLocalized(bar)]; // no-warning<br>
+}<br>
+<br>
+- (void)testAnnotationAddsLocalizedStateForObjCMethod {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  NSString *bar = NSLocalizedString(@"Hello", @"Comment");<br>
+<br>
+  if (random()) {<br>
+    bar = @"Unlocalized string";<br>
+  }<br>
+<br>
+  [testLabel setText:[LocalizationTestSuite forceLocalized:bar]]; // no-warning<br>
+}<br>
+<br>
+// An empty string literal @"" should not raise an error<br>
+- (void)testEmptyStringLiteralHasLocalizedState {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  NSString *bar = @"";<br>
+<br>
+  [testLabel setText:bar]; // no-warning<br>
+}<br>
+<br>
+// An empty string literal @"" inline should not raise an error<br>
+- (void)testInlineEmptyStringLiteralHasLocalizedState {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  [testLabel setText:@""]; // no-warning<br>
+}<br>
+<br>
+// An string literal @"Hello" inline should raise an error<br>
+- (void)testInlineStringLiteralHasLocalizedState {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  [testLabel setText:@"Hello"]; // expected-warning {{String should be localized}}<br>
+}<br>
+<br>
+// A nil string should not raise an error<br>
+- (void)testNilStringIsNotMarkedAsUnlocalized {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  [testLabel setText:nil]; // no-warning<br>
+}<br>
+<br>
+// A method that takes in a localized string and returns a string<br>
+// most likely that string is localized.<br>
+- (void)testLocalizedStringArgument {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  NSString *localizedString = NSLocalizedString(@"Hello", @"Comment");<br>
+<br>
+  NSString *combinedString =<br>
+      [NSString localizedStringWithFormat:@"%@", localizedString];<br>
+<br>
+  [testLabel setText:combinedString]; // no-warning<br>
+}<br>
+<br>
+// A String passed in as a an parameter should not be considered<br>
+// unlocalized<br>
+- (void)testLocalizedStringAsArgument:(NSString *)argumentString {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+<br>
+  [testLabel setText:argumentString]; // no-warning<br>
+}<br>
+<br>
+// A String passed into another method that calls a method that<br>
+// requires a localized string should give an error<br>
+- (void)localizedStringAsArgument:(NSString *)argumentString {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+<br>
+  [testLabel setText:argumentString]; // expected-warning {{String should be localized}}<br>
+}<br>
+<br>
+// The warning is expected to be seen in localizedStringAsArgument: body<br>
+- (void)testLocalizedStringAsArgumentOtherMethod:(NSString *)argumentString {<br>
+  [self localizedStringAsArgument:@"UnlocalizedString"];<br>
+}<br>
+<br>
+// [LocalizationTestSuite unLocalizedStringMethod] returns an unlocalized string<br>
+// so we expect an error. Unfrtunately, it probably doesn't make a difference<br>
+// what [LocalizationTestSuite unLocalizedStringMethod] returns since all<br>
+// string values returned are marked as Unlocalized in aggressive reporting.<br>
+- (void)testUnLocalizedStringMethod {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  NSString *bar = NSLocalizedString(@"Hello", @"Comment");<br>
+<br>
+  [testLabel setText:[LocalizationTestSuite unLocalizedStringMethod]]; // expected-warning {{String should be localized}}<br>
+}<br>
+<br>
+// This is the reverse situation: accessibilitySetIdentification: doesn't care<br>
+// about localization so we don't expect a warning<br>
+- (void)testMethodNotInRequiresLocalizedStringMethods {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+<br>
+  [testLabel accessibilitySetIdentification:@"UnlocalizedString"]; // no-warning<br>
+}<br>
+<br>
+// EmptyLocalizationContextChecker tests<br>
+#define HOM(s) YOLOC(s)<br>
+#define YOLOC(x) NSLocalizedString(x, nil)<br>
+<br>
+- (void)testNilLocalizationContext {<br>
+  NSString *string = NSLocalizedString(@"LocalizedString", nil); // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+  NSString *string2 = NSLocalizedString(@"LocalizedString", nil); // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+  NSString *string3 = NSLocalizedString(@"LocalizedString", nil); // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+}<br>
+<br>
+- (void)testEmptyLocalizationContext {<br>
+  NSString *string = NSLocalizedString(@"LocalizedString", @""); // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+  NSString *string2 = NSLocalizedString(@"LocalizedString", @" "); // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+  NSString *string3 = NSLocalizedString(@"LocalizedString", @"  "); // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+}<br>
+<br>
+- (void)testNSLocalizedStringVariants {<br>
+  NSString *string = NSLocalizedStringFromTable(@"LocalizedString", nil, @""); // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+  NSString *string2 = NSLocalizedStringFromTableInBundle(@"LocalizedString", nil, [[NSBundle alloc] init],@""); // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+  NSString *string3 = NSLocalizedStringWithDefaultValue(@"LocalizedString", nil, [[NSBundle alloc] init], nil,@""); // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+}<br>
+<br>
+- (void)testMacroExpansionNilString {<br>
+  NSString *string = YOLOC(@"Hello"); // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+  NSString *string2 = HOM(@"Hello");  // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+  NSString *string3 = NSLocalizedString((0 ? @"Critical" : @"Current"),nil); // expected-warning {{Localized string macro should include a non-empty comment for translators}}<br>
+}<br>
+<br>
+#define KCLocalizedString(x,comment) NSLocalizedString(x, comment)<br>
+#define POSSIBLE_FALSE_POSITIVE(s,other) KCLocalizedString(s,@"Comment")<br>
+<br>
+- (void)testNoWarningForNilCommentPassedIntoOtherMacro {<br>
+  NSString *string = KCLocalizedString(@"Hello",@""); // no-warning<br>
+  NSString *string2 = KCLocalizedString(@"Hello",nil); // no-warning<br>
+  NSString *string3 = KCLocalizedString(@"Hello",@"Comment"); // no-warning<br>
+}<br>
+<br>
+- (void)testPossibleFalsePositiveSituationAbove {<br>
+  NSString *string = POSSIBLE_FALSE_POSITIVE(@"Hello", nil); // no-warning<br>
+  NSString *string2 = POSSIBLE_FALSE_POSITIVE(@"Hello", @"Hello"); // no-warning<br>
+}<br>
+<br>
+@end<br>
<br>
Added: cfe/trunk/test/Analysis/localization.m<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/localization.m?rev=244389&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/localization.m?rev=244389&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/Analysis/localization.m (added)<br>
+++ cfe/trunk/test/Analysis/localization.m Fri Aug  7 20:49:26 2015<br>
@@ -0,0 +1,86 @@<br>
+// RUN: %clang_cc1 -analyze -fblocks -analyzer-store=region -analyzer-checker=alpha.osx.cocoa.NonLocalizedStringChecker -analyzer-checker=alpha.osx.cocoa.EmptyLocalizationContextChecker -verify  %s<br>
+<br>
+// The larger set of tests in located in localization.m. These are tests<br>
+// specific for non-aggressive reporting.<br>
+<br>
+// These declarations were reduced using Delta-Debugging from Foundation.h<br>
+// on Mac OS X.<br>
+<br>
+#define nil ((id)0)<br>
+#define NSLocalizedString(key, comment)                                        \<br>
+  [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil]<br>
+#define NSLocalizedStringFromTable(key, tbl, comment)                          \<br>
+  [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:(tbl)]<br>
+#define NSLocalizedStringFromTableInBundle(key, tbl, bundle, comment)          \<br>
+  [bundle localizedStringForKey:(key) value:@"" table:(tbl)]<br>
+#define NSLocalizedStringWithDefaultValue(key, tbl, bundle, val, comment)      \<br>
+  [bundle localizedStringForKey:(key) value:(val) table:(tbl)]<br>
+@interface NSObject<br>
++ (id)alloc;<br>
+- (id)init;<br>
+@end<br>
+@interface NSString : NSObject<br>
+@end<br>
+@interface NSBundle : NSObject<br>
++ (NSBundle *)mainBundle;<br>
+- (NSString *)localizedStringForKey:(NSString *)key<br>
+                              value:(NSString *)value<br>
+                              table:(NSString *)tableName;<br>
+@end<br>
+@interface UILabel : NSObject<br>
+@property(nullable, nonatomic, copy) NSString *text;<br>
+@end<br>
+@interface TestObject : NSObject<br>
+@property(strong) NSString *text;<br>
+@end<br>
+<br>
+@interface LocalizationTestSuite : NSObject<br>
+int random();<br>
+@end<br>
+<br>
+// Test cases begin here<br>
+@implementation LocalizationTestSuite<br>
+<br>
+// An object passed in as an parameter's string member<br>
+// should not be considered unlocalized<br>
+- (void)testObjectAsArgument:(TestObject *)argumentObject {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+<br>
+  [testLabel setText:[argumentObject text]]; // no-warning<br>
+  [testLabel setText:argumentObject.text];   // no-warning<br>
+}<br>
+<br>
+- (void)testLocalizationErrorDetectedOnPathway {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  NSString *bar = NSLocalizedString(@"Hello", @"Comment");<br>
+<br>
+  if (random()) {<br>
+    bar = @"Unlocalized string";<br>
+  }<br>
+<br>
+  [testLabel setText:bar]; // expected-warning {{String should be localized}}<br>
+}<br>
+<br>
+- (void)testOneCharacterStringsDoNotGiveAWarning {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  NSString *bar = NSLocalizedString(@"Hello", @"Comment");<br>
+<br>
+  if (random()) {<br>
+    bar = @"-";<br>
+  }<br>
+<br>
+  [testLabel setText:bar]; // no-warning<br>
+}<br>
+<br>
+- (void)testOneCharacterUTFStringsDoNotGiveAWarning {<br>
+  UILabel *testLabel = [[UILabel alloc] init];<br>
+  NSString *bar = NSLocalizedString(@"Hello", @"Comment");<br>
+<br>
+  if (random()) {<br>
+    bar = @"—";<br>
+  }<br>
+<br>
+  [testLabel setText:bar]; // no-warning<br>
+}<br>
+<br>
+@end<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><br>
</blockquote></div>
</div></blockquote></div></div></div></blockquote></div>