summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExpr.cpp
AgeCommit message (Collapse)Author
2023-07-02[clang] Remove CGBuilderTy::CreateElementBitCastYoungsuk Kim
`CGBuilderTy::CreateElementBitCast()` no longer does what its name suggests. Remove remaining in-tree uses by one of the following methods. * drop the call entirely * fold it to an `Address` construction * replace it with `Address::withElementType()` This is a NFC cleanup effort. Reviewed By: barannikov88, nikic, jrtc27 Differential Revision: https://reviews.llvm.org/D154285
2023-06-29[clang][CodeGen] Remove no-op EmitCastToVoidPtr (NFC)Sergei Barannikov
Reviewed By: JOE1994 Differential Revision: https://reviews.llvm.org/D153694
2023-06-18[clang] Replace uses of CGBuilderTy::CreateElementBitCast (NFC)Youngsuk Kim
* Add `Address::withElementType()` as a replacement for `CGBuilderTy::CreateElementBitCast`. * Partial progress towards replacing `CreateElementBitCast`, as it no longer does what its name suggests. Either replace its uses with `Address::withElementType()`, or remove them if no longer needed. * Remove unused parameter 'Name' of `CreateElementBitCast` Reviewed By: barannikov88, nikic Differential Revision: https://reviews.llvm.org/D153196
2023-06-10[clang][WebAssembly] Implement support for table types and builtinsPaulo Matos
This commit implements support for WebAssembly table types and respective builtins. Table tables are WebAssembly objects to store reference types. They have a large amount of semantic restrictions including, but not limited to, only being allowed to be declared at the top-level as static arrays of zero-length. Not being arguments or result of functions, not being stored ot memory, etc. This commit introduces the __attribute__((wasm_table)) to attach to arrays of WebAssembly reference types. And the following builtins to manage tables: * ref __builtin_wasm_table_get(table, idx) * void __builtin_wasm_table_set(table, idx, ref) * uint __builtin_wasm_table_size(table) * uint __builtin_wasm_table_grow(table, ref, uint) * void __builtin_wasm_table_fill(table, idx, ref, uint) * void __builtin_wasm_table_copy(table, table, uint, uint, uint) This commit also enables reference-types feature at bleeding-edge. This is joint work with Alex Bradbury (@asb). Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D139010
2023-05-29[CodeGen] Use llvm::LLVMContext::MD_nontemporal (NFC)Kazu Hirata
2023-05-25-fsanitize=function: fix alignment fault on Arm targets.Simon Tatham
Function pointers are checked by loading a prefix structure from just before the function's entry point. However, on Arm, the function pointer is not always exactly equal to the address of the entry point, because Thumb function pointers have the low bit set to tell the BX instruction to enter them in Thumb state. So the generated code loads from an odd address and suffers an alignment fault. Fixed by clearing the low bit of the function pointer before subtracting 8. Differential Revision: https://reviews.llvm.org/D151308
2023-05-23[NFC][Clang] Fix Coverity bug with dereference null return value in ↵Manna, Soumi
clang::CodeGen::CodeGenFunction::EmitOMPArraySectionExpr() Reported by Coverity: Inside "CGExpr.cpp" file, in clang::CodeGen::CodeGenFunction::EmitOMPArraySectionExpr(clang::OMPArraySectionExpr const *, bool): Return value of function which returns null is dereferenced without checking. } else { //returned_null: getAsConstantArrayType returns nullptr (checked 83 out of 95 times). // var_assigned: Assigning: CAT = nullptr return value from getAsConstantArrayType. auto *CAT = C.getAsConstantArrayType(ArrayTy); //identity_transfer: Member function call CAT->getSize() returns an offset off CAT (this). // Dereference null return value (NULL_RETURNS) //dereference: Dereferencing a pointer that might be nullptr CAT->getSize() when calling APInt. ConstLength = CAT->getSize(); } This patch adds an assert to resolve the bug. Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D151137
2023-05-22-fsanitize=function: support CFangrui Song
With D148785, -fsanitize=function no longer uses C++ RTTI objects and therefore can support C. The rationale for reporting errors is C11 6.5.2.2p9: > If the function is defined with a type that is not compatible with the type (of the expression) pointed to by the expression that denotes the called function, the behavior is undefined. The mangled types approach we use does not exactly match the C type compatibility (see `f(callee1)` below). This is probably fine as the rules are unlikely leveraged in practice. In addition, the call is warned by -Wincompatible-function-pointer-types-strict. ``` void callee0(int (*a)[]) {} void callee1(int (*a)[1]) {} void f(void (*fp)(int (*)[])) { fp(0); } int main() { int a[1]; f(callee0); f(callee1); // compatible but flagged by -fsanitize=function, -fsanitize=kcfi, and -Wincompatible-function-pointer-types-strict } ``` Skip indirect call sites of a function type without a prototype to avoid deal with C11 6.5.2.2p6. -fsanitize=kcfi skips such calls as well. Reviewed By: #sanitizers, vitalybuka Differential Revision: https://reviews.llvm.org/D148827
2023-05-20-fsanitize=function: use type hashes instead of RTTI objectsFangrui Song
Currently we use RTTI objects to check type compatibility. To support non-unique RTTI objects, commit 5745eccef54ddd3caca278d1d292a88b2281528b added a `checkTypeInfoEquality` string matching to the runtime. The scheme is inefficient. ``` _Z1fv: .long 846595819 # jmp .long .L__llvm_rtti_proxy-_Z3funv ... main: ... # Load the second word (pointer to the RTTI object) and dereference it. movslq 4(%rsi), %rax movq (%rax,%rsi), %rdx # Is it the desired typeinfo object? leaq _ZTIFvvE(%rip), %rax # If not, call __ubsan_handle_function_type_mismatch_v1, which may recover if checkTypeInfoEquality allows cmpq %rax, %rdx jne .LBB1_2 ... .section .data.rel.ro,"aw",@progbits .p2align 3, 0x0 .L__llvm_rtti_proxy: .quad _ZTIFvvE ``` Let's replace the indirect `_ZTI` pointer with a type hash similar to `-fsanitize=kcfi`. ``` _Z1fv: .long 3238382334 .long 2772461324 # type hash main: ... # Load the second word (callee type hash) and check whether it is expected cmpl $-1522505972, -4(%rax) # If not, fail: call __ubsan_handle_function_type_mismatch jne .LBB2_2 ``` The RTTI object derives its name from `clang::MangleContext::mangleCXXRTTI`, which uses `mangleType`. `mangleTypeName` uses `mangleType` as well. So the type compatibility change is high-fidelity. Since we no longer need RTTI pointers in `__ubsan::__ubsan_handle_function_type_mismatch_v1`, let's switch it back to version 0, the original signature before e215996a2932ed7c472f4e94dc4345b30fd0c373 (2019). `__ubsan::__ubsan_handle_function_type_mismatch_abort` is not recoverable, so we can revert some changes from e215996a2932ed7c472f4e94dc4345b30fd0c373. Reviewed By: samitolvanen Differential Revision: https://reviews.llvm.org/D148785
2023-05-19Change -fsanitize=function to place two words before the function entryFangrui Song
The current implementation of -fsanitize=function places two words (the prolog signature and the RTTI proxy) at the function entry, which makes the feature incompatible with Intel Indirect Branch Tracking (IBT) that needs an ENDBR instruction at the function entry. To allow the combination, move the two words before the function entry, similar to -fsanitize=kcfi. Armv8.5 Branch Target Identification (BTI) has a similar requirement. Note: for IBT and BTI, whether a function gets a marker instruction at the entry generally cannot be assumed (it can be disabled by a function attribute or stronger LTO optimizations). It is extremely unlikely for two words preceding a function entry to be inaccessible. One way to achieve this is by ensuring that a function is aligned at a page boundary and making the preceding page unmapped or unreadable. This is not reasonable for application or library code. (Think: the first text section has crt* code not instrumented by -fsanitize=function.) We use 0xc105cafe for all targets. .long 0xc105cafe disassembles to invalid instructions on all architectures I have tested, except Power where it is `lfs 8, -13570(5)` (Load Floating-Point with a weird offset, unlikely to be used in real code). --- For the removed function in AsmPrinter.cpp, remove an assert: `mdconst::extract` already asserts non-nullness. For compiler-rt/test/ubsan/TestCases/TypeCheck/Function/function.cpp, when the function doesn't have prolog/epilog (-O1 and above), after moving the two words, the address of the function equals the address of ret instruction, so symbolizing the function will additionally get a non-zero column number. Adjust the test to allow an optional column number. ``` .long 3238382334 .long .L__llvm_rtti_proxy-_Z1fv _Z1fv: // symbolizing here retrieves the line table entry from the second .loc .file 0 ... .loc 0 1 0 .cfi_startproc .loc 0 2 1 prologue_end retq ``` Reviewed By: peter.smith Differential Revision: https://reviews.llvm.org/D148665
2023-03-16Emit const globals with constexpr destructor as constant LLVM valuesHans Wennborg
This follows 2b4fa53 which made Clang not emit destructor calls for such objects. However, they would still not get emitted as constants since CodeGenModule::isTypeConstant() returns false if the destructor is constexpr. This change adds a param to make isTypeConstant() ignore the dtor, allowing the caller to check it instead. Fixes Issue #61212 Differential revision: https://reviews.llvm.org/D145369
2023-02-28[Coroutines] Avoid creating conditional cleanup markers in suspend blockWei Wang
We shouldn't access coro frame after returning from `await_suspend()` and before `llvm.coro.suspend()`. Make sure we always hoist conditional cleanup markers when inside the `await.suspend` block. Fix https://github.com/llvm/llvm-project/issues/59181 Reviewed By: ChuanqiXu Differential Revision: https://reviews.llvm.org/D144680
2023-02-15[CodeGen] Add a flag to `Address` and `Lvalue` that is used to keepAkira Hatanaka
track of whether the pointer is known not to be null The flag will be used for the arm64e work we plan to upstream in the future (see https://lists.llvm.org/pipermail/llvm-dev/2019-October/136091.html). Currently the flag has no effect on code generation. Differential Revision: https://reviews.llvm.org/D142584
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-13[clang][NFC] Remove dependency on DataLayout::getPrefTypeAlignmentGuillaume Chatelet
2023-01-13[clang][NFC] Remove dependency on DataLayout::getPrefTypeAlignmentGuillaume Chatelet
2023-01-12[Clang] Emit noundef metadata next to range metadataNikita Popov
To preserve the previous semantics after D141386, adjust places that currently emit !range metadata to also emit !noundef metadata. This retains range violation as immediate undefined behavior, rather than just poison. Differential Revision: https://reviews.llvm.org/D141494
2023-01-11[clang][NFC] Use the TypeSize::getXXXValue() instead of TypeSize::getXXXSize)Guillaume Chatelet
This change is one of a series to implement the discussion from https://reviews.llvm.org/D141134.
2022-12-08Revert "[AMDGPU] Disable bool range metadata to workaround backend issue"Yaxun (Sam) Liu
This reverts commit 107ee2613063183cb643cef97f0fad403508c9f0 to facilitate investigating and fixing the root cause. Differential Revision: https://reviews.llvm.org/D135269
2022-12-03[CodeGen] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-01[clang] Avoid duplicating ProgramAddressSpace in TargetInfo. NFCIAlex Richardson
This value was added to clang/Basic in D111566, but is only used during codegen, where we can use the LLVM IR DataLayout instead. I noticed this because the downstream CHERI targets would have to also set this value for AArch64/RISC-V/MIPS. Instead of duplicating more information between LLVM IR and Clang, this patch moves getTargetAddressSpace(QualType T) to CodeGenTypes, where we can consult the DataLayout. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D138296
2022-11-30[clang] Do not merge traps in functions annotated optnoneHenrik G. Olsson
This aligns the behaviour with that of disabling optimisations for the translation unit entirely. Not merging the traps allows us to keep separate debug information for each, improving the debugging experience when finding the cause for a ubsan trap. Differential Revision: https://reviews.llvm.org/D137714
2022-11-29clang: Fix cast failure when using -fsanitize=undefined for HIPMatt Arsenault
This was assuming a direct reference to the global variable. The constant string is placed in addrspace 4, and has a constexpr addrspacecast to the generic address space.
2022-11-17Fix declare target implementation to support enter.Doru Bercea
2022-11-10[ObjC] avoid crashing when emitting synthesized getter/setter and ptrdiff_t ↵Matt Jacobson
is smaller than long On targets where ptrdiff_t is smaller than long, clang crashes when emitting synthesized getters/setters that call objc_[gs]etProperty. Explicitly emit a zext/trunc of the ivar offset value (which is defined to long) to ptrdiff_t, which objc_[gs]etProperty takes. Add a test using the AVR target, where ptrdiff_t is smaller than long. Test failed previously and passes now. Differential Revision: https://reviews.llvm.org/D112049
2022-11-07[HLSL] Added HLSL this as a referenceGrace Jennings
This change makes `this` a reference instead of a pointer in HLSL. HLSL does not have the `->` operator, and accesses through `this` are with the `.` syntax. Tests were added and altered to make sure the AST accurately reflects the types. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D135721
2022-11-02[clang] Fix inline builtin functions of an __asm__ renamed function with ↵Martin Storsjö
symbol prefixes If a function is renamed with `__asm__`, the name provided is the exact symbol name, without any extra implicit symbol prefixes. If the target does use symbol prefixes, the IR level symbol gets an `\01` prefix to indicate that it's a literal symbol name to be taken as is. When a builtin function is specialized by providing an inline version of it, that inline function is named `<funcname>.inline`. When the base function has been renamed due to `__asm__`, the inline function ends up named `<asmname>.inline`. Up to this point, things did work as expected before. However, for targets with symbol prefixes, one codepath that produced the combined name `<asmname>.inline` used the mangled `asmname` with `\01` prefix, while others didn't. This patch fixes this. This fixes the combination of asm renamed builtin function, with inline override of the function, on any target with symbol prefixes (such as i386 windows and any Darwin target). Differential Revision: https://reviews.llvm.org/D137073
2022-10-07[AMDGPU] Disable bool range metadata to workaround backend issueYaxun (Sam) Liu
Currently there is a middle-end or backend issue https://github.com/llvm/llvm-project/issues/58176 which causes values loaded from bool pointer incorrect when bool range metadata is emitted. Temporarily disable bool range metadata until the backend issue is fixed. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D135269 Fixes: SWDEV-344137
2022-10-06[clang][NFC] Use enum for -fstrict-flex-arraysBill Wendling
Use enums for the strict flex arrays flag so that it's more readable. Differential Revision: https://reviews.llvm.org/D135107
2022-10-04[clang] Unify Sema and CodeGen implementation of isFlexibleArrayMemberExprserge-sans-paille
Turn it into a single Expr::isFlexibleArrayMemberLike method, as discussed in https://discourse.llvm.org/t/rfc-harmonize-flexible-array-members-handling Keep different behavior with respect to macro / template substitution, and harmonize sharp edges: ObjC interface now behave as C struct wrt. FAM and -fstrict-flex-arrays. This does not impact __builtin_object_size interactions with FAM. Differential Revision: https://reviews.llvm.org/D134791
2022-09-22[clang] Fix interaction between asm labels and inline builtinsserge-sans-paille
One must pick the same name as the one referenced in CodeGenFunction when generating .inline version of an inline builtin, otherwise they are not correctly replaced. Differential Revision: https://reviews.llvm.org/D134362
2022-09-08[clang] Use std::size instead of llvm::array_lengthofJoe Loser
LLVM contains a helpful function for getting the size of a C-style array: `llvm::array_lengthof`. This is useful prior to C++17, but not as helpful for C++17 or later: `std::size` already has support for C-style arrays. Change call sites to use `std::size` instead. Leave the few call sites that use a locally defined `array_lengthof` that are meant to test previous bugs with NTTPs in clang analyzer and SemaTemplate. Differential Revision: https://reviews.llvm.org/D133520
2022-09-03[clang] Qualify auto in range-based for loops (NFC)Kazu Hirata
2022-09-01[clang] cleanup -fstrict-flex-arrays implementationserge-sans-paille
This is a follow up to https://reviews.llvm.org/D126864, addressing some remaining comments. It also considers union with a single zero-length array field as FAM for each value of -fstrict-flex-arrays. Differential Revision: https://reviews.llvm.org/D132944
2022-08-04[Clang][C++20] Support capturing structured bindings in lambdasCorentin Jabot
This completes the implementation of P1091R3 and P1381R1. This patch allow the capture of structured bindings both for C++20+ and C++17, with extension/compat warning. In addition, capturing an anonymous union member, a bitfield, or a structured binding thereof now has a better diagnostic. We only support structured bindings - as opposed to other kinds of structured statements/blocks. We still emit an error for those. In addition, support for structured bindings capture is entirely disabled in OpenMP mode as this needs more investigation - a specific diagnostic indicate the feature is not yet supported there. Note that the rest of P1091R3 (static/thread_local structured bindings) was already implemented. at the request of @shafik, i can confirm the correct behavior of lldb wit this change. Fixes https://github.com/llvm/llvm-project/issues/54300 Fixes https://github.com/llvm/llvm-project/issues/54300 Fixes https://github.com/llvm/llvm-project/issues/52720 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D122768
2022-08-03Revert "[Clang][C++20] Support capturing structured bindings in lambdas"Corentin Jabot
This reverts commit 44f2baa3804a62ca793f0ff3e43aa71cea91a795. Breaks self builds and seems to have conformance issues.
2022-08-03[Clang][C++20] Support capturing structured bindings in lambdasCorentin Jabot
This completes the implementation of P1091R3 and P1381R1. This patch allow the capture of structured bindings both for C++20+ and C++17, with extension/compat warning. In addition, capturing an anonymous union member, a bitfield, or a structured binding thereof now has a better diagnostic. We only support structured bindings - as opposed to other kinds of structured statements/blocks. We still emit an error for those. In addition, support for structured bindings capture is entirely disabled in OpenMP mode as this needs more investigation - a specific diagnostic indicate the feature is not yet supported there. Note that the rest of P1091R3 (static/thread_local structured bindings) was already implemented. at the request of @shafik, i can confirm the correct behavior of lldb wit this change. Fixes https://github.com/llvm/llvm-project/issues/54300 Fixes https://github.com/llvm/llvm-project/issues/54300 Fixes https://github.com/llvm/llvm-project/issues/52720 Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D122768
2022-08-01Use @llvm.threadlocal.address intrinsic to access TLS variableChuanqi Xu
This is successor for D125291. This revision would try to use @llvm.threadlocal.address in clang to access TLS variable. The reason why the OpenMP tests contains a lot of change is that they uses utils/update_cc_test_checks.py to update their tests. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D129833
2022-07-28[Clang] Diagnose ill-formed constant expression when setting a non fixed ↵Shafik Yaghmour
enum to a value outside the range of the enumeration values DR2338 clarified that it was undefined behavior to set the value outside the range of the enumerations values for an enum without a fixed underlying type. We should diagnose this with a constant expression context. Differential Revision: https://reviews.llvm.org/D130058
2022-07-27Revert "[Clang] Diagnose ill-formed constant expression when setting a non ↵Shafik Yaghmour
fixed enum to a value outside the range of the enumeration values" This reverts commit a3710589f285de0bb22ff92b1fc24df9411e986f.
2022-07-27[Clang] Diagnose ill-formed constant expression when setting a non fixed ↵Shafik Yaghmour
enum to a value outside the range of the enumeration values DR2338 clarified that it was undefined behavior to set the value outside the range of the enumerations values for an enum without a fixed underlying type. We should diagnose this with a constant expression context. Differential Revision: https://reviews.llvm.org/D130058
2022-07-18[clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of flexible ↵serge-sans-paille
arrays Some code [0] consider that trailing arrays are flexible, whatever their size. Support for these legacy code has been introduced in f8f632498307d22e10fab0704548b270b15f1e1e but it prevents evaluation of __builtin_object_size and __builtin_dynamic_object_size in some legit cases. Introduce -fstrict-flex-arrays=<n> to have stricter conformance when it is desirable. n = 0: current behavior, any trailing array member is a flexible array. The default. n = 1: any trailing array member of undefined, 0 or 1 size is a flexible array member n = 2: any trailing array member of undefined or 0 size is a flexible array member This takes into account two specificities of clang: array bounds as macro id disqualify FAM, as well as non standard layout. Similar patch for gcc discuss here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [0] https://docs.freebsd.org/en/books/developers-handbook/sockets/#sockets-essential-functions
2022-06-27Revert "[clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of ↵Vitaly Buka
flexible arrays" This reverts D126864 and related fixes. This reverts commit 572b08790a69f955ae0cbb1b4a7d4a215f15dad9. This reverts commit 886715af962de2c92fac4bd37104450345711e4a.
2022-06-24[clang] Add back -fsanitize=array-bounds workaround for size-1 array after ↵Fangrui Song
-fstrict-flex-arrays change Before C99 introduced flexible array member, common practice uses size-1 array to emulate FAM, e.g. https://github.com/python/cpython/issues/94250 As a result, -fsanitize=array-bounds instrumentation skipped such structures as a workaround (from 539e4a77bbabbc19f22b2bd24e04af2e432e599d). D126864 accidentally dropped the workaround. Add it back with tests.
2022-06-24[clang] Introduce -fstrict-flex-arrays=<n> for stricter handling of flexible ↵serge-sans-paille
arrays Some code [0] consider that trailing arrays are flexible, whatever their size. Support for these legacy code has been introduced in f8f632498307d22e10fab0704548b270b15f1e1e but it prevents evaluation of __builtin_object_size and __builtin_dynamic_object_size in some legit cases. Introduce -fstrict-flex-arrays=<n> to have stricter conformance when it is desirable. n = 0: current behavior, any trailing array member is a flexible array. The default. n = 1: any trailing array member of undefined, 0 or 1 size is a flexible array member n = 2: any trailing array member of undefined or 0 size is a flexible array member n = 3: any trailing array member of undefined size is a flexible array member (strict c99 conformance) Similar patch for gcc discuss here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101836 [0] https://docs.freebsd.org/en/books/developers-handbook/sockets/#sockets-essential-functions
2022-06-14[NFC][Alignment] Use MaybeAlign in CGCleanup/CGExprGuillaume Chatelet
2022-05-20[clang] Honor __attribute__((no_builtin("foo"))) on functionsStephen Long
Support for `__attribute__((no_builtin("foo")))` was added in https://reviews.llvm.org/D68028, but builtins were still being used even when the attribute was placed on a function. Reviewed By: hans Differential Revision: https://reviews.llvm.org/D124701
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-20Fixup D123950 to address revert of D123345David Tenty
Since D123345 got reverted Builtin::BIaddressof and Builtin::BI__addressof don't exist and cause build breaks.