forked from OSchip/llvm-project
[Sema, StaticAnalyzer] Use StringRef::contains (NFC)
This commit is contained in:
parent
fe1f0de003
commit
0abb5d293c
|
@ -9773,8 +9773,7 @@ static void CheckFormatString(Sema &S, const FormatStringLiteral *FExpr,
|
|||
|
||||
// Emit a warning if the string literal is truncated and does not contain an
|
||||
// embedded null character.
|
||||
if (TypeSize <= StrRef.size() &&
|
||||
StrRef.substr(0, TypeSize).find('\0') == StringRef::npos) {
|
||||
if (TypeSize <= StrRef.size() && !StrRef.substr(0, TypeSize).contains('\0')) {
|
||||
CheckFormatHandler::EmitFormatDiagnostic(
|
||||
S, inFunctionCall, Args[format_idx],
|
||||
S.PDiag(diag::warn_printf_format_string_not_null_terminated),
|
||||
|
|
|
@ -3213,13 +3213,13 @@ static void handleCodeSegAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
|
|||
bool Sema::checkTargetAttr(SourceLocation LiteralLoc, StringRef AttrStr) {
|
||||
enum FirstParam { Unsupported, Duplicate, Unknown };
|
||||
enum SecondParam { None, Architecture, Tune };
|
||||
if (AttrStr.find("fpmath=") != StringRef::npos)
|
||||
if (AttrStr.contains("fpmath="))
|
||||
return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
|
||||
<< Unsupported << None << "fpmath=";
|
||||
|
||||
// Diagnose use of tune if target doesn't support it.
|
||||
if (!Context.getTargetInfo().supportsTargetAttributeTune() &&
|
||||
AttrStr.find("tune=") != StringRef::npos)
|
||||
AttrStr.contains("tune="))
|
||||
return Diag(LiteralLoc, diag::warn_unsupported_target_attribute)
|
||||
<< Unsupported << None << "tune=";
|
||||
|
||||
|
@ -7570,7 +7570,7 @@ static void handleOpenCLAccessAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
|
|||
// C++ for OpenCL 2021 inherits rule from OpenCL C v3.0.
|
||||
if (const auto *PDecl = dyn_cast<ParmVarDecl>(D)) {
|
||||
const Type *DeclTy = PDecl->getType().getCanonicalType().getTypePtr();
|
||||
if (AL.getAttrName()->getName().find("read_write") != StringRef::npos) {
|
||||
if (AL.getAttrName()->getName().contains("read_write")) {
|
||||
bool ReadWriteImagesUnsupported =
|
||||
(S.getLangOpts().getOpenCLCompatibleVersion() < 200) ||
|
||||
(S.getLangOpts().getOpenCLCompatibleVersion() == 300 &&
|
||||
|
|
|
@ -12434,8 +12434,7 @@ static void diagnoseXorMisusedAsPow(Sema &S, const ExprResult &XorLHS,
|
|||
RHSStrRef.startswith("0x") || RHSStrRef.startswith("0X") ||
|
||||
(LHSStrRef.size() > 1 && LHSStrRef.startswith("0")) ||
|
||||
(RHSStrRef.size() > 1 && RHSStrRef.startswith("0")) ||
|
||||
LHSStrRef.find('\'') != StringRef::npos ||
|
||||
RHSStrRef.find('\'') != StringRef::npos)
|
||||
LHSStrRef.contains('\'') || RHSStrRef.contains('\''))
|
||||
return;
|
||||
|
||||
bool SuggestXor =
|
||||
|
|
|
@ -785,9 +785,8 @@ void WalkAST::checkDeprecatedOrUnsafeBufferHandling(const CallExpr *CE,
|
|||
// real flow analysis.
|
||||
auto FormatString =
|
||||
dyn_cast<StringLiteral>(CE->getArg(ArgIndex)->IgnoreParenImpCasts());
|
||||
if (FormatString &&
|
||||
FormatString->getString().find("%s") == StringRef::npos &&
|
||||
FormatString->getString().find("%[") == StringRef::npos)
|
||||
if (FormatString && !FormatString->getString().contains("%s") &&
|
||||
!FormatString->getString().contains("%["))
|
||||
BoundsProvided = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,8 +44,8 @@ static bool DefaultMethodFilter(const ObjCMethodDecl *M) {
|
|||
M->getMethodFamily() == OMF_dealloc ||
|
||||
M->getMethodFamily() == OMF_copy ||
|
||||
M->getMethodFamily() == OMF_mutableCopy ||
|
||||
M->getSelector().getNameForSlot(0).find("init") != StringRef::npos ||
|
||||
M->getSelector().getNameForSlot(0).find("Init") != StringRef::npos;
|
||||
M->getSelector().getNameForSlot(0).contains("init") ||
|
||||
M->getSelector().getNameForSlot(0).contains("Init");
|
||||
}
|
||||
|
||||
class DirectIvarAssignment :
|
||||
|
|
|
@ -789,7 +789,7 @@ bool GenericTaintChecker::isStdin(const Expr *E, CheckerContext &C) {
|
|||
// variable named stdin with the proper type.
|
||||
if (const auto *D = dyn_cast_or_null<VarDecl>(DeclReg->getDecl())) {
|
||||
D = D->getCanonicalDecl();
|
||||
if ((D->getName().find("stdin") != StringRef::npos) && D->isExternC()) {
|
||||
if (D->getName().contains("stdin") && D->isExternC()) {
|
||||
const auto *PtrTy = dyn_cast<PointerType>(D->getType().getTypePtr());
|
||||
if (PtrTy && PtrTy->getPointeeType().getCanonicalType() ==
|
||||
C.getASTContext().getFILEType().getCanonicalType())
|
||||
|
@ -816,7 +816,7 @@ static bool getPrintfFormatArgumentNum(const CallEvent &Call,
|
|||
}
|
||||
|
||||
// Or if a function is named setproctitle (this is a heuristic).
|
||||
if (C.getCalleeName(FDecl).find("setproctitle") != StringRef::npos) {
|
||||
if (C.getCalleeName(FDecl).contains("setproctitle")) {
|
||||
ArgNum = 0;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -3195,7 +3195,7 @@ bool MallocChecker::mayFreeAnyEscapedMemoryOrIsModeledExplicitly(
|
|||
const Expr *ArgE = Call->getArgExpr(0)->IgnoreParenCasts();
|
||||
if (const DeclRefExpr *ArgDRE = dyn_cast<DeclRefExpr>(ArgE))
|
||||
if (const VarDecl *D = dyn_cast<VarDecl>(ArgDRE->getDecl()))
|
||||
if (D->getCanonicalDecl()->getName().find("std") != StringRef::npos)
|
||||
if (D->getCanonicalDecl()->getName().contains("std"))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -681,7 +681,7 @@ bool AnyFunctionCall::argumentsMayEscape() const {
|
|||
|
||||
// - NSXXInsertXX, for example NSMapInsertIfAbsent, since they can
|
||||
// be deallocated by NSMapRemove.
|
||||
if (FName.startswith("NS") && (FName.find("Insert") != StringRef::npos))
|
||||
if (FName.startswith("NS") && FName.contains("Insert"))
|
||||
return true;
|
||||
|
||||
// - Many CF containers allow objects to escape through custom
|
||||
|
|
|
@ -55,7 +55,7 @@ bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD,
|
|||
if (Name.empty())
|
||||
return true;
|
||||
StringRef BName = FD->getASTContext().BuiltinInfo.getName(BId);
|
||||
if (BName.find(Name) != StringRef::npos)
|
||||
if (BName.contains(Name))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -83,11 +83,10 @@ bool CheckerContext::isCLibraryFunction(const FunctionDecl *FD,
|
|||
if (FName.equals(Name))
|
||||
return true;
|
||||
|
||||
if (FName.startswith("__inline") && (FName.find(Name) != StringRef::npos))
|
||||
if (FName.startswith("__inline") && FName.contains(Name))
|
||||
return true;
|
||||
|
||||
if (FName.startswith("__") && FName.endswith("_chk") &&
|
||||
FName.find(Name) != StringRef::npos)
|
||||
if (FName.startswith("__") && FName.endswith("_chk") && FName.contains(Name))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
|
@ -976,7 +976,7 @@ const VarRegion *MemRegionManager::getVarRegion(const VarDecl *D,
|
|||
if (Ctx.getSourceManager().isInSystemHeader(D->getLocation())) {
|
||||
// Whitelist the system globals which often DO GET modified, assume the
|
||||
// rest are immutable.
|
||||
if (D->getName().find("errno") != StringRef::npos)
|
||||
if (D->getName().contains("errno"))
|
||||
sReg = getGlobalsRegion(MemRegion::GlobalSystemSpaceRegionKind);
|
||||
else
|
||||
sReg = getGlobalsRegion(MemRegion::GlobalImmutableSpaceRegionKind);
|
||||
|
|
Loading…
Reference in New Issue