summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExpr.cpp
AgeCommit message (Collapse)Author
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.
2022-04-20Look through calls to std::addressof to compute pointer alignment.Eli Friedman
This is sort of a followup to D37310; that basically fixed the same issue, but then the libstdc++ implementation of <atomic> changed. Re-fix the the issue in essentially the same way: look through the addressof operation to find the alignment of the underlying object. Differential Revision: https://reviews.llvm.org/D123950
2022-04-13Fix Werror build issue from 6f20744b7ff875Erich Keane
2022-04-13Add support for ignored bitfield conditional codegen.Erich Keane
Currently we emit an error in just about every case of conditionals with a 'non simple' branch if treated as an LValue. This patch adds support for the special case where this is an 'ignored' lvalue, which permits the side effects from happening. It also splits up the emit for conditional LValue in a way that should be usable to handle simple assignment expressions in similar situations. Differential Revision: https://reviews.llvm.org/D123680
2022-04-08[Clang][Fortify] drop inline decls when redeclaredserge-sans-paille
When an inline builtin declaration is shadowed by an actual declaration, we must reference the actual declaration, even if it's not the last, following GCC behavior. This fixes #54715 Differential Revision: https://reviews.llvm.org/D123308
2022-03-23[CGExpr] Perform bitcast unconditionallyNikita Popov
The way the check is written is not compatible with opaque pointers -- while we don't need to change the IR pointer type, we do need to change the element type stored in the Address.
2022-03-23Reapply [CodeGen] Avoid deprecated Address ctor in EmitLoadOfPointer()Nikita Popov
This requires some adjustment in caller code, because there was a confusion regarding the meaning of the PtrTy argument: This argument is the type of the pointer being loaded, not the addresses being loaded from. Reapply after fixing the specified pointer type for one call in 47eb4f7dcd845878b16a53dadd765195b9c24b6e, where the used type is important for determining alignment.
2022-03-23Revert "[CodeGen] Avoid deprecated Address ctor in EmitLoadOfPointer()"Nikita Popov
This reverts commit 767ec883e37510a247ea5695921876ef67cf5b3f. This results in a some incorrect alignments which are not covered by existing tests.
2022-03-22[CodeGen] Avoid deprecated Address ctor in EmitLoadOfPointer()Nikita Popov
This requires some adjustment in caller code, because there was a confusion regarding the meaning of the PtrTy argument: This argument is the type of the pointer being loaded, not the addresses being loaded from.
2022-03-17[CodeGen] Avoid some pointer element type accessesNikita Popov
2022-03-16[Clang] Allow "ext_vector_type" applied to BooleansSimon Moll
This is the `ext_vector_type` alternative to D81083. This patch extends Clang to allow 'bool' as a valid vector element type (attribute ext_vector_type) in C/C++. This is intended as the canonical type for SIMD masks and facilitates clean vector intrinsic declarations. Vectors of i1 are supported on IR level and below down to many SIMD ISAs, such as AVX512, ARM SVE (fixed vector length) and the VE target (NEC SX-Aurora TSUBASA). The RFC on cfe-dev: https://lists.llvm.org/pipermail/cfe-dev/2020-May/065434.html Reviewed By: erichkeane Differential Revision: https://reviews.llvm.org/D88905
2022-03-02[NFC][Clang][OpaquePtr] Remove the call to Address::deprecated inAkira Hatanaka
CreatePointerBitCastOrAddrSpaceCast Differential Revision: https://reviews.llvm.org/D120757
2022-02-23[clang] Remove Address::deprecated() from CGClass.cppArthur Eubanks
2022-02-17[CodeGen] Rename deprecated Address constructorNikita Popov
To make uses of the deprecated constructor easier to spot, and to ensure that no new uses are introduced, rename it to Address::deprecated(). While doing the rename, I've filled in element types in cases where it was relatively obvious, but we're still left with 135 calls to the deprecated constructor.
2022-02-16[CGBuilder] Assert that CreateAddrSpaceCast does not change element typeNikita Popov
Address space casts in general may change the element type, but don't allow it in the method working on Address, so we can preserve the element type. CreatePointerBitCastOrAddrSpaceCast() still needs to be addressed.
2022-02-14Extend the `uwtable` attribute with unwind table kindMomchil Velikov
We have the `clang -cc1` command-line option `-funwind-tables=1|2` and the codegen option `VALUE_CODEGENOPT(UnwindTables, 2, 0) ///< Unwind tables (1) or asynchronous unwind tables (2)`. However, this is encoded in LLVM IR by the presence or the absence of the `uwtable` attribute, i.e. we lose the information whether to generate want just some unwind tables or asynchronous unwind tables. Asynchronous unwind tables take more space in the runtime image, I'd estimate something like 80-90% more, as the difference is adding roughly the same number of CFI directives as for prologues, only a bit simpler (e.g. `.cfi_offset reg, off` vs. `.cfi_restore reg`). Or even more, if you consider tail duplication of epilogue blocks. Asynchronous unwind tables could also restrict code generation to having only a finite number of frame pointer adjustments (an example of *not* having a finite number of `SP` adjustments is on AArch64 when untagging the stack (MTE) in some cases the compiler can modify `SP` in a loop). Having the CFI precise up to an instruction generally also means one cannot bundle together CFI instructions once the prologue is done, they need to be interspersed with ordinary instructions, which means extra `DW_CFA_advance_loc` commands, further increasing the unwind tables size. That is to say, async unwind tables impose a non-negligible overhead, yet for the most common use cases (like C++ exceptions), they are not even needed. This patch extends the `uwtable` attribute with an optional value: - `uwtable` (default to `async`) - `uwtable(sync)`, synchronous unwind tables - `uwtable(async)`, asynchronous (instruction precise) unwind tables Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D114543
2022-02-14[CGBuilder] Remove CreateBitCast() methodNikita Popov
Use CreateElementBitCast() instead, or don't work on Address where not necessary.
2022-02-11[Clang][OpaquePtr] Remove deprecated Address constructor callsWeverything
Remove most calls to deprcated Address constructor in CGExpr.cpp Differential Revision: https://reviews.llvm.org/D119496
2022-02-07[MatrixBuilder] Remove unnecessary IRBuilder template (NFC)Nikita Popov
IRBuilderBase exists specifically to avoid the need for this.
2022-01-27[NFC][Clang][OpaquePtr] Move away from deprecated Address constructor in ↵Arthur Eubanks
CreateTempAlloca() Specify the Address element type, which is the bitcast destination type. (the whole bitcast won't be needed after opaque pointers)
2022-01-26Revert "Rename llvm::array_lengthof into llvm::size to match std::size from ↵Benjamin Kramer
C++17" This reverts commit ef8206320769ad31422a803a0d6de6077fd231d2. - It conflicts with the existing llvm::size in STLExtras, which will now never be called. - Calling it without llvm:: breaks C++17 compat
2022-01-26Rename llvm::array_lengthof into llvm::size to match std::size from C++17serge-sans-paille
As a conquence move llvm::array_lengthof from STLExtras.h to STLForwardCompat.h (which is included by STLExtras.h so no build breakage expected).
2022-01-10[CodeGen] Avoid some pointer element type accessesNikita Popov
Possibly this is sufficient to fix PR53089.
2022-01-10Use a sorted array instead of a map to store AttrBuilder string attributesSerge Guelton
Using and std::map<SmallString, SmallString> for target dependent attributes is inefficient: it makes its constructor slightly heavier, and involves extra allocation for each new string attribute. Storing the attribute key/value as strings implies extra allocation/copy step. Use a sorted vector instead. Given the low number of attributes generally involved, this is cheaper, as showcased by https://llvm-compile-time-tracker.com/compare.php?from=5de322295f4ade692dc4f1823ae4450ad3c48af2&to=05bc480bf641a9e3b466619af43a2d123ee3f71d&stat=instructions Differential Revision: https://reviews.llvm.org/D116599
2022-01-08[CGExpr] Use castAs<> instead of getAs<> to avoid dereference of nullptrSimon Pilgrim
This will assert the cast is correct instead of returning nullptr
2021-12-23[CodeGen] Avoid pointer element type access when creating LValueNikita Popov
This required fixing two places that were passing the pointer type rather than the expected pointee type to the method.
2021-12-21[CodeGen] Accept Address in CreateLaunderInvariantGroupNikita Popov
Add an overload that accepts and returns an Address, as we generally just want to replace the pointer with a laundered one, while retaining remaining information.
2021-12-21[CodeGen] Avoid some pointer element type accessesNikita Popov
This avoids some pointer element type accesses when compiling C++ code.
2021-12-16[CodeGen] Avoid more pointer element type accessesNikita Popov