diff options
author | Gabor Horvath <xazax.hun@gmail.com> | 2019-08-09 17:11:32 +0000 |
---|---|---|
committer | Gabor Horvath <xazax.hun@gmail.com> | 2019-08-09 17:11:32 +0000 |
commit | 7c3c8ba8daf40534e09f6fe8701b723e25e4e2dc (patch) | |
tree | db82984ec19e7467e0f2c5b06c397f73371ca303 /clang/lib/Sema/SemaInit.cpp | |
parent | 8a2121417486f6d58ad6f5e459028c1644678141 (diff) | |
download | bcm5719-llvm-7c3c8ba8daf40534e09f6fe8701b723e25e4e2dc.tar.gz bcm5719-llvm-7c3c8ba8daf40534e09f6fe8701b723e25e4e2dc.zip |
Even more warnings utilizing gsl::Owner/gsl::Pointer annotations
Differential Revision: https://reviews.llvm.org/D65127
llvm-svn: 368454
Diffstat (limited to 'clang/lib/Sema/SemaInit.cpp')
-rw-r--r-- | clang/lib/Sema/SemaInit.cpp | 38 |
1 files changed, 29 insertions, 9 deletions
diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index 44504971d8f..dfc12e91a65 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -6568,19 +6568,33 @@ static bool shouldTrackImplicitObjectArg(const CXXMethodDecl *Callee) { if (auto *Conv = dyn_cast_or_null<CXXConversionDecl>(Callee)) if (isRecordWithAttr<PointerAttr>(Conv->getConversionType())) return true; - if (!Callee->getParent()->isInStdNamespace() || !Callee->getIdentifier()) + if (!Callee->getParent()->isInStdNamespace()) return false; if (!isRecordWithAttr<PointerAttr>(Callee->getThisObjectType()) && !isRecordWithAttr<OwnerAttr>(Callee->getThisObjectType())) return false; - if (!isRecordWithAttr<PointerAttr>(Callee->getReturnType()) && - !Callee->getReturnType()->isPointerType()) - return false; - return llvm::StringSwitch<bool>(Callee->getName()) - .Cases("begin", "rbegin", "cbegin", "crbegin", true) - .Cases("end", "rend", "cend", "crend", true) - .Cases("c_str", "data", "get", true) - .Default(false); + if (Callee->getReturnType()->isPointerType() || + isRecordWithAttr<PointerAttr>(Callee->getReturnType())) { + if (!Callee->getIdentifier()) + return false; + return llvm::StringSwitch<bool>(Callee->getName()) + .Cases("begin", "rbegin", "cbegin", "crbegin", true) + .Cases("end", "rend", "cend", "crend", true) + .Cases("c_str", "data", "get", true) + // Map and set types. + .Cases("find", "equal_range", "lower_bound", "upper_bound", true) + .Default(false); + } else if (Callee->getReturnType()->isReferenceType()) { + if (!Callee->getIdentifier()) { + auto OO = Callee->getOverloadedOperator(); + return OO == OverloadedOperatorKind::OO_Subscript || + OO == OverloadedOperatorKind::OO_Star; + } + return llvm::StringSwitch<bool>(Callee->getName()) + .Cases("front", "back", "at", true) + .Default(false); + } + return false; } static void handleGslAnnotatedTypes(IndirectLocalPath &Path, Expr *Call, @@ -6600,6 +6614,12 @@ static void handleGslAnnotatedTypes(IndirectLocalPath &Path, Expr *Call, if (MD && shouldTrackImplicitObjectArg(MD)) VisitPointerArg(MD, MCE->getImplicitObjectArgument()); return; + } else if (auto *OCE = dyn_cast<CXXOperatorCallExpr>(Call)) { + FunctionDecl *Callee = OCE->getDirectCallee(); + if (Callee->isCXXInstanceMember() && + shouldTrackImplicitObjectArg(cast<CXXMethodDecl>(Callee))) + VisitPointerArg(Callee, OCE->getArg(0)); + return; } if (auto *CCE = dyn_cast<CXXConstructExpr>(Call)) { |