diff options
author | Richard Trieu <rtrieu@google.com> | 2016-12-06 01:42:28 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2016-12-06 01:42:28 +0000 |
commit | a7f30b1af127dbbd95a33518437fd36a8bb07796 (patch) | |
tree | fda49c70ea765a40d10c9de5a245d2dfd4c7a9fe /clang/lib/Sema/SemaChecking.cpp | |
parent | 25af0418da702e10041829699b6d1384502b9c70 (diff) | |
download | llvm-a7f30b1af127dbbd95a33518437fd36a8bb07796.zip llvm-a7f30b1af127dbbd95a33518437fd36a8bb07796.tar.gz llvm-a7f30b1af127dbbd95a33518437fd36a8bb07796.tar.bz2 |
Clean up some Sema checking code. NFC
- Rename CheckMinZero to CheckMaxUnsignedZero to reflect its actual purpose.
- Remove unused parameters from CheckAbsoluteValueFunction and
CheckMaxUnsignedZero functions.
- Refactor the function name check so both functions can use the same one.
llvm-svn: 288756
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 56 |
1 files changed, 12 insertions, 44 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index bb68853..fd0654b 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -2517,8 +2517,8 @@ bool Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall, if (!FnInfo) return false; - CheckAbsoluteValueFunction(TheCall, FDecl, FnInfo); - CheckMinZero(TheCall, FDecl, FnInfo); + CheckAbsoluteValueFunction(TheCall, FDecl); + CheckMaxUnsignedZero(TheCall, FDecl); if (getLangOpts().ObjC1) DiagnoseCStringFormatDirectiveInCFAPI(*this, FDecl, Args, NumArgs); @@ -6666,23 +6666,14 @@ static void emitReplacement(Sema &S, SourceLocation Loc, SourceRange Range, << FunctionName; } -static bool IsFunctionStdAbs(const FunctionDecl *FDecl) { +template <std::size_t StrLen> +static bool IsStdFunction(const FunctionDecl *FDecl, + const char (&Str)[StrLen]) { if (!FDecl) return false; - - if (!FDecl->getIdentifier() || !FDecl->getIdentifier()->isStr("abs")) + if (!FDecl->getIdentifier() || !FDecl->getIdentifier()->isStr(Str)) return false; - - const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(FDecl->getDeclContext()); - - while (ND && ND->isInlineNamespace()) { - ND = dyn_cast<NamespaceDecl>(ND->getDeclContext()); - } - - if (!ND || !ND->getIdentifier() || !ND->getIdentifier()->isStr("std")) - return false; - - if (!isa<TranslationUnitDecl>(ND->getDeclContext())) + if (!FDecl->isInStdNamespace()) return false; return true; @@ -6690,13 +6681,12 @@ static bool IsFunctionStdAbs(const FunctionDecl *FDecl) { // Warn when using the wrong abs() function. void Sema::CheckAbsoluteValueFunction(const CallExpr *Call, - const FunctionDecl *FDecl, - IdentifierInfo *FnInfo) { + const FunctionDecl *FDecl) { if (Call->getNumArgs() != 1) return; unsigned AbsKind = getAbsoluteValueFunctionKind(FDecl); - bool IsStdAbs = IsFunctionStdAbs(FDecl); + bool IsStdAbs = IsStdFunction(FDecl, "abs"); if (AbsKind == 0 && !IsStdAbs) return; @@ -6770,30 +6760,8 @@ void Sema::CheckAbsoluteValueFunction(const CallExpr *Call, } //===--- CHECK: Warn on use of std::max and unsigned zero. r---------------===// -static bool IsFunctionStdMax(const FunctionDecl *FDecl) { - if (!FDecl) - return false; - - if (!FDecl->getIdentifier() || !FDecl->getIdentifier()->isStr("max")) - return false; - - const NamespaceDecl *ND = dyn_cast<NamespaceDecl>(FDecl->getDeclContext()); - - while (ND && ND->isInlineNamespace()) { - ND = dyn_cast<NamespaceDecl>(ND->getDeclContext()); - } - - if (!ND || !ND->getIdentifier() || !ND->getIdentifier()->isStr("std")) - return false; - - if (!isa<TranslationUnitDecl>(ND->getDeclContext())) - return false; - - return true; -} - -void Sema::CheckMinZero(const CallExpr *Call, const FunctionDecl *FDecl, - IdentifierInfo *FnInfo) { +void Sema::CheckMaxUnsignedZero(const CallExpr *Call, + const FunctionDecl *FDecl) { if (!Call || !FDecl) return; // Ignore template specializations and macros. @@ -6802,7 +6770,7 @@ void Sema::CheckMinZero(const CallExpr *Call, const FunctionDecl *FDecl, // Only care about the one template argument, two function parameter std::max if (Call->getNumArgs() != 2) return; - if (!IsFunctionStdMax(FDecl)) return; + if (!IsStdFunction(FDecl, "max")) return; const auto * ArgList = FDecl->getTemplateSpecializationArgs(); if (!ArgList) return; if (ArgList->size() != 1) return; |