summaryrefslogtreecommitdiff
path: root/clang/test/Analysis/inner-pointer.cpp
AgeCommit message (Collapse)Author
2022-05-03[analyzer] Check for std::__addressof for inner pointer checkerAli Shuja Siddiqui
This is an extension to diff D99260. This adds an additional exception for `std::__addressof` in `InnerPointerChecker`. Patch By alishuja (Ali Shuja Siddiqui)! Reviewed By: martong, alishuja Differential Revision: https://reviews.llvm.org/D109467
2022-04-20Treat `std::move`, `forward`, etc. as builtins.Richard Smith
This is extended to all `std::` functions that take a reference to a value and return a reference (or pointer) to that same value: `move`, `forward`, `move_if_noexcept`, `as_const`, `addressof`, and the libstdc++-specific function `__addressof`. We still require these functions to be declared before they can be used, but don't instantiate their definitions unless their addresses are taken. Instead, code generation, constant evaluation, and static analysis are given direct knowledge of their effect. This change aims to reduce various costs associated with these functions -- per-instantiation memory costs, compile time and memory costs due to creating out-of-line copies and inlining them, code size at -O0, and so on -- so that they are not substantially more expensive than a cast. Most of these improvements are very small, but I measured a 3% decrease in -O0 object file size for a simple C++ source file using the standard library after this change. We now automatically infer the `const` and `nothrow` attributes on these now-builtin functions, in particular meaning that we get a warning for an unused call to one of these functions. In C++20 onwards, we disallow taking the addresses of these functions, per the C++20 "addressable function" rule. In earlier language modes, a compatibility warning is produced but the address can still be taken. The same infrastructure is extended to the existing MSVC builtin `__GetExceptionInfo`, which is now only recognized in namespace `std` like it always should have been. This is a re-commit of fc3090109643af8d2da9822d0f99c84742b9c877, a571f82a50416b767fd3cce0fb5027bb5dfec58c, 64c045e25b8471bbb572bd29159c294a82a86a2, and de6ddaeef3aaa8a9ae3663c12cdb57d9afc0f906, and reverts aa643f455a5362de7189eac630050d2c8aefe8f2. This change also includes a workaround for users using libc++ 3.1 and earlier (!!), as apparently happens on AIX, where std::move sometimes returns by value. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D123345 Revert "Fixup D123950 to address revert of D123345" This reverts commit aa643f455a5362de7189eac630050d2c8aefe8f2.
2022-04-20Revert "Treat `std::move`, `forward`, etc. as builtins."David Tenty
This reverts commit b27430f9f46b88bcd54d992debc8d72e131e1bd0 as the parent https://reviews.llvm.org/D123345 breaks the AIX CI: https://lab.llvm.org/buildbot/#/builders/214/builds/819
2022-04-17Treat `std::move`, `forward`, etc. as builtins.Richard Smith
This is extended to all `std::` functions that take a reference to a value and return a reference (or pointer) to that same value: `move`, `forward`, `move_if_noexcept`, `as_const`, `addressof`, and the libstdc++-specific function `__addressof`. We still require these functions to be declared before they can be used, but don't instantiate their definitions unless their addresses are taken. Instead, code generation, constant evaluation, and static analysis are given direct knowledge of their effect. This change aims to reduce various costs associated with these functions -- per-instantiation memory costs, compile time and memory costs due to creating out-of-line copies and inlining them, code size at -O0, and so on -- so that they are not substantially more expensive than a cast. Most of these improvements are very small, but I measured a 3% decrease in -O0 object file size for a simple C++ source file using the standard library after this change. We now automatically infer the `const` and `nothrow` attributes on these now-builtin functions, in particular meaning that we get a warning for an unused call to one of these functions. In C++20 onwards, we disallow taking the addresses of these functions, per the C++20 "addressable function" rule. In earlier language modes, a compatibility warning is produced but the address can still be taken. The same infrastructure is extended to the existing MSVC builtin `__GetExceptionInfo`, which is now only recognized in namespace `std` like it always should have been. This is a re-commit of fc3090109643af8d2da9822d0f99c84742b9c877, a571f82a50416b767fd3cce0fb5027bb5dfec58c, and 64c045e25b8471bbb572bd29159c294a82a86a25 which were reverted in e75d8b70370435b0ad10388afba0df45fcf9bfcc due to a crasher bug where CodeGen would emit a builtin glvalue as an rvalue if it constant-folds. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D123345
2022-04-16Revert "Treat `std::move`, `forward`, and `move_if_noexcept` as builtins."Vitaly Buka
Revert "Extend support for std::move etc to also cover std::as_const and" Revert "Update test to handle opaque pointers flag flip." It crashes on libcxx tests https://lab.llvm.org/buildbot/#/builders/85/builds/8174 This reverts commit fc3090109643af8d2da9822d0f99c84742b9c877. This reverts commit a571f82a50416b767fd3cce0fb5027bb5dfec58c. This reverts commit 64c045e25b8471bbb572bd29159c294a82a86a25.
2022-04-15Extend support for std::move etc to also cover std::as_const andRichard Smith
std::addressof, plus the libstdc++-specific std::__addressof. This brings us to parity with the corresponding GCC behavior. Remove STDBUILTIN macro that ended up not being used.
2021-04-08[analyzer] Fix false positives in inner pointer checker (PR49628)Valeriy Savchenko
This patch supports std::data and std::addressof functions. rdar://73463300 Differential Revision: https://reviews.llvm.org/D99260
2019-10-19[analyzer] Specify the C++ standard in more tests.Artem Dergachev
Makes life easier for downstream developers with different default standard. llvm-svn: 375308
2019-08-09More warnings regarding gsl::Pointer and gsl::Owner attributesGabor Horvath
Differential Revision: https://reviews.llvm.org/D65120 llvm-svn: 368446
2019-05-29[analyzer] ConditionBRVisitor: Boolean supportCsaba Dabis
Summary: - Reviewers: NoQ, george.karpenkov Reviewed By: NoQ, george.karpenkov Subscribers: cfe-commits, xazax.hun, baloghadamsoftware, szepet, a.sidorin, mikhail.ramalho, Szelethus, donat.nagy, dkrupp Tags: #clang Differential Revision: https://reviews.llvm.org/D58207 llvm-svn: 362027
2018-11-02[analyzer] Put llvm.Conventions back in alphaKristof Umann
Interestingly, this many year old (when I last looked I remember 2010ish) checker was committed without any tests, so I thought I'd implement them, but I was shocked to see how I barely managed to get it working. The code is severely outdated, I'm not even sure it has ever been used, so I'd propose to move it back into alpha, and possibly even remove it. Differential Revision: https://reviews.llvm.org/D53856 llvm-svn: 345990
2018-09-21[analyzer] Associate diagnostics created in checkEndFunction with a return ↵George Karpenkov
statement, if possible If not possible, use the last line of the declaration, as before. Differential Revision: https://reviews.llvm.org/D52326 llvm-svn: 342768
2018-08-30[analyzer] InnerPointerChecker: Fix a segfault when checking symbolic strings.Artem Dergachev
Return value of dyn_cast_or_null should be checked before use. Otherwise we may put a null pointer into the map as a key and eventually crash in checkDeadSymbols. Differential Revision: https://reviews.llvm.org/D51385 llvm-svn: 341092
2018-08-10[analyzer] InnerPointerChecker: improve warning messages and notes.Reka Kovacs
Differential Revision: https://reviews.llvm.org/D49570 llvm-svn: 339489
2018-08-03[analyzer] Add test for a crash fixed in r338775.Reka Kovacs
Do not crash if a CXXRecordDecl cannot be obtained for an object. Special thanks for the reproduction to Alexander Kornienko. llvm-svn: 338918
2018-08-02[analyzer] Detect pointers escaped after ReturnStmt execution in MallocChecker.Reka Kovacs
Objects local to a function are destroyed right after the statement returning (part of) them is executed in the analyzer. This patch enables MallocChecker to warn in these cases. Differential Revision: https://reviews.llvm.org/D49361 llvm-svn: 338780
2018-07-31[analyzer] Move InnerPointerChecker out of alpha.Reka Kovacs
Differential Revision: https://reviews.llvm.org/D49058 llvm-svn: 338433
2018-07-30[analyzer] Add support for more invalidating functions in InnerPointerChecker.Reka Kovacs
According to the standard, pointers referring to the elements of a `basic_string` may be invalidated if they are used as an argument to any standard library function taking a reference to non-const `basic_string` as an argument. This patch makes InnerPointerChecker warn for these cases. Differential Revision: https://reviews.llvm.org/D49656 llvm-svn: 338259
2018-07-20[analyzer] Rename DanglingInternalBufferChecker to InnerPointerChecker.Reka Kovacs
Differential Revision: https://reviews.llvm.org/D49553 llvm-svn: 337559