llvm-project/clang/unittests
Sam Estep cd0d52610d [clang][dataflow] In `optional` model, match call return via hasType
Currently the unchecked-optional-access model fails on this example:

    #include <memory>
    #include <optional>

    void foo() {
      std::unique_ptr<std::optional<float>> x;
      *x = std::nullopt;
    }

You can verify the failure by saving the file as `foo.cpp` and running this command:

    clang-tidy -checks='-*,bugprone-unchecked-optional-access' foo.cpp -- -std=c++17

The failing `assert` is in the `transferAssignment` function of the `UncheckedOptionalAccessModel.cpp` file:

    assert(OptionalLoc != nullptr);

The symptom can be treated by replacing that `assert` with an early `return`:

    if (OptionalLoc == nullptr)
      return;

That would be better anyway since we cannot expect to always cover all possible LHS expressions, but it is out of scope for this patch and left as a followup.

Note that the failure did not occur on this very similar example:

    #include <optional>

    template <typename T>
    struct smart_ptr {
      T& operator*() &;
      T* operator->();
    };

    void foo() {
      smart_ptr<std::optional<float>> x;
      *x = std::nullopt;
    }

The difference is caused by the `isCallReturningOptional` matcher, which was previously checking the `functionDecl` of the `callee`. This patch changes it to instead use `hasType` directly on the call expression, fixing the failure for the `std::unique_ptr` example above.

Reviewed By: sgatev

Differential Revision: https://reviews.llvm.org/D127434
2022-06-10 14:52:05 +00:00
..
AST [clang][ASTImporter] Fix import of function with auto return type. 2022-06-10 10:18:53 +02:00
ASTMatchers Revert "Drop qualifiers from return types in C (DR423)" 2022-06-02 08:28:43 -04:00
Analysis [clang][dataflow] In `optional` model, match call return via hasType 2022-06-10 14:52:05 +00:00
Basic Fix a buglet in remove_dots(). 2022-06-02 11:07:44 -07:00
CodeGen Use the public clang::Builtin API in the unit test 2022-05-20 18:09:09 +02:00
CrossTU [analyzer][ctu] Fix wrong 'multiple definitions' errors caused by space characters in lookup names when parsing the ctu index file 2022-03-22 10:28:42 +08:00
DirectoryWatcher Revert "Re-Revert "DirectoryWatcher: add an implementation for Windows"" 2021-06-19 09:19:52 -07:00
Driver [clang][tests] Add missing compiler name 2022-06-09 15:11:40 +02:00
Format [clang-format][NFC] Format lib/Format and unittests/Format in clang 2022-06-09 02:25:06 -07:00
Frontend Fix a buglet in remove_dots(). 2022-06-02 11:07:44 -07:00
Index [clang] Visit enum base specifiers in libIndex 2021-10-25 13:16:14 +02:00
Interpreter [clang-repl][NFC] Fix calling convention mismatch in test 2021-11-30 13:26:10 -08:00
Introspection Revert "[llvm][clang][bolt][NFC] Use llvm::less_first() when applicable" 2022-05-27 11:19:18 +02:00
Lex [Tooling/DependencyScanning & Preprocessor] Refactor dependency scanning to produce pre-lexed preprocessor directive tokens, instead of minimized sources 2022-05-26 12:50:06 -07:00
Rename Bump googletest to 1.10.0 2021-05-14 19:16:31 +02:00
Rewrite
Sema [Testing] Drop clangTesting from clang's public library interface 2022-04-20 13:28:44 +02:00
Serialization [Serialization] Add missing includes for CHAR_BIT 2022-05-19 10:04:25 +02:00
StaticAnalyzer [Testing] Drop clangTesting from clang's public library interface 2022-04-20 13:28:44 +02:00
Tooling [PS5] Add PS5OSTargetInfo class, update affected tests 2022-06-01 13:30:29 -07:00
libclang [libclang] Add CXRewriter to libclang API 2020-09-04 14:17:03 -07:00
CMakeLists.txt [clang-repl] Recommit "Land initial infrastructure for incremental parsing" 2021-05-13 06:30:29 +00:00