aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaChecking.cpp
AgeCommit message (Collapse)AuthorFilesLines
2020-06-03[clang][Sema] SequenceChecker: C++17 sequencing rule for call expressions.Bruno Ricci1-3/+39
In C++17 the postfix-expression of a call expression is sequenced before each expression in the expression-list and any default argument. Differential Revision: https://reviews.llvm.org/D58579 Reviewed By: rsmith
2020-05-19Fix aux-target diagnostics for certain builtinsErich Keane1-48/+52
When I fixed the targets specific builtins to make sure that aux-targets are checked, it seems I didn't consider cases where the builtins check the target info for further info. This patch bubbles the target-info down to the individual checker functions to ensure that they validate against the aux-target as well. For non-aux-target invocations, this is an NFC.
2020-05-15[Clang][BPF] implement __builtin_btf_type_id() builtin functionYonghong Song1-3/+20
Such a builtin function is mostly useful to preserve btf type id for non-global data. For example, extern void foo(..., void *data, int size); int test(...) { struct t { int a; int b; int c; } d; d.a = ...; d.b = ...; d.c = ...; foo(..., &d, sizeof(d)); } The function "foo" in the above only see raw data and does not know what type of the data is. In certain cases, e.g., logging, the additional type information will help pretty print. This patch implemented a BPF specific builtin u32 btf_type_id = __builtin_btf_type_id(param, flag) which will return a btf type id for the "param". flag == 0 will indicate a BTF local relocation, which means btf type_id only adjusted when bpf program BTF changes. flag == 1 will indicate a BTF remote relocation, which means btf type_id is adjusted against linux kernel or future other entities. Differential Revision: https://reviews.llvm.org/D74668
2020-05-15[Sema] Teach -Wcast-align to compute an accurate alignment using theAkira Hatanaka1-18/+220
alignment information on VarDecls in more cases This commit improves upon https://reviews.llvm.org/D21099. The code that computes the source alignment now understands array subscript expressions, binary operators, derived-to-base casts, and several more expressions. rdar://problem/59242343 Differential Revision: https://reviews.llvm.org/D78767
2020-05-07Ensure aux-target specific builtins get validated.Erich Keane1-51/+53
I discovered that when using an aux-target builtin, it was recognized as a builtin but never checked. This patch checks for an aux-target builtin and instead validates it against the correct target. It does this by extracting the checking code for Target-specific builtins into its own function, then calls with either targetInfo or AuxTargetInfo.
2020-04-27[AMDGPU] Expose llvm fence instruction as clang intrinsicSaiyedul Islam1-0/+44
Expose llvm fence instruction as clang builtin for AMDGPU target __builtin_amdgcn_fence(unsigned int memoryOrdering, const char *syncScope) The first argument of this builtin is one of the memory-ordering specifiers __ATOMIC_ACQUIRE, __ATOMIC_RELEASE, __ATOMIC_ACQ_REL, or __ATOMIC_SEQ_CST following C++11 memory model semantics. This is mapped to corresponding LLVM atomic memory ordering for the fence instruction using LLVM atomic C ABI. The second argument is an AMDGPU-specific synchronization scope defined as string. Reviewed By: sameerds Differential Revision: https://reviews.llvm.org/D75917
2020-04-24[SveEmitter] Add builtins for contiguous prefetchesSander de Smalen1-0/+4
This patch also adds the enum `sv_prfop` for the prefetch operation specifier and checks to ensure the passed enum values are valid. Reviewers: SjoerdMeijer, efriedma, ctetreau Reviewed By: efriedma Tags: #clang Differential Revision: https://reviews.llvm.org/D78674
2020-04-23[NFC] Refactoring PropertyAttributeKind for ObjCPropertyDecl and ObjCDeclSpec.Puyan Lotfi1-4/+3
This is a code clean up of the PropertyAttributeKind and ObjCPropertyAttributeKind enums in ObjCPropertyDecl and ObjCDeclSpec that are exactly identical. This non-functional change consolidates these enums into one. The changes are to many files across clang (and comments in LLVM) so that everything refers to the new consolidated enum in DeclObjCCommon.h. 2nd Landing Attempt... Differential Revision: https://reviews.llvm.org/D77233
2020-04-23Revert "[NFC] Refactoring PropertyAttributeKind for ObjCPropertyDecl and ↵Puyan Lotfi1-3/+4
ObjCDeclSpec." This reverts commit 2aa044ed088ae41461ad7029c055014df6c60976. Reverting due to bot failure in lldb.
2020-04-22[NFC] Refactoring PropertyAttributeKind for ObjCPropertyDecl and ObjCDeclSpec.Puyan Lotfi1-4/+3
This is a code clean up of the PropertyAttributeKind and ObjCPropertyAttributeKind enums in ObjCPropertyDecl and ObjCDeclSpec that are exactly identical. This non-functional change consolidates these enums into one. The changes are to many files across clang (and comments in LLVM) so that everything refers to the new consolidated enum in DeclObjCCommon.h. Differential Revision: https://reviews.llvm.org/D77233
2020-04-20[SveEmitter] Add immediate checks for lanes and complex immsSander de Smalen1-0/+49
Adds another bunch of of intrinsics that take immediates with varying ranges based, some being a complex rotation immediate which are a set of allowed immediates rather than a range. svmla_lane: lane immediate ranging 0..(128/(1*sizeinbits(elt)) - 1) svcmla_lane: lane immediate ranging 0..(128/(2*sizeinbits(elt)) - 1) svdot_lane: lane immediate ranging 0..(128/(4*sizeinbits(elt)) - 1) svcadd: complex rotate immediate [90, 270] svcmla: svcmla_lane: complex rotate immediate [0, 90, 180, 270] Reviewers: efriedma, SjoerdMeijer, rovka Reviewed By: efriedma Tags: #clang Differential Revision: https://reviews.llvm.org/D76680
2020-04-20[SveEmitter] Add more immediate operand checks.Sander de Smalen1-0/+23
This patch adds a number of intrinsics that take immediates with varying ranges based on the element size one of the operands. svext: immediate ranging 0 to (2048/sizeinbits(elt) - 1) svasrd: immediate ranging 1..sizeinbits(elt) svqshlu: immediate ranging 1..sizeinbits(elt)/2 ftmad: immediate ranging 0..(sizeinbits(elt) - 1) Reviewers: efriedma, SjoerdMeijer, rovka, rengolin Reviewed By: SjoerdMeijer Tags: #clang Differential Revision: https://reviews.llvm.org/D76679
2020-04-17Reland Implement _ExtInt as an extended int type specifier.Erich Keane1-0/+6
I fixed the LLDB issue, so re-applying the patch. This reverts commit a4b88c044980337bb14390be654fe76864aa60ec.
2020-04-17Revert "Implement _ExtInt as an extended int type specifier."Sterling Augustine1-6/+0
This reverts commit 61ba1481e200b5b35baa81ffcff81acb678e8508. I'm reverting this because it breaks the lldb build with incomplete switch coverage warnings. I would fix it forward, but am not familiar enough with lldb to determine the correct fix. lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:3958:11: error: enumeration values 'DependentExtInt' and 'ExtInt' not handled in switch [-Werror,-Wswitch] switch (qual_type->getTypeClass()) { ^ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4633:11: error: enumeration values 'DependentExtInt' and 'ExtInt' not handled in switch [-Werror,-Wswitch] switch (qual_type->getTypeClass()) { ^ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp:4889:11: error: enumeration values 'DependentExtInt' and 'ExtInt' not handled in switch [-Werror,-Wswitch] switch (qual_type->getTypeClass()) {
2020-04-17Implement _ExtInt as an extended int type specifier.Erich Keane1-0/+6
Introduction/Motivation: LLVM-IR supports integers of non-power-of-2 bitwidth, in the iN syntax. Integers of non-power-of-two aren't particularly interesting or useful on most hardware, so much so that no language in Clang has been motivated to expose it before. However, in the case of FPGA hardware normal integer types where the full bitwidth isn't used, is extremely wasteful and has severe performance/space concerns. Because of this, Intel has introduced this functionality in the High Level Synthesis compiler[0] under the name "Arbitrary Precision Integer" (ap_int for short). This has been extremely useful and effective for our users, permitting them to optimize their storage and operation space on an architecture where both can be extremely expensive. We are proposing upstreaming a more palatable version of this to the community, in the form of this proposal and accompanying patch. We are proposing the syntax _ExtInt(N). We intend to propose this to the WG14 committee[1], and the underscore-capital seems like the active direction for a WG14 paper's acceptance. An alternative that Richard Smith suggested on the initial review was __int(N), however we believe that is much less acceptable by WG14. We considered _Int, however _Int is used as an identifier in libstdc++ and there is no good way to fall back to an identifier (since _Int(5) is indistinguishable from an unnamed initializer of a template type named _Int). [0]https://www.intel.com/content/www/us/en/software/programmable/quartus-prime/hls-compiler.html) [1]http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2472.pdf Differential Revision: https://reviews.llvm.org/D73967
2020-04-14[SveEmitter] Add range checks for immediates and predicate patterns.Sander de Smalen1-0/+36
Summary: This patch adds a mechanism to easily add range checks for a builtin's immediate operands. This patch is tested with the qdech intrinsic, which takes both an enum for the predicate pattern, as well as an immediate for the multiplier. Reviewers: efriedma, SjoerdMeijer, rovka Reviewed By: efriedma, SjoerdMeijer Subscribers: mgorny, tschuett, mgrang, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76678
2020-04-07Allow parameter names to be elided in a function definition in C.Aaron Ballman1-5/+6
WG14 has adopted N2480 (http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2480.pdf) into C2x at the meetings last week, allowing parameter names of a function definition to be elided. This patch relaxes the error so that C++ and C2x do not diagnose this situation, and modes before C2x will allow it as an extension. This also adds the same feature to ObjC blocks under the assumption that ObjC wishes to follow the C standard in this regard.
2020-04-06For PR45333: Move AnalyzeImplicitConversions to using data recursionRichard Smith1-10/+33
instead of recursing on the stack. This doesn't actually resolve PR45333, because we now hit stack overflow somewhere else, but it does get us further. I've not found any way of testing this that doesn't still crash elsewhere.
2020-03-21[clang] Fix crash during template sema checkingGuillaume Chatelet1-4/+9
Summary: If the size parameter of `__builtin_memcpy_inline` comes from an un-instantiated template parameter current code would crash. Reviewers: efriedma, courbet Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D76504
2020-03-10Suppress an "unused variable" warning in release buildMikhail Maltsev1-0/+1
2020-03-10[ARM,CDE] Generalize MVE intrinsics infrastructure to support CDEMikhail Maltsev1-0/+60
Summary: This patch generalizes the existing code to support CDE intrinsics which will share some properties with existing MVE intrinsics (some of the intrinsics will be polymorphic and accept/return values of MVE vector types). Specifically the patch: * Adds new tablegen backends -gen-arm-cde-builtin-def, -gen-arm-cde-builtin-codegen, -gen-arm-cde-builtin-sema, -gen-arm-cde-builtin-aliases, -gen-arm-cde-builtin-header based on existing MVE backends. * Renames the '__clang_arm_mve_alias' attribute into '__clang_arm_builtin_alias' (it will be used with CDE intrinsics as well as MVE intrinsics) * Implements semantic checks for the coprocessor argument of the CDE intrinsics as well as the existing coprocessor intrinsics. * Adds one CDE intrinsic __arm_cx1 to test the above changes Reviewers: simon_tatham, MarkMurrayARM, ostannard, dmgreen Reviewed By: simon_tatham Subscribers: sdesmalen, mgorny, kristof.beyls, danielkiss, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D75850
2020-03-09Add a warning for builtin_return_address/frame_address with > 0 argumentJeremy Stenglein1-0/+11
Clang is missing a warning for builtin_return_address/builtin_frame_address called with > 0 argument. Gcc provides a warning for this via -Wframe-address: https://gcc.gnu.org/onlinedocs/gcc/Return-Address.html As calling these functions with argument > 0 has caused several crashes for us, we would like to have the same warning as gcc here. This diff adds the warning and makes it part of -Wmost. Differential Revision: https://reviews.llvm.org/D75768
2020-03-06[CodeGen][ObjC] Extend lifetime of ObjC pointers passed to calls toAkira Hatanaka1-0/+2
__builtin_os_log_format This is needed to keep all the objects, including temporaries returned by function calls, written to the buffer alive until os_log_pack_send is called. rdar://problem/60105410
2020-03-02[Sema] Look through OpaqueValueExpr when checking implicit conversionsErik Pilkington1-6/+14
Specifically, this fixes a false-positive in -Wobjc-signed-char-bool. rdar://57372317 Differential revision: https://reviews.llvm.org/D75387
2020-02-26[Sema] Perform call checking when building CXXNewExprRoman Lebedev1-2/+3
Summary: There was even a TODO for this. The main motivation is to make use of call-site based `__attribute__((alloc_align(param_idx)))` validation (D72996). Reviewers: rsmith, erichkeane, aaron.ballman, jdoerfert Reviewed By: rsmith Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D73020
2020-02-25Check args passed to __builtin_frame_address and __builtin_return_address.zoecarver1-0/+5
Verifies that an argument passed to __builtin_frame_address or __builtin_return_address is within the range [0, 0xFFFF] Differential revision: https://reviews.llvm.org/D66839 Re-committed after fixed: c93112dc4f745b0455addb54bfe1c2f79b827c6d
2020-02-24Revert "Validate argument passed to __builtin_frame_address and ↵zoecarver1-5/+0
__builtin_return_address" This reverts commit c93112dc4f745b0455addb54bfe1c2f79b827c6d.
2020-02-24Validate argument passed to __builtin_frame_address and __builtin_return_addresszoecarver1-0/+5
Verifies that the argument passed to __builtin_frame_address and __builtin_return_address is within the range [0, 0xFFFF].
2020-02-20[Sema] Demote call-site-based 'alignment is a power of two' check for ↵Roman Lebedev1-4/+2
AllocAlignAttr into a warning Summary: As @rsmith notes in https://reviews.llvm.org/D73020#inline-672219 while that is certainly UB land, it may not be actually reachable at runtime, e.g.: ``` template<int N> void *make() { if ((N & (N-1)) == 0) return operator new(N, std::align_val_t(N)); else return operator new(N); } void *p = make<7>(); ``` and we shouldn't really error-out there. That being said, i'm not really following the logic here. Which ones of these cases should remain being an error? Reviewers: rsmith, erichkeane Reviewed By: erichkeane Subscribers: cfe-commits, rsmith Tags: #clang Differential Revision: https://reviews.llvm.org/D73996
2020-02-11[Mips] Add intrinsics for 4-byte and 8-byte MSA loads/stores.Mirko Brkusanin1-0/+4
New intrinisics are implemented for when we need to port SIMD code from other arhitectures and only load or store portions of MSA registers. Following intriniscs are added which only load/store element 0 of a vector: v4i32 __builtin_msa_ldrq_w (const void *, imm_n2048_2044); v2i64 __builtin_msa_ldr_d (const void *, imm_n4096_4088); void __builtin_msa_strq_w (v4i32, void *, imm_n2048_2044); void __builtin_msa_str_d (v2i64, void *, imm_n4096_4088); Differential Revision: https://reviews.llvm.org/D73644
2020-02-07[clang] Add support for __builtin_memcpy_inlineGuillaume Chatelet1-0/+11
Summary: This is a follow up on D61634 and the last step to implement http://lists.llvm.org/pipermail/llvm-dev/2019-April/131973.html Reviewers: efriedma, courbet, tejohnson Subscribers: hiraditya, cfe-commits, llvm-commits, jdoerfert, t.p.northover Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D73543
2020-01-25Improve static checks for sprintf and __builtin___sprintf_chkserge-sans-paille1-10/+234
Implement a pessimistic evaluator of the minimal required size for a buffer based on the format string, and couple that with the fortified version to emit a warning when the buffer size is lower than the lower bound computed from the format string. Differential Revision: https://reviews.llvm.org/D71566
2020-01-24[Sema] Introduce MaximumAlignment value, to be used instead of magical constantsRoman Lebedev1-8/+4
There is llvm::Value::MaximumAlignment, which is numerically equivalent to these constants, but we can't use it directly because we can't include llvm IR headers in clang Sema. So instead, copy-paste the constant, and fixup the places to use it. This was initially reviewed in https://reviews.llvm.org/D72998
2020-01-24[Sema] Try 2: Attempt to perform call-size-specific ↵Roman Lebedev1-0/+21
`__attribute__((alloc_align(param_idx)))` validation Summary: `alloc_align` attribute takes parameter number, not the alignment itself, so given **just** the attribute/function declaration we can't do any sanity checking for said alignment. However, at call site, given the actual `Expr` that is passed into that parameter, we //might// be able to evaluate said `Expr` as Integer Constant Expression, and perform the sanity checks. But since there is no requirement for that argument to be an immediate, we may fail, and that's okay. However if we did evaluate, we should enforce the same constraints as with `__builtin_assume_aligned()`/`__attribute__((assume_aligned(imm)))`: said alignment is a power of two, and is not greater than our magic threshold This was initially committed in c2a9061ac5166e48fe85ea2b6dbce9457c964958 but reverted in 00756b182398b92abe16559287467079087aa631 because of suspicious bot failures. Reviewers: erichkeane, aaron.ballman, hfinkel, rsmith, jdoerfert Reviewed By: erichkeane Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72996
2020-01-23Partially revert "[IR] Attribute/AttrBuilder: use Value::MaximumAlignment ↵Roman Lebedev1-2/+4
magic constant" Apparently makes bots angry. This reverts commit d096f8d306b2b16a25f65ffb70849ca7963a0dac.
2020-01-23Revert "[Sema] Attempt to perform call-size-specific ↵Roman Lebedev1-19/+0
`__attribute__((alloc_align(param_idx)))` validation" Likely makes bots angry. This reverts commit c2a9061ac5166e48fe85ea2b6dbce9457c964958.
2020-01-23[IR] Attribute/AttrBuilder: use Value::MaximumAlignment magic constantRoman Lebedev1-8/+4
Summary: I initially encountered those assertions when trying to create this IR `alignment` attribute from clang's `__attribute__((assume_aligned(imm)))`, because until D72994 there is no sanity checking for the value of `imm`. But even then, we have `llvm::Value::MaximumAlignment` constant (which is `536870912`), which is enforced for clang attributes, and then there are some other magical constant (`0x40000000` i.e. `1073741824` i.e. `2 * 536870912`) in `Attribute::getWithAlignment()`/`AttrBuilder::addAlignmentAttr()`. I strongly suspect that `0x40000000` is incorrect, and that also should be `llvm::Value::MaximumAlignment`. Reviewers: erichkeane, hfinkel, jdoerfert, gchatelet, courbet Reviewed By: erichkeane Subscribers: hiraditya, cfe-commits, llvm-commits Tags: #llvm, #clang Differential Revision: https://reviews.llvm.org/D72998
2020-01-23[Sema] Attempt to perform call-size-specific ↵Roman Lebedev1-0/+21
`__attribute__((alloc_align(param_idx)))` validation Summary: `alloc_align` attribute takes parameter number, not the alignment itself, so given **just** the attribute/function declaration we can't do any sanity checking for said alignment. However, at call site, given the actual `Expr` that is passed into that parameter, we //might// be able to evaluate said `Expr` as Integer Constant Expression, and perform the sanity checks. But since there is no requirement for that argument to be an immediate, we may fail, and that's okay. However if we did evaluate, we should enforce the same constraints as with `__builtin_assume_aligned()`/`__attribute__((assume_aligned(imm)))`: said alignment is a power of two, and is not greater than our magic threshold Reviewers: erichkeane, aaron.ballman, hfinkel, rsmith, jdoerfert Reviewed By: erichkeane Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72996
2020-01-23[ARM,MVE] Support immediate vbicq,vorrq,vmvnq intrinsics.Simon Tatham1-2/+12
Summary: Immediate vmvnq is code-generated as a simple vector constant in IR, and left to the backend to recognize that it can be created with an MVE VMVN instruction. The predicated version is represented as a select between the input and the same constant, and I've added a Tablegen isel rule to turn that into a predicated VMVN. (That should be better than the previous VMVN + VPSEL: it's the same number of instructions but now it can fold into an adjacent VPT block.) The unpredicated forms of VBIC and VORR are done by enabling the same isel lowering as for NEON, recognizing appropriate immediates and rewriting them as ARMISD::VBICIMM / ARMISD::VORRIMM SDNodes, which I then instruction-select into the right MVE instructions (now that I've also reworked those instructions to use the same MC operand encoding). In order to do that, I had to promote the Tablegen SDNode instance `NEONvorrImm` to a general `ARMvorrImm` available in MVE as well, and similarly for `NEONvbicImm`. The predicated forms of VBIC and VORR are represented as a vector select between the original input vector and the output of the unpredicated operation. The main convenience of this is that it still lets me use the existing isel lowering for VBICIMM/VORRIMM, and not have to write another copy of the operand encoding translation code. This intrinsic family is the first to use the `imm_simd` system I put into the MveEmitter tablegen backend. So, naturally, it showed up a bug or two (emitting bogus range checks and the like). Fixed those, and added a full set of tests for the permissible immediates in the existing Sema test. Also adjusted the isel pattern for `vmovlb.u8`, which stopped matching because lowering started turning its input into a VBICIMM. Now it recognizes the VBICIMM instead. Reviewers: dmgreen, MarkMurrayARM, miyuki, ostannard Reviewed By: dmgreen Subscribers: kristof.beyls, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D72934
2020-01-16[Hexagon] Update autogenerated intrinsic info in clangKrzysztof Parzyszek1-821/+1
In addition to that, use target features to validate intrinsic availability on a given target.
2020-01-16[Hexagon] Fix alignment info for __builtin_circ_lduhKrzysztof Parzyszek1-1/+1
2020-01-09Add builtins for aligning and checking alignment of pointers and integersAlex Richardson1-0/+87
This change introduces three new builtins (which work on both pointers and integers) that can be used instead of common bitwise arithmetic: __builtin_align_up(x, alignment), __builtin_align_down(x, alignment) and __builtin_is_aligned(x, alignment). I originally added these builtins to the CHERI fork of LLVM a few years ago to handle the slightly different C semantics that we use for CHERI [1]. Until recently these builtins (or sequences of other builtins) were required to generate correct code. I have since made changes to the default C semantics so that they are no longer strictly necessary (but using them does generate slightly more efficient code). However, based on our experience using them in various projects over the past few years, I believe that adding these builtins to clang would be useful. These builtins have the following benefit over bit-manipulation and casts via uintptr_t: - The named builtins clearly convey the semantics of the operation. While checking alignment using __builtin_is_aligned(x, 16) versus ((x & 15) == 0) is probably not a huge win in readably, I personally find __builtin_align_up(x, N) a lot easier to read than (x+(N-1))&~(N-1). - They preserve the type of the argument (including const qualifiers). When using casts via uintptr_t, it is easy to cast to the wrong type or strip qualifiers such as const. - If the alignment argument is a constant value, clang can check that it is a power-of-two and within the range of the type. Since the semantics of these builtins is well defined compared to arbitrary bit-manipulation, it is possible to add a UBSAN checker that the run-time value is a valid power-of-two. I intend to add this as a follow-up to this change. - The builtins avoids int-to-pointer casts both in C and LLVM IR. In the future (i.e. once most optimizations handle it), we could use the new llvm.ptrmask intrinsic to avoid the ptrtoint instruction that would normally be generated. - They can be used to round up/down to the next aligned value for both integers and pointers without requiring two separate macros. - In many projects the alignment operations are already wrapped in macros (e.g. roundup2 and rounddown2 in FreeBSD), so by replacing the macro implementation with a builtin call, we get improved diagnostics for many call-sites while only having to change a few lines. - Finally, the builtins also emit assume_aligned metadata when used on pointers. This can improve code generation compared to the uintptr_t casts. [1] In our CHERI compiler we have compilation mode where all pointers are implemented as capabilities (essentially unforgeable 128-bit fat pointers). In our original model, casts from uintptr_t (which is a 128-bit capability) to an integer value returned the "offset" of the capability (i.e. the difference between the virtual address and the base of the allocation). This causes problems for cases such as checking the alignment: for example, the expression `if ((uintptr_t)ptr & 63) == 0` is generally used to check if the pointer is aligned to a multiple of 64 bytes. The problem with offsets is that any pointer to the beginning of an allocation will have an offset of zero, so this check always succeeds in that case (even if the address is not correctly aligned). The same issues also exist when aligning up or down. Using the alignment builtins ensures that the address is used instead of the offset. While I have since changed the default C semantics to return the address instead of the offset when casting, this offset compilation mode can still be used by passing a command-line flag. Reviewers: rsmith, aaron.ballman, theraven, fhahn, lebedev.ri, nlopes, aqjune Reviewed By: aaron.ballman, lebedev.ri Differential Revision: https://reviews.llvm.org/D71499
2020-01-09Improve support of GNU mempcpyserge-sans-paille1-2/+5
- Lower to the memcpy intrinsic - Raise warnings when size/bounds are known Differential Revision: https://reviews.llvm.org/D71374
2019-12-27[OpenCL] Fix inconsistency between opencl and c11 atomic fetch max/minYaxun (Sam) Liu1-2/+2
There is some inconsistency between opencl and c11 atomic fetch max/min after https://reviews.llvm.org/D46386 https://reviews.llvm.org/D55562 It is not reasonable to have such inconsistencies. This patch fixes that. Differential Revision: https://reviews.llvm.org/D71725
2019-12-22[Sema] SequenceChecker: C++17 sequencing rules for built-in operators <<, ↵Bruno Ricci1-25/+83
>>, .*, ->*, =, op= Implement the C++17 sequencing rules for the built-in operators <<, >>, .*, ->*, = and op=. Differential Revision: https://reviews.llvm.org/D58297 Reviewed By: rsmith
2019-12-22[Sema] SequenceChecker: Fix handling of operator ||, && and ?:Bruno Ricci1-31/+96
The current handling of the operators ||, && and ?: has a number of false positive and false negative. The issues for operator || and && are: 1. We need to add sequencing regions for the LHS and RHS as is done for the comma operator. Not doing so causes false positives in expressions like `((a++, false) || (a++, false))` (from PR39779, see PR22197 for another example). 2. In the current implementation when the evaluation of the LHS fails, the RHS is added to a worklist to be processed later. This results in false negatives in expressions like `(a && a++) + a`. Fix these issues by introducing sequencing regions for the LHS and RHS, and by not deferring the visitation of the RHS. The issues with the ternary operator ?: are similar, with the added twist that we should not warn on expressions like `(x ? y += 1 : y += 2)` since exactly one of the 2nd and 3rd expression is going to be evaluated, but we should still warn on expressions like `(x ? y += 1 : y += 2) = y`. Differential Revision: https://reviews.llvm.org/D57747 Reviewed By: rsmith
2019-12-22[Sema] SequenceChecker: Add some comments + related small NFCsBruno Ricci1-73/+122
NFCs factored out of the following patches: - Change all of the `Expr *` to `const Expr *` in SequenceChecker for const-correctness. SequenceChecker should not modify AST nodes. - Add some comments. - clang-format Differential Revision: https://reviews.llvm.org/D57659 Reviewed By: xbolva00
2019-12-17Reland [NFC-I] Remove hack for fp-classification builtinsErich Keane1-34/+24
The FP-classification builtins (__builtin_isfinite, etc) use variadic packs in the definition file to mean an overload set. Because of that, floats were converted to doubles, which is incorrect. There WAS a patch to remove the cast after the fact. THis patch switches these builtins to just be custom type checking, calls the implicit conversions for the integer members, and makes sure the correct L->R casts are put into place, then does type checking like normal. A future direction (that wouldn't be NFC) would consider making conversions for the floating point parameter legal. Note: The initial patch for this missed that certain systems need to still convert half to float, since they dont' support that type.
2019-12-16[c++20] Add deprecation warnings for the expression forms deprecated by P1120R0.Richard Smith1-29/+2
This covers: * usual arithmetic conversions (comparisons, arithmetic, conditionals) between different enumeration types * usual arithmetic conversions between enums and floating-point types * comparisons between two operands of array type The deprecation warnings are on-by-default (in C++20 compilations); it seems likely that these forms will become ill-formed in C++23, so warning on them now by default seems wise. For the first two bullets, off-by-default warnings were also added for all the cases where we didn't already have warnings (covering language modes prior to C++20). These warnings are in subgroups of the existing -Wenum-conversion (except that the first case is not warned on if either enumeration type is anonymous, consistent with our existing -Wenum-conversion warnings).
2019-12-16Revert "[NFC-I] Remove hack for fp-classification builtins"Erich Keane1-18/+34
This reverts commit b1e542f302c1ed796ad9f703d4d36e010afcb914. The original 'hack' didn't chop out fp-16 to double conversions, so systems that use FP16ConversionIntrinsics end up in IR-CodeGen with an i16 type isntead of a float type (like PPC64-BE). The bots noticed this. Reverting until I figure out how to fix this