This revision was automatically updated to reflect the committed changes. Closed by commit rL368929: [LifetimeAnalysis] Support std::stack::top() and std::optional::value() (authored by mgehre, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D66164?vs=214954&id=215259#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D66164/new/ https://reviews.llvm.org/D66164 Files: cfe/trunk/lib/Sema/SemaInit.cpp cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp Index: cfe/trunk/lib/Sema/SemaInit.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaInit.cpp +++ cfe/trunk/lib/Sema/SemaInit.cpp @@ -6610,7 +6610,7 @@ OO == OverloadedOperatorKind::OO_Star; } return llvm::StringSwitch<bool>(Callee->getName()) - .Cases("front", "back", "at", true) + .Cases("front", "back", "at", "top", "value", true) .Default(false); } return false; Index: cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp =================================================================== --- cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp +++ cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp @@ -170,7 +170,15 @@ struct optional { optional(); optional(const T&); - T &operator*(); + T &operator*() &; + T &&operator*() &&; + T &value() &; + T &&value() &&; +}; + +template<typename T> +struct stack { + T &top(); }; } @@ -188,6 +196,16 @@ return s.c_str(); // expected-warning {{address of stack memory associated with local variable 's' returned}} } +int &danglingRawPtrFromLocal2() { + std::optional<int> o; + return o.value(); // expected-warning {{reference to stack memory associated with local variable 'o' returned}} +} + +int &danglingRawPtrFromLocal3() { + std::optional<int> o; + return *o; // expected-warning {{reference to stack memory associated with local variable 'o' returned}} +} + const char *danglingRawPtrFromTemp() { return std::basic_string<char>().c_str(); // expected-warning {{returning address of local temporary object}} } @@ -203,9 +221,10 @@ } void danglingReferenceFromTempOwner() { - int &r = *std::optional<int>(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} - int &r2 = *std::optional<int>(5); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} - int &r3 = std::vector<int>().at(3); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} + int &&r = *std::optional<int>(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} + int &&r2 = *std::optional<int>(5); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} + int &&r3 = std::optional<int>(5).value(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} + int &r4 = std::vector<int>().at(3); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} } std::vector<int> getTempVec();
Index: cfe/trunk/lib/Sema/SemaInit.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaInit.cpp +++ cfe/trunk/lib/Sema/SemaInit.cpp @@ -6610,7 +6610,7 @@ OO == OverloadedOperatorKind::OO_Star; } return llvm::StringSwitch<bool>(Callee->getName()) - .Cases("front", "back", "at", true) + .Cases("front", "back", "at", "top", "value", true) .Default(false); } return false; Index: cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp =================================================================== --- cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp +++ cfe/trunk/test/Sema/warn-lifetime-analysis-nocfg.cpp @@ -170,7 +170,15 @@ struct optional { optional(); optional(const T&); - T &operator*(); + T &operator*() &; + T &&operator*() &&; + T &value() &; + T &&value() &&; +}; + +template<typename T> +struct stack { + T &top(); }; } @@ -188,6 +196,16 @@ return s.c_str(); // expected-warning {{address of stack memory associated with local variable 's' returned}} } +int &danglingRawPtrFromLocal2() { + std::optional<int> o; + return o.value(); // expected-warning {{reference to stack memory associated with local variable 'o' returned}} +} + +int &danglingRawPtrFromLocal3() { + std::optional<int> o; + return *o; // expected-warning {{reference to stack memory associated with local variable 'o' returned}} +} + const char *danglingRawPtrFromTemp() { return std::basic_string<char>().c_str(); // expected-warning {{returning address of local temporary object}} } @@ -203,9 +221,10 @@ } void danglingReferenceFromTempOwner() { - int &r = *std::optional<int>(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} - int &r2 = *std::optional<int>(5); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} - int &r3 = std::vector<int>().at(3); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} + int &&r = *std::optional<int>(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} + int &&r2 = *std::optional<int>(5); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} + int &&r3 = std::optional<int>(5).value(); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} + int &r4 = std::vector<int>().at(3); // expected-warning {{object backing the pointer will be destroyed at the end of the full-expression}} } std::vector<int> getTempVec();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits