From: Gabor Horvath Date: Fri, 9 Aug 2019 19:01:23 +0000 (+0000) Subject: Revert Even more warnings utilizing gsl::Owner/gsl::Pointer annotations X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=14c49f8d7710c0006511d438f94628ea579672a7;p=clang Revert Even more warnings utilizing gsl::Owner/gsl::Pointer annotations This reverts r368454 (git commit 7c3c8ba8daf40534e09f6fe8701b723e25e4e2dc) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@368463 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index dfc12e91a6..44504971d8 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -6568,33 +6568,19 @@ static bool shouldTrackImplicitObjectArg(const CXXMethodDecl *Callee) { if (auto *Conv = dyn_cast_or_null(Callee)) if (isRecordWithAttr(Conv->getConversionType())) return true; - if (!Callee->getParent()->isInStdNamespace()) + if (!Callee->getParent()->isInStdNamespace() || !Callee->getIdentifier()) return false; if (!isRecordWithAttr(Callee->getThisObjectType()) && !isRecordWithAttr(Callee->getThisObjectType())) return false; - if (Callee->getReturnType()->isPointerType() || - isRecordWithAttr(Callee->getReturnType())) { - if (!Callee->getIdentifier()) - return false; - return llvm::StringSwitch(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(Callee->getName()) - .Cases("front", "back", "at", true) - .Default(false); - } - return false; + if (!isRecordWithAttr(Callee->getReturnType()) && + !Callee->getReturnType()->isPointerType()) + return false; + return llvm::StringSwitch(Callee->getName()) + .Cases("begin", "rbegin", "cbegin", "crbegin", true) + .Cases("end", "rend", "cend", "crend", true) + .Cases("c_str", "data", "get", true) + .Default(false); } static void handleGslAnnotatedTypes(IndirectLocalPath &Path, Expr *Call, @@ -6614,12 +6600,6 @@ static void handleGslAnnotatedTypes(IndirectLocalPath &Path, Expr *Call, if (MD && shouldTrackImplicitObjectArg(MD)) VisitPointerArg(MD, MCE->getImplicitObjectArgument()); return; - } else if (auto *OCE = dyn_cast(Call)) { - FunctionDecl *Callee = OCE->getDirectCallee(); - if (Callee->isCXXInstanceMember() && - shouldTrackImplicitObjectArg(cast(Callee))) - VisitPointerArg(Callee, OCE->getArg(0)); - return; } if (auto *CCE = dyn_cast(Call)) { diff --git a/test/Sema/warn-lifetime-analysis-nocfg.cpp b/test/Sema/warn-lifetime-analysis-nocfg.cpp index efa54fe662..89cf39a9ca 100644 --- a/test/Sema/warn-lifetime-analysis-nocfg.cpp +++ b/test/Sema/warn-lifetime-analysis-nocfg.cpp @@ -121,47 +121,24 @@ void initLocalGslPtrWithTempOwner() { namespace std { template -struct basic_iterator { - basic_iterator operator++(); - T& operator*(); -}; - -template -bool operator!=(basic_iterator, basic_iterator); +struct basic_iterator {}; template struct vector { typedef basic_iterator iterator; iterator begin(); - iterator end(); T *data(); - T &at(int n); -}; - -template -struct basic_string_view { - basic_string_view(const T *); - const T *begin() const; }; template struct basic_string { const T *c_str() const; - operator basic_string_view () const; }; - template struct unique_ptr { T *get() const; }; - -template -struct optional { - optional(); - optional(const T&); - T &operator*(); -}; } void modelIterators() { @@ -191,29 +168,3 @@ int *danglingUniquePtrFromTemp() { int *danglingUniquePtrFromTemp2() { return std::unique_ptr().get(); // expected-warning {{returning address of local temporary object}} } - -void danglingReferenceFromTempOwner() { - int &r = *std::optional(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} - int &r2 = *std::optional(5); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} - int &r3 = std::vector().at(3); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} -} - -std::vector getTempVec(); -std::optional> getTempOptVec(); - -int &usedToBeFalsePositive(std::vector &v) { - std::vector::iterator it = v.begin(); - int& value = *it; - return value; // ok -} - -int &doNotFollowReferencesForLocalOwner() { - std::unique_ptr localOwner; - int &p = *localOwner.get(); - // In real world code localOwner is usually moved here. - return p; // ok -} - -const char *trackThroughMultiplePointer() { - return std::basic_string_view(std::basic_string()).begin(); // expected-warning {{returning address of local temporary object}} -}