llvm-project/clang/unittests
Richard Smith b27430f9f4 Treat `std::move`, `forward`, etc. as builtins.
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
  fc30901096,
  a571f82a50, and
  64c045e25b
which were reverted in
  e75d8b7037
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-17 13:26:16 -07:00
..
AST [randstruct] Add test for "-frandomize-layout-seed-file" flag 2022-04-14 16:35:41 -07:00
ASTMatchers Reland "[ASTMatchers] Output currently matching node on crash" 2022-04-05 21:47:16 +01:00
Analysis Treat `std::move`, `forward`, etc. as builtins. 2022-04-17 13:26:16 -07:00
Basic [clang] NFCI: Use FileEntryRef in FileManagerTest 2022-04-15 15:16:17 +02:00
CodeGen [clang-repl] Recommit "Land initial infrastructure for incremental parsing" 2021-05-13 06:30:29 +00: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 Blind stab in the dark to fix a bot failure 2022-04-15 20:12:59 -05:00
Format [clang-format] Skip preprocessor lines when finding the record lbrace 2022-04-14 09:31:15 -07:00
Frontend [test][clang] Use -clear-ast-before-backend instead of -flegacy-pass-manager in CommandLineTest 2022-04-11 14:06:40 -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 [IntrospectionTest] Replace "return" with "GTEST_SKIP" 2022-02-04 12:35:44 -08:00
Lex [clang][lex] NFCI: Use FileEntryRef in PPCallbacks::InclusionDirective() 2022-04-14 10:46:12 +02:00
Rename Bump googletest to 1.10.0 2021-05-14 19:16:31 +02:00
Rewrite
Sema [NFC][Clang][test] Inclusive language: Remove and rephrase uses of sanity test/check in clang/test 2021-11-24 14:03:49 -05:00
Serialization [Frontend] Only compile modules if not already finalized 2021-07-15 18:27:08 -07:00
StaticAnalyzer [NFC][analyzer] Allow CallDescriptions to be matched with CallExprs 2022-03-01 17:13:04 +01:00
Tooling [RGT] Use GTEST_SKIP instead of just returning 2022-04-08 12:20:20 -07:00
libclang
CMakeLists.txt [clang-repl] Recommit "Land initial infrastructure for incremental parsing" 2021-05-13 06:30:29 +00:00