summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
diff options
context:
space:
mode:
authorDevin Coughlin <dcoughlin@apple.com>2016-02-05 04:22:15 +0000
committerDevin Coughlin <dcoughlin@apple.com>2016-02-05 04:22:15 +0000
commit084e363517fc2248412f227862cdabd2f439e83d (patch)
tree0f484f8cb46289dfece0d2e114dd507c75dde9b0 /clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
parentd0807aee51b7a19a58d8b4c2044bc17a5fddf545 (diff)
downloadbcm5719-llvm-084e363517fc2248412f227862cdabd2f439e83d.tar.gz
bcm5719-llvm-084e363517fc2248412f227862cdabd2f439e83d.zip
[analyzer] Suppress localization diagnostics in debug classes and methods.
If the class or method name case-insensitively contains the term "debug", suppress warnings about string constants flowing to user-facing UI APIs. llvm-svn: 259875
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
index 56346cd4f70..504b8b30187 100644
--- a/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
@@ -619,11 +619,46 @@ void NonLocalizedStringChecker::setNonLocalizedState(const SVal S,
}
}
+
+static bool isDebuggingName(std::string name) {
+ return StringRef(name).lower().find("debug") != StringRef::npos;
+}
+
+/// Returns true when, heuristically, the analyzer may be analyzing debugging
+/// code. We use this to suppress localization diagnostics in un-localized user
+/// interfaces that are only used for debugging and are therefore not user
+/// facing.
+static bool isDebuggingContext(CheckerContext &C) {
+ const Decl *D = C.getCurrentAnalysisDeclContext()->getDecl();
+ if (!D)
+ return false;
+
+ if (auto *ND = dyn_cast<NamedDecl>(D)) {
+ if (isDebuggingName(ND->getNameAsString()))
+ return true;
+ }
+
+ const DeclContext *DC = D->getDeclContext();
+
+ if (auto *CD = dyn_cast<ObjCContainerDecl>(DC)) {
+ if (isDebuggingName(CD->getNameAsString()))
+ return true;
+ }
+
+ return false;
+}
+
+
/// Reports a localization error for the passed in method call and SVal
void NonLocalizedStringChecker::reportLocalizationError(
SVal S, const ObjCMethodCall &M, CheckerContext &C,
int argumentNumber) const {
+ // Don't warn about localization errors in classes and methods that
+ // may be debug code.
+ if (isDebuggingContext(C))
+ return;
+
ExplodedNode *ErrNode = C.getPredecessor();
static CheckerProgramPointTag Tag("NonLocalizedStringChecker",
"UnlocalizedString");
OpenPOWER on IntegriCloud