summaryrefslogtreecommitdiffstats
path: root/clang/lib
Commit message (Collapse)AuthorAgeFilesLines
...
* Implement VectorType conditional operator GNU extension.Erich Keane2020-01-133-15/+163
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [clang][IFS] Prevent Clang-IFS from Leaking symbols from inside a block.Puyan Lotfi2020-01-131-0/+4
| | | | | | | | | | | | Built libdispatch with clang interface stubs. Ran into some block related issues. Basically VarDecl symbols can leak out because I wasn't checking the case where a VarDecl is contained inside a BlockDecl (versus a method or function). This patch checks that a VarDecl is not a child decl of a BlockDecl. This patch also does something very similar for c++ lambdas as well. Differential Revision: https://reviews.llvm.org/D71301
* [NFC][clang][IFS] Adding braces to if-statement as prep for D71301.Puyan Lotfi2020-01-131-1/+2
| | | | Just trying to make https://reviews.llvm.org/D71301 look cleaner.
* [Clang] Always set -z now linker option on FuchsiaPetr Hosek2020-01-131-0/+3
| | | | | | This should be the default on Fuchsia. Differential Revision: https://reviews.llvm.org/D70576
* [Clang][Driver] Re-use the calling process instead of creating a new process ↵Alexandre Ganea2020-01-132-33/+79
| | | | | | | | | | | | | | | for the cc1 invocation With this patch, the clang tool will now call the -cc1 invocation directly inside the same process. Previously, the -cc1 invocation was creating, and waiting for, a new process. This patch therefore reduces the number of created processes during a build, thus it reduces build times on platforms where process creation can be costly (Windows) and/or impacted by a antivirus. It also makes debugging a bit easier, as there's no need to attach to the secondary -cc1 process anymore, breakpoints will be hit inside the same process. Crashes or signaling inside the -cc1 invocation will have the same side-effect as before, and will be reported through the same means. This behavior can be controlled at compile-time through the CLANG_SPAWN_CC1 cmake flag, which defaults to OFF. Setting it to ON will revert to the previous behavior, where any -cc1 invocation will create/fork a secondary process. At run-time, it is also possible to tweak the CLANG_SPAWN_CC1 environment variable. Setting it and will override the compile-time setting. A value of 0 calls -cc1 inside the calling process; a value of 1 will create a secondary process, as before. Differential Revision: https://reviews.llvm.org/D69825
* Fix cppcheck uninitialized variable in DiffTree() constructor warning. NFCI.Simon Pilgrim2020-01-131-2/+1
|
* Merge isVectorType() and getAs<VectorType> calls to silence clang static ↵Simon Pilgrim2020-01-131-2/+1
| | | | analyzer warning. NFCI.
* Fix some cppcheck shadow variable warnings. NFCI.Simon Pilgrim2020-01-131-15/+13
|
* Fix "pointer is null" static analyzer warnings. NFCI.Simon Pilgrim2020-01-131-2/+2
| | | | Use castAs<> instead of getAs<> since the pointers are always dereferenced and castAs will perform the null assertion for us.
* 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.
* This option allows selecting the TLS size in the local exec TLS model,KAWASHIMA Takahiro2020-01-133-0/+16
| | | | | | | | | | | | | | | | | | which is the default TLS model for non-PIC objects. This allows large/ many thread local variables or a compact/fast code in an executable. Specification is same as that of GCC. For example, the code model option precedes the TLS size option. TLS access models other than local-exec are not changed. It means supoort of the large code model is only in the local exec TLS model. Patch By KAWASHIMA Takahiro (kawashima-fj <t-kawashima@fujitsu.com>) Reviewers: dmgreen, mstorsjo, t.p.northover, peter.smith, ostannard Reviewd By: peter.smith Committed by: peter.smith Differential Revision: https://reviews.llvm.org/D71688
* Revert "[DWARF5][clang]: Added support for DebugInfo generation for auto ↵Sam McCall2020-01-132-21/+11
| | | | | | | | | return type for C++ member functions." This reverts commit 6d6a4590c5d4c7fc7445d72fe685f966b0a8cafb, which introduces a crash. See https://reviews.llvm.org/D70524 for details.
* [DWARF5][clang]: Added support for DebugInfo generation for auto return type ↵Awanish Pandey2020-01-132-11/+21
| | | | | | | | | | | | | | | | | for C++ member functions. Summary: This patch will provide support for auto return type for the C++ member functions. This patch includes clang side implementation of this feature. Patch by: Awanish Pandey <Awanish.Pandey@amd.com> Reviewers: dblaikie, aprantl, shafik, alok, SouraVX, jini.susan.george Reviewed by: dblaikie Differential Revision: https://reviews.llvm.org/D70524
* Fix "pointer is null" static analyzer warnings. NFCI.Simon Pilgrim2020-01-121-2/+2
| | | | 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 warnings. NFCI.Simon Pilgrim2020-01-121-8/+9
| | | | Use cast<> instead of dyn_cast<> and move into its users where its dereferenced immediately.
* Revert "[ASTMatchers] extract public matchers from const-analysis into own ↵Jonas Toth2020-01-111-2/+0
| | | | | | | | patch" This reverts commit 4c48ea68e491cb42f1b5d43ffba89f6a7f0dadc4. The powerpc buildbots had an internal compiler error after this patch. This requires some inspection.
* [ASTMatchers] extract public matchers from const-analysis into own patchJonas Toth2020-01-111-0/+2
| | | | | | | | | | | | | | | | | | | Summary: The analysis for const-ness of local variables required a view generally useful matchers that are extracted into its own patch. They are `decompositionDecl` and `forEachArgumentWithParamType`, that works for calls through function pointers as well. Reviewers: aaron.ballman Reviewed By: aaron.ballman Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72505
* GlobalModuleIndex - Fix use-after-move clang static analyzer warning.Simon Pilgrim2020-01-111-4/+5
| | | | Shadow variable names meant we were referencing the Buffer input argument, not the GlobalModuleIndex member that its std::move()'d it.
* 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-1/+1
| | | | Use cast<> instead of dyn_cast<> since we know that the pointer should be valid (and is dereferenced immediately).
* Fix "pointer is null" static analyzer warning. NFCI.Simon Pilgrim2020-01-111-1/+1
| | | | Use castAs<> instead of getAs<> since the pointer is dereferenced immediately within mangleCallingConvention and castAs will perform the null assertion for us.
* Fix "pointer is null" static analyzer warnings. NFCI.Simon Pilgrim2020-01-113-17/+10
| | | | Use castAs<> instead of getAs<> since the pointer is dereferenced immediately below 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.
* driver: Allow -fdebug-compilation-dir=foo in joined form.Nico Weber2020-01-101-0/+6
| | | | | | | All 130+ f_Group flags that take an argument allow it after a '=', except for fdebug-complation-dir. Add a Joined<> alias so that it behaves consistently with all the other f_Group flags. (Keep the old Separate flag for backwards compat.)
* 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.
* Only destroy static locals if they have non-trivial destructors.Richard Smith2020-01-101-1/+2
| | | | | | | This fixes a regression introduced in 2b4fa5348ee157b6b1a1af44d0137ca8c7a71573 that caused us to emit shutdown-time destruction for variables with ARC ownership, using C++-specific functions that don't exist in C implementations.
* Implement new AST matcher hasAnyCapture to match on LambdaExpr captures.Reid2020-01-101-0/+1
| | | | Accepts child matchers cxxThisExpr to match on capture of this and also on varDecl.
* [Driver][PowerPC] Move powerpcspe logic from cc1 to DriverFangrui Song2020-01-102-2/+4
| | | | | | | | | Follow-up of D72014. It is more appropriate to use a target feature instead of a SubTypeArch to express the difference. Reviewed By: #powerpc, jhibbits Differential Revision: https://reviews.llvm.org/D72433
* [clang] Fix out-of-bounds memory access in ComputeLineNumbersJan Korous2020-01-101-13/+8
| | | | Differential Revision: https://reviews.llvm.org/D72409
* [Driver][CodeGen] Add -fpatchable-function-entry=N[,0]Fangrui Song2020-01-104-0/+30
| | | | | | | | | | | In the backend, this feature is implemented with the function attribute "patchable-function-entry". Both the attribute and XRay use TargetOpcode::PATCHABLE_FUNCTION_ENTER, so the two features are incompatible. Reviewed By: ostannard, MaskRay Differential Revision: https://reviews.llvm.org/D72222
* Support function attribute patchable_function_entryFangrui Song2020-01-102-1/+30
| | | | | | | | | 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
* Fix "pointer is null" static analyzer warning. NFCI.Simon Pilgrim2020-01-101-1/+1
| | | | Use castAs<> instead of getAs<> since the pointer is dereferenced immediately below and castAs will perform the null assertion for us.
* Fix "pointer is null" static analyzer warning. NFCI.Simon Pilgrim2020-01-101-1/+1
| | | | Use castAs<> instead of getAs<> since the pointer is dereferenced immediately below and castAs will perform the null assertion for us.
* Fix "pointer is null" static analyzer warning. NFCI.Simon Pilgrim2020-01-101-1/+1
| | | | Use cast<> instead of dyn_cast<> since we know that the pointer should be valid (and is dereferenced immediately).
* [analyzer] Add PlacementNewCheckerGabor Marton2020-01-102-0/+120
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This checker verifies if default placement new is provided with pointers to sufficient storage capacity. Noncompliant Code Example: #include <new> void f() { short s; long *lp = ::new (&s) long; } Based on SEI CERT rule MEM54-CPP https://wiki.sei.cmu.edu/confluence/display/cplusplus/MEM54-CPP.+Provide+placement+new+with+properly+aligned+pointe This patch does not implement checking of the alignment. Reviewers: NoQ, xazax.hun Subscribers: mgorny, whisperity, xazax.hun, baloghadamsoftware, szepet, rnkovacs, a.sidorin, mikhail.ramalho, donat Tags: #clang Differential Revision: https://reviews.llvm.org/D71612
* Add support for __declspec(guard(nocf))Andrew Paverd2020-01-102-0/+33
| | | | | | | | | | | | | | | | | | 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
* [FPEnv] Generate constrained FP comparisons from clangUlrich Weigand2020-01-101-11/+17
| | | | | | | | | | | | | | | | | | | | | Update the IRBuilder to generate constrained FP comparisons in CreateFCmp when IsFPConstrained is true, similar to the other places in the IRBuilder. Also, add a new CreateFCmpS to emit signaling FP comparisons, and use it in clang where comparisons are supposed to be signaling (currently, only when emitting code for the <, <=, >, >= operators). Note that there is currently no way to add fast-math flags to a constrained FP comparison, since this is implemented as an intrinsic call that returns a boolean type, and FMF are only allowed for calls returning a floating-point type. However, given the discussion around https://bugs.llvm.org/show_bug.cgi?id=42179, it seems that FCmp itself really shouldn't have any FMF either, so this is probably OK. Reviewed by: craig.topper Differential Revision: https://reviews.llvm.org/D71467
* [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
* Fix Wdocumentation warning. NFCI.Simon Pilgrim2020-01-101-2/+0
|
* Allow system header to provide their own implementation of some builtinserge-sans-paille2020-01-103-1/+21
| | | | | | | | | | | | | | | | | | If a system header provides an (inline) implementation of some of their function, clang still matches on the function name and generate the appropriate llvm builtin, e.g. memcpy. This behavior is in line with glibc recommendation « users may not provide their own version of symbols » but doesn't account for the fact that glibc itself can provide inline version of some functions. It is the case for the memcpy function when -D_FORTIFY_SOURCE=1 is on. In that case an inline version of memcpy calls __memcpy_chk, a function that performs extra runtime checks. Clang currently ignores the inline version and thus provides no runtime check. This code fixes the issue by detecting functions whose name is a builtin name but also have an inline implementation. Differential Revision: https://reviews.llvm.org/D71082
* [ThinLTO] Pass CodeGenOpts like UnrollLoops/VectorizeLoop/VectorizeSLPWei Mi2020-01-091-0/+6
| | | | | | | | | | | | | down to pass builder in ltobackend. Currently CodeGenOpts like UnrollLoops/VectorizeLoop/VectorizeSLP in clang are not passed down to pass builder in ltobackend when new pass manager is used. This is inconsistent with the behavior when new pass manager is used and thinlto is not used. Such inconsistency causes slp vectorization pass not being enabled in ltobackend for O3 + thinlto right now. This patch fixes that. Differential Revision: https://reviews.llvm.org/D72386
* 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-094-11/+350
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* [Clang] Handle target-specific builtins returning aggregates.Simon Tatham2020-01-091-3/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: A few of the ARM MVE builtins directly return a structure type. This causes an assertion failure at code-gen time if you try to assign the result of the builtin to a variable, because the `RValue` created in `EmitBuiltinExpr` from the `llvm::Value` produced by codegen is always made by `RValue::get()`, which creates a non-aggregate `RValue` that will fail an assertion when `AggExprEmitter::withReturnValueSlot` calls `Src.getAggregatePointer()`. A similar failure occurs if you try to use the struct return value directly to extract one field, e.g. `vld2q(address).val[0]`. The existing code-gen tests for those MVE builtins pass the returned structure type directly to the C `return` statement, which apparently managed to avoid that particular code path, so we didn't notice the crash. Now `EmitBuiltinExpr` checks the evaluation kind of the builtin's return value, and does the necessary handling for aggregate returns. I've added two extra test cases, both of which crashed before this change. Reviewers: dmgreen, rjmccall Reviewed By: rjmccall Subscribers: kristof.beyls, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72271
* Improve support of GNU mempcpyserge-sans-paille2020-01-093-4/+20
| | | | | | | - Lower to the memcpy intrinsic - Raise warnings when size/bounds are known Differential Revision: https://reviews.llvm.org/D71374
OpenPOWER on IntegriCloud