llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-analysis Author: None (martinboehme) <details> <summary>Changes</summary> This occurs in rewritten candidates for binary operators (a C++20 feature). The patch modifies UncheckedOptionalAccessModelTest to run in C++20 mode (as well as C++17 mode, as before) and to use rewritten candidates. The modified test fails without the newly added support for `CXXRewrittenBinaryOperator`. --- Full diff: https://github.com/llvm/llvm-project/pull/81086.diff 2 Files Affected: - (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+4) - (modified) clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp (+15-1) ``````````diff diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp index bb3aec763c29ca..a098471d0ee905 100644 --- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp +++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp @@ -545,6 +545,10 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> { VisitCallExpr(S); } + void VisitCXXRewrittenBinaryOperator(const CXXRewrittenBinaryOperator *RBO) { + propagateValue(*RBO->getSemanticForm(), *RBO, Env); + } + void VisitCXXFunctionalCastExpr(const CXXFunctionalCastExpr *S) { if (S->getCastKind() == CK_ConstructorConversion) { const Expr *SubExpr = S->getSubExpr(); diff --git a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp index 73fb4063d92be9..b6e4973fd7cb2b 100644 --- a/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp +++ b/clang/unittests/Analysis/FlowSensitive/UncheckedOptionalAccessModelTest.cpp @@ -770,12 +770,17 @@ constexpr bool operator!=(const optional<T> &lhs, const optional<U> &rhs); template <typename T> constexpr bool operator==(const optional<T> &opt, nullopt_t); + +// C++20 and later do not define the following overloads because they are +// provided by rewritten candidates instead. +#if __cplusplus < 202002L template <typename T> constexpr bool operator==(nullopt_t, const optional<T> &opt); template <typename T> constexpr bool operator!=(const optional<T> &opt, nullopt_t); template <typename T> constexpr bool operator!=(nullopt_t, const optional<T> &opt); +#endif // __cplusplus < 202002L template <typename T, typename U> constexpr bool operator==(const optional<T> &opt, const U &value); @@ -1289,6 +1294,15 @@ class UncheckedOptionalAccessTest template <typename FuncDeclMatcher> void ExpectDiagnosticsFor(std::string SourceCode, FuncDeclMatcher FuncMatcher) { + // Run in C++17 and C++20 mode to cover differences in the AST between modes + // (e.g. C++20 can contain `CXXRewrittenBinaryOperator`). + for (const char *CxxMode : {"-std=c++17", "-std=c++20"}) + ExpectDiagnosticsFor(SourceCode, FuncMatcher, CxxMode); + } + + template <typename FuncDeclMatcher> + void ExpectDiagnosticsFor(std::string SourceCode, FuncDeclMatcher FuncMatcher, + const char *CxxMode) { ReplaceAllOccurrences(SourceCode, "$ns", GetParam().NamespaceName); ReplaceAllOccurrences(SourceCode, "$optional", GetParam().TypeName); @@ -1332,7 +1346,7 @@ class UncheckedOptionalAccessTest llvm::move(EltDiagnostics, std::back_inserter(Diagnostics)); }) .withASTBuildArgs( - {"-fsyntax-only", "-std=c++17", "-Wno-undefined-inline"}) + {"-fsyntax-only", CxxMode, "-Wno-undefined-inline"}) .withASTBuildVirtualMappedFiles( tooling::FileContentMappings(Headers.begin(), Headers.end())), /*VerifyResults=*/[&Diagnostics]( `````````` </details> https://github.com/llvm/llvm-project/pull/81086 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits