summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix "pointer is null" static analyzer warnings. NFCI.Simon Pilgrim2020-01-141-20/+17
| | | | Use castAs<> instead of getAs<> since the pointer is dereferenced immediately in all cases and castAs will perform the null assertion for us.
* Fix "pointer is null" clang static analyzer warnings. NFCI.Simon Pilgrim2020-01-141-23/+14
| | | | Use cast<>/castAs<> instead of dyn_cast<>/getAs<> since the pointers are always dereferenced and cast<>/castAs<> will perform the null assertion for us.
* [OpenCL] Add MSAA sharing extension builtin functionsSven van Haastregt2020-01-141-0/+37
| | | | | | | Add the MSAA sharing builtin functions from the OpenCL Extension Specification. Patch by Pierre Gondois and Sven van Haastregt.
* Fix "pointer is null" static analyzer warning. NFCI.Simon Pilgrim2020-01-141-1/+2
| | | | Remove Ctx null test as clang static analyzer assumes that this can fail - replace it with an assertion as the pointer is always dereferenced below.
* Fix "pointer is null" static analyzer warnings. NFCI.Simon Pilgrim2020-01-141-1/+1
| | | | Use cast<> instead of cast_or_null<> since the pointers are always dereferenced and cast<> will perform the null assertion for us.
* Remove duplicate variable. NFCI.Simon Pilgrim2020-01-141-1/+0
|
* Merge isa<> and getAs<> calls to fix "pointer is null" static analyzer ↵Simon Pilgrim2020-01-141-6/+5
| | | | warnings. NFCI.
* PR44514: Fix recovery from noexcept with non-convertible expressionsErich Keane2020-01-131-2/+10
| | | | | | | | | | | | We currently treat noexcept(not-convertible-to-bool) as 'none', which results in the typeloc info being a different size, and causing an assert later on in the process. In order to make recovery less destructive, replace this with noexcept(false) and a constructed 'false' expression. Bug Report: https://bugs.llvm.org/show_bug.cgi?id=44514 Differential Revision: https://reviews.llvm.org/D72621
* Implement VectorType conditional operator GNU extension.Erich Keane2020-01-131-15/+147
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | GCC supports the conditional operator on VectorTypes that acts as a 'select' in C++ mode. This patch implements the support. Types are converted as closely to GCC's behavior as possible, though in a few places consistency with our existing vector type support was preferred. Note that this implementation is different from the OpenCL version in a number of ways, so it unfortunately required a different implementation. First, the SEMA rules and promotion rules are significantly different. Secondly, GCC implements COND[i] != 0 ? LHS[i] : RHS[i] (where i is in the range 0- VectorSize, for each element). In OpenCL, the condition is COND[i] < 0 ? LHS[i]: RHS[i]. In the process of implementing this, it was also required to make the expression COND ? LHS : RHS type dependent if COND is type dependent, since the type is now dependent on the condition. For example: T ? 1 : 2; Is not typically type dependent, since the result can be deduced from the operands. HOWEVER, if T is a VectorType now, it could change this to a 'select' (basically a swizzle with a non-constant mask) with the 1 and 2 being promoted to vectors themselves. While this is a change, it is NOT a standards incompatible change. Based on my (and D. Gregor's, at the time of writing the code) reading of the standard, the expression is supposed to be type dependent if ANY sub-expression is type dependent. Differential Revision: https://reviews.llvm.org/D71463
* Sema::getOwningModule - take const Decl* type.Simon Pilgrim2020-01-131-4/+3
| | | | Fixes static analyzer warning that const_cast was being used despite only const methods being called.
* Fix "pointer is null" static analyzer warnings. NFCI.Simon Pilgrim2020-01-111-6/+6
| | | | Use castAs<> instead of getAs<> since the pointers are dereferenced immediately and castAs will perform the null assertion for us.
* Fix "pointer is null" static analyzer warning. NFCI.Simon Pilgrim2020-01-111-2/+1
| | | | Use castAs<> instead of getAs<> since the pointer is dereferenced immediately below and castAs will perform the null assertion for us.
* [Sema] Improve -Wrange-loop-analysis warnings.Mark de Wever2020-01-111-4/+16
| | | | | | | | | | | | | | | No longer generate a diagnostic when a small trivially copyable type is used without a reference. Before the test looked for a POD type and had no size restriction. Since the range-based for loop is only available in C++11 and POD types are trivially copyable in C++11 it's not required to test for a POD type. Since copying a large object will be expensive its size has been restricted. 64 bytes is a common size of a cache line and if the object is aligned the copy will be cheap. No performance impact testing has been done. Differential Revision: https://reviews.llvm.org/D72212
* [Concepts] Fix MarkUsedTemplateParameters for exprsSaar Raz2020-01-111-25/+20
| | | | | | D41910 introduced a recursive visitor to MarkUsedTemplateParameters, but disregarded the 'Depth' parameter, and had incorrect assertions. This fixes the visitor and removes the assertions.
* Clean up and slightly generalize implementation of composite pointerRichard Smith2020-01-101-126/+212
| | | | | | | | | | | type computation, in preparation for P0388R4, which adds another few cases here. We now properly handle forming multi-level composite pointer types involving nested Objective-C pointer types (as is consistent with including them as part of the notion of 'similar types' on which this rule is based). We no longer lose non-CVR qualifiers on nested pointer types.
* Add a FIXME and corresponding test coverage for some suspicious behaviorRichard Smith2020-01-101-0/+3
| | | | forming composite ObjC pointer types in comparisons.
* Remove redundant implicit cast creation.Richard Smith2020-01-101-2/+0
| | | | | FindCompositePointerType has already cast the operands to the composite type for us in the case where it succeeds.
* Support function attribute patchable_function_entryFangrui Song2020-01-101-0/+23
| | | | | | | | | This feature is generic. Make it applicable for AArch64 and X86 because the backend has only implemented NOP insertion for AArch64 and X86. Reviewed By: nickdesaulniers, aaron.ballman Differential Revision: https://reviews.llvm.org/D72221
* Add support for __declspec(guard(nocf))Andrew Paverd2020-01-101-0/+22
| | | | | | | | | | | | | | | | | | Summary: Avoid using the `nocf_check` attribute with Control Flow Guard. Instead, use a new `"guard_nocf"` function attribute to indicate that checks should not be added on indirect calls within that function. Add support for `__declspec(guard(nocf))` following the same syntax as MSVC. Reviewers: rnk, dmajor, pcc, hans, aaron.ballman Reviewed By: aaron.ballman Subscribers: aaron.ballman, tomrittervg, hiraditya, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D72167
* [CodeComplete] Suggest 'return nullptr' in functions returning pointersIlya Biryukov2020-01-101-0/+7
| | | | | | | | | | Reviewers: kadircet Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72497
* CWG2352: Allow qualification conversions during reference binding.Richard Smith2020-01-093-131/+165
| | | | | | | | | | | | | | | | | | | | | | The language wording change forgot to update overload resolution to rank implicit conversion sequences based on qualification conversions in reference bindings. The anticipated resolution for that oversight is implemented here -- we order candidates based on qualification conversion, not only on top-level cv-qualifiers, including ranking reference bindings against non-reference bindings if they differ in non-top-level qualification conversions. For OpenCL/C++, this allows reference binding between pointers with differing (nested) address spaces. This makes the behavior of reference binding consistent with that of implicit pointer conversions, as is the purpose of this change, but that pre-existing behavior for pointer conversions is itself probably not correct. In any case, it's now consistently the same behavior and implemented in only one place. This reinstates commit de21704ba96fa80d3e9402f12c6505917a3885f4, reverted in commit d8018233d1ea4234de68d5b4593abd773db79484, with workarounds for some overload resolution ordering problems introduced by CWG2352.
* When diagnosing the lack of a viable conversion function, also listRichard Smith2020-01-092-100/+143
| | | | | | | | | | | | | | explicit functions that are not candidates. It's not always obvious that the reason a conversion was not possible is because the function you wanted to call is 'explicit', so explicitly say if that's the case. It would be nice to rank the explicit candidates higher in the diagnostic if an implicit conversion sequence exists for their arguments, but unfortunately we can't determine that without potentially triggering non-immediate-context errors that we're not permitted to produce.
* Add builtins for aligning and checking alignment of pointers and integersAlex Richardson2020-01-091-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
* Improve support of GNU mempcpyserge-sans-paille2020-01-091-2/+5
| | | | | | | - Lower to the memcpy intrinsic - Raise warnings when size/bounds are known Differential Revision: https://reviews.llvm.org/D71374
* [Concepts] Function trailing requires clausesSaar Raz2020-01-0914-212/+648
| | | | | | Function trailing requires clauses now parsed, supported in overload resolution and when calling, referencing and taking the address of functions or function templates. Differential Revision: https://reviews.llvm.org/D43357
* Fix "pointer is null" static analyzer warning. NFCI.Simon Pilgrim2020-01-091-4/+3
| | | | Use cast<> instead of dyn_cast<> since we know that the pointer should be valid (and is dereferenced immediately below).
* Fix "pointer is null" static analyzer warnings. NFCI.Simon Pilgrim2020-01-091-2/+2
| | | | Use castAs<> instead of getAs<> since the pointer is dereferenced immediately below and castAs will perform the null assertion for us.
* [LifetimeAnalysis] Do not forbid void deref type in gsl::Pointer/gsl::Owner ↵Gabor Horvath2020-01-071-5/+3
| | | | | | | | | | | annotations It turns out it is useful to be able to define the deref type as void. In case we have a type erased owner, we want to express that the pointee can be basically any type. It should not be unnatural to have a void deref type as we already familiar with "pointers to void". Differential Revision: https://reviews.llvm.org/D72097
* [OPENMP]Do not diagnose references to non-integral types for ref inAlexey Bataev2020-01-071-2/+2
| | | | | | declare simd. According to the standard, a list-item that appears in a linear clause without the ref modifier must be of integral or pointer type, or must be a reference to an integral or pointer type. Added check that this restriction is applied only to non-ref items.
* [NFC] Use isX86() instead of getArch()Jim Lin2020-01-071-2/+1
| | | | | | | | | | | | | | Summary: This is a clean up for https://reviews.llvm.org/D72247. Reviewers: MaskRay, craig.topper, jhenderson Reviewed By: MaskRay Subscribers: hiraditya, rupprecht, cfe-commits, llvm-commits Tags: #clang, #llvm Differential Revision: https://reviews.llvm.org/D72320
* Always deduce the lengths of contained parameter packs when deducing aRichard Smith2020-01-062-21/+34
| | | | | | | | | | | | | | | | | pack expansion. Previously, if all parameter / argument pairs for a pack expansion deduction were non-deduced contexts, we would not deduce the arity of the pack, and could end up deducing a different arity (leading to failures during substitution) or defaulting to an arity of 0 (leading to bad diagnostics about passing the wrong number of arguments to a variadic function). Instead, we now always deduce the arity for all involved packs any time we deduce a pack expansion. This will result in less substitution happening in some cases, which could avoid non-SFINAEable errors, and should generally improve the quality of diagnostics when passing initializer lists to variadic functions.
* [OPENMP]Fix crash on error message for declare reduction.Alexey Bataev2020-01-031-1/+2
| | | | | If the qualified reduction name is specified and not found, the compiler may crash because of not specified parameter.
* [OpenMP] diagnose zero-length array section in the depend clauseKelvin Li2020-01-031-0/+16
| | | | | | | The OpenMP specification disallows having zero-length array sections in the depend clause (OpenMP 5.0 2.17.11). Differential Revision: https://reviews.llvm.org/D71969
* [OpenMP] Fix formatting of OpenMP error message, by Wang Tianqing.Alexey Bataev2020-01-021-3/+2
| | | | | | | | | | | | | | Summary: `getListOfPossibleValues()` formatted incorrectly when there is only one value, emitting something like `expected 'conditional' or in OpenMP clause 'lastprivate'`. Reviewers: jdoerfert, ABataev Reviewed By: jdoerfert Subscribers: guansong, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71884
* Improve Wrange-loop-analyses for rvalue referenceMark de Wever2020-01-011-1/+3
| | | | | | | | | | The Wrange-loop-analyses warns if a copy is made. Suppress this warning when a temporary is bound to a rvalue reference. While fixing this issue also found a copy-paste error in test6, which is also fixed. Differential Revision: https://reviews.llvm.org/D71806
* Adds fixit hints to the -Wrange-loop-analysisMark de Wever2020-01-011-3/+6
| | | | Differential Revision: https://reviews.llvm.org/D68913
* [OpenCL] Remove redundant foreach in OpenCLBuiltins.td; NFCSven van Haastregt2019-12-311-76/+32
| | | | | Remove various `foreach` declarations where the iterator is used only once. This makes the .td file more compact.
* [X86][AsmParser] re-introduce 'offset' operatorEric Astor2019-12-301-1/+6
| | | | | | | | | | | | | | | | | | | | | | | Summary: Amend MS offset operator implementation, to more closely fit with its MS counterpart: 1. InlineAsm: evaluate non-local source entities to their (address) location 2. Provide a mean with which one may acquire the address of an assembly label via MS syntax, rather than yielding a memory reference (i.e. "offset asm_label" and "$asm_label" should be synonymous 3. address PR32530 Based on http://llvm.org/D37461 Fix broken test where the break appears unrelated. - Set up appropriate memory-input rewrites for variable references. - Intel-dialect assembly printing now correctly handles addresses by adding "offset". - Pass offsets as immediate operands (using "r" constraint for offsets of locals). Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D71436
* [OpenCL] Add mipmap builtin functionsSven van Haastregt2019-12-301-0/+177
| | | | | | | Add the mipmap builtin functions from the OpenCL extension specification. Patch by Pierre Gondois and Sven van Haastregt.
* Allow redeclaration of __declspec(uuid)Zachary Henkel2019-12-282-3/+9
| | | | | | | | | msvc allows a subsequent declaration of a uuid attribute on a struct/class. Mirror this behavior in clang-cl. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D71439
* Revert "CWG2352: Allow qualification conversions during reference binding."David Blaikie2019-12-273-164/+136
| | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit de21704ba96fa80d3e9402f12c6505917a3885f4. Regressed/causes this to error due to ambiguity: void f(const int * const &); void f(int *); int main() { int * x; f(x); } (in case it's important - the original case where this turned up was a member function overload in a class template with, essentially: f(const T1&) f(T2*) (where T1 == X const *, T2 == X)) It's not super clear to me if this ^ is expected behavior, in which case I'm sorry about the revert & happy to look into ways to fix the original code.
* [OpenCL] Fix inconsistency between opencl and c11 atomic fetch max/minYaxun (Sam) Liu2019-12-271-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
* [OpenCL] Pretty print __private addr spaceAnastasia Stulova2019-12-271-1/+1
| | | | | | | | | | Add printing of __private address space to TypePrinter to allow it appears in diagnostics and AST dumps as all other language addr spaces. Tags: #clang Differential Revision: https://reviews.llvm.org/D71272
* [OpenMP][NFCI] Use the libFrontend ProcBindKind in ClangJohannes Doerfert2019-12-262-8/+8
| | | | | | | | | | | | This removes the OpenMPProcBindClauseKind enum in favor of llvm::omp::ProcBindKind which lives in OpenMPConstants.h and was introduced in D70109. No change in behavior is expected. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D70289
* [OPENMP]Add extra checks and initialization for clause modifier.Alexey Bataev2019-12-241-0/+8
| | | | | Added initialization of the extra modifier to silence sanitizer. Added extra checks to avoid such trouble in future.
* [OPENMP50]Basic support for conditional lastprivate.Alexey Bataev2019-12-242-20/+51
| | | | Added parsing/sema checks for conditional lastprivates.
* [Sema][X86] Consider target attribute into the checks in validateOutputSize ↵Craig Topper2019-12-231-4/+9
| | | | | | | | | | | | | and validateInputSize. The validateOutputSize and validateInputSize need to check whether AVX or AVX512 are enabled. But this can be affected by the target attribute so we need to factor that in. This patch moves some of the code from CodeGen to create an appropriate feature map that we can pass to the function. Differential Revision: https://reviews.llvm.org/D68627
* [OPENMP50]Codegen for nontemporal clause.Alexey Bataev2019-12-231-11/+35
| | | | | | | | | | | | | | | | Summary: Basic codegen for the declarations marked as nontemporal. Also, if the base declaration in the member expression is marked as nontemporal, lvalue for member decl access inherits nonteporal flag from the base lvalue. Reviewers: rjmccall, hfinkel, jdoerfert Subscribers: guansong, arphaman, caomhin, kkwli0, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71708
* [OpenCL] Add atomic builtin functionsSven van Haastregt2019-12-231-0/+79
| | | | | | Add atomic builtin functions from the OpenCL C specification. Patch by Pierre Gondois and Sven van Haastregt.
* [Concepts] Constrained partial specializations and function overloads.Saar Raz2019-12-235-49/+617
| | | | | | | Added support for constraint satisfaction checking and partial ordering of constraints in constrained partial specialization and function template overloads. Re-commit after fixing another crash (added regression test). Differential Revision: https://reviews.llvm.org/D41910
OpenPOWER on IntegriCloud