summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaOverload.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix overloaded static functions in SemaCodeCompleteBenjamin Kramer2017-10-261-8/+20
| | | | | | | | | | | | | | | | | | | | | https://bugs.llvm.org/show_bug.cgi?id=33904 Happens when static function is accessed via the class variable. That leads to incorrect overloads number because the variable is considered as the first argument. struct Bar { static void foo(); static void foo(int); }; int main() { Bar b; b.foo(/*complete here*/); // did not work before Bar::foo(/*complete here*/); // worked fine } Patch by Ivan Donchevskii! Differential Revision: https://reviews.llvm.org/D36390 llvm-svn: 316646
* [C++17] Fix PR34970 - tweak overload resolution for class template ↵Faisal Vali2017-10-221-6/+17
| | | | | | | | | | | | | | | | | | | deduction-guides in line with WG21's p0620r0. In order to identify the copy deduction candidate, I considered two approaches: - attempt to determine whether an implicit guide is a copy deduction candidate by checking certain properties of its subsituted parameter during overload-resolution. - using one of the many bits (WillHaveBody) from FunctionDecl (that CXXDeductionGuideDecl inherits from) that are otherwise irrelevant for deduction guides After some brittle gymnastics w the first strategy, I settled on the second, although to avoid confusion and to give that bit a better name, i turned it into a member of an anonymous union. Given this identification 'bit', the tweak to overload resolution was a simple reordering of the deduction guide checks (in SemaOverload.cpp::isBetterOverloadCandidate), in-line with Jason Merrill's p0620r0 drafting which made it into the working paper. Concordant with that, I made sure the copy deduction candidate is always added. References: See https://bugs.llvm.org/show_bug.cgi?id=34970 See http://wg21.link/p0620r0 llvm-svn: 316292
* Fix two-phase name lookup for non-dependent overloaded operators.Richard Smith2017-10-051-7/+9
| | | | | | | | If we resolve an overloaded operator call to a specific function during template definition, don't perform ADL during template instantiation. Doing so finds overloads that we're not supposed to find. llvm-svn: 315005
* Fix uninitialized member found by msan build bot.Richard Smith2017-09-261-1/+1
| | | | llvm-svn: 314246
* Resolve a defect in C++17 copy omission.Richard Smith2017-09-261-29/+57
| | | | | | | | | | | | When selecting constructors for initializing an object of type T from a single expression of class type U, also consider conversion functions of U that convert to T (rather than modeling such conversions as calling a conversion function and then calling a constructor). This approach is proposed as the resolution for the defect, and is also already implemented by GCC. llvm-svn: 314231
* Add support for attribute 'noescape'.Akira Hatanaka2017-09-221-2/+23
| | | | | | | | | | | | | | | | | | | | The attribute informs the compiler that the annotated pointer parameter of a function cannot escape and enables IRGen to attach attribute 'nocapture' to parameters that are annotated with the attribute. That is the only optimization that currently takes advantage of 'noescape', but there are other optimizations that will be added later that improves IRGen for ObjC blocks. This recommits r313722, which was reverted in r313725 because clang couldn't build compiler-rt. It failed to build because there were function declarations that were missing 'noescape'. That has been fixed in r313929. rdar://problem/19886775 Differential Revision: https://reviews.llvm.org/D32210 llvm-svn: 313945
* Revert "Add support for attribute 'noescape'."Akira Hatanaka2017-09-201-23/+2
| | | | | | | | | | This reverts commit r313722. It looks like compiler-rt/lib/tsan/rtl/tsan_libdispatch_mac.cc cannot be compiled because some of the functions declared in the file do not match the ones in the SDK headers (which are annotated with 'noescape'). llvm-svn: 313725
* Add support for attribute 'noescape'.Akira Hatanaka2017-09-201-2/+23
| | | | | | | | | | | | | | | The attribute informs the compiler that the annotated pointer parameter of a function cannot escape and enables IRGen to attach attribute 'nocapture' to parameters that are annotated with the attribute. That is the only optimization that currently takes advantage of 'noescape', but there are other optimizations that will be added later that improves IRGen for ObjC blocks. rdar://problem/19886775 Differential Revision: https://reviews.llvm.org/D32210 llvm-svn: 313722
* Revert "Add support for attribute 'noescape'."Akira Hatanaka2017-09-201-23/+2
| | | | | | | | This reverts r313717. I closed the wrong phabricator review. llvm-svn: 313721
* Add support for attribute 'noescape'.Akira Hatanaka2017-09-201-2/+23
| | | | | | | | | | | | | | | The attribute informs the compiler that the annotated pointer parameter of a function cannot escape and enables IRGen to attach attribute 'nocapture' to parameters that are annotated with the attribute. That is the only optimization that currently takes advantage of 'noescape', but there are other optimizations that will be added later that improves IRGen for ObjC blocks. rdar://problem/19886775 Differential Revision: https://reviews.llvm.org/D32520 llvm-svn: 313720
* [Sema] Mark a virtual CXXMethodDecl as used if a call to it can beAkira Hatanaka2017-07-131-9/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | devirtualized. The code to detect devirtualized calls is already in IRGen, so move the code to lib/AST and make it a shared utility between Sema and IRGen. This commit fixes a linkage error I was seeing when compiling the following code: $ cat test1.cpp struct Base { virtual void operator()() {} }; template<class T> struct Derived final : Base { void operator()() override {} }; Derived<int> *d; int main() { if (d) (*d)(); return 0; } rdar://problem/33195657 Differential Revision: https://reviews.llvm.org/D34301 llvm-svn: 307883
* Customize the SFINAE diagnostics for enable_if to provide the failed condition.Douglas Gregor2017-07-051-0/+9
| | | | | | | | | | | | | | | | | | | | When enable_if disables a particular overload resolution candidate, rummage through the enable_if condition to find the specific condition that caused the failure. For example, if we have something like: template< typename Iter, typename = std::enable_if_t<Random_access_iterator<Iter> && Comparable<Iterator_value_type<Iter>>>> void mysort(Iter first, Iter last) {} and we call "mysort" with "std::list<int>" iterators, we'll get a diagnostic saying that the "Random_access_iterator<Iter>" requirement failed. If we call "mysort" with "std::vector<something_not_comparable>", we'll get a diagnostic saying that the "Comparable<...>" requirement failed. llvm-svn: 307196
* [Sema] Refactor OverloadCandidate::BuiltinTypes. NFC.George Burgess IV2017-06-081-16/+14
| | | | | | As promised in r304996. llvm-svn: 305013
* [Sema] Remove unused field from OverloadCandidate.George Burgess IV2017-06-081-144/+50
| | | | | | | | | | | | | | | | | | The only use in-tree I can find for BuiltinTypes.ResultTy is a single store to it. We otherwise just recompute what it should be later on (and sometimes do things like argument conversions in the process of recomputing it). Since it's impossible to test if the value stored there is sane, and we don't use it anyway, we should probably just drop the field. I'll do a follow-up patch to rename BuiltinTypes.ParamTypes -> BuiltinParamTypes in a bit. Wanted to keep this patch relatively minimal. Thanks to Petr Kudryavtsev for bringing this up! llvm-svn: 304996
* Strip trailing whitespace. NFCI.Simon Pilgrim2017-06-011-147/+147
| | | | llvm-svn: 304445
* Remove late nullptr pointer test (PR32447)Simon Pilgrim2017-06-011-2/+2
| | | | | | IgnoreNarrowingConversion should never return nullptr, but I've added an assert just in case. llvm-svn: 304444
* Enhance the 'diagnose_if' attribute so that we can apply it for ObjC methods ↵Argyrios Kyrtzidis2017-05-241-5/+5
| | | | | | | | and properties as well This is an initial commit to allow using it with constant expressions, a follow-up commit will enable full support for it in ObjC methods. llvm-svn: 303712
* [Sema] Make typeof(OverloadedFunctionName) not a pointer.George Burgess IV2017-05-091-3/+3
| | | | | | | | | | | | | | | | We were sometimes doing a function->pointer conversion in Sema::CheckPlaceholderExpr, which isn't the job of CheckPlaceholderExpr. So, when we saw typeof(OverloadedFunctionName), where OverloadedFunctionName referenced a name with only one function that could have its address taken, we'd give back a function pointer type instead of a function type. This is incorrect. I kept the logic for doing the function pointer conversion in resolveAndFixAddressOfOnlyViableOverloadCandidate because it was more consistent with existing ResolveAndFix* methods. llvm-svn: 302506
* [Modules] Fix a crash-on-invalid with overloaded functionsBruno Cardoso Lopes2017-04-261-0/+4
| | | | | | | | | | Do not add an overload if the function doesn't have a prototype; this can happen if, for instance, a misplaced/malformed call site is considered like a declaration for recovery purposes. rdar://problem/31306325 llvm-svn: 301453
* [OpenCL] Map default address space to alloca address spaceYaxun Liu2017-04-111-1/+2
| | | | | | | | | | | | | | For OpenCL, the private address space qualifier is 0 in AST. Before this change, 0 address space qualifier is always mapped to target address space 0. As now target private address space is specified by alloca address space in data layout, address space qualifier 0 needs to be mapped to alloca addr space specified by the data layout. This change has no impact on targets whose alloca addr space is 0. With contributions from Matt Arsenault, Tony Tye and Wen-Heng (Jack) Chung Differential Revision: https://reviews.llvm.org/D31404 llvm-svn: 299965
* [ObjC++] Conversions from specialized to non-specialized Objective-C genericAlex Lorenz2017-04-061-3/+17
| | | | | | | | | | | | | | | | | | | object types should be preferred over conversions to other object pointers This change ensures that Clang will select the correct overload for the following code sample: void overload(Base *b); void overload(Derived *d); void test(Base<Base *> b) { overload(b); // Select overload(Base *), not overload(Derived *) } rdar://20124827 Differential Revision: https://reviews.llvm.org/D31597 llvm-svn: 299648
* [Sema] Update CheckOverload docsGeorge Burgess IV2017-04-061-34/+33
| | | | | | | | | | | - Replace documented return values (true/false) with what's actually returned - Doxygenify the comment - Reflow said comment to 80 cols Not overly familiar with Doxygen, so nits are welcome. :) llvm-svn: 299603
* [NFC, Scoped Enum] Convert Sema::ExpressionEvaluationContext into a scoped EnumFaisal Vali2017-04-011-6/+12
| | | | | | | | - also replace direct equality checks against the ConstantEvaluated enumerator with isConstantEvaluted(), in anticipation of adding finer granularity to the various ConstantEvaluated contexts and reinstating certain restrictions on where lambda expressions can occur in C++17. - update the clang tablegen backend that uses these Enumerators, and add the relevant scope where needed. llvm-svn: 299316
* [libclang] Fix crash in member access code completion with implicit baseErik Verbruggen2017-03-281-11/+26
| | | | | | | | | | If there is an unresolved member access AST node, and the base is implicit, do not access/use it for generating candidate overloads for code completion results. Fixes PR31093. llvm-svn: 298903
* Encapsulate FPOptions and use it consistentlyAdam Nemet2017-03-271-10/+10
| | | | | | | | | | | | | | | | | | Sema holds the current FPOptions which is adjusted by 'pragma STDC FP_CONTRACT'. This then gets propagated into expression nodes as they are built. This encapsulates FPOptions so that this propagation happens opaquely rather than directly with the fp_contractable on/off bit. This allows controlled transitioning of fp_contractable to a ternary value (off, on, fast). It will also allow adding more fast-math flags later. This is toward moving fp-contraction=fast from an LLVM TargetOption to a FastMathFlag in order to fix PR25721. Differential Revision: https://reviews.llvm.org/D31166 llvm-svn: 298877
* [OpenCL] Added implicit conversion rank for overloading functions with ↵Egor Churaev2017-03-211-1/+1
| | | | | | | | | | | | | | | | vector data type in OpenCL Summary: I added a new rank to ImplicitConversionRank enum to resolve the function overload ambiguity with vector types. Rank of scalar types conversion is lower than vector splat. So, we can choose which function should we call. See test for more details. Reviewers: Anastasia, cfe-commits Reviewed By: Anastasia Subscribers: bader, yaxunl Differential Revision: https://reviews.llvm.org/D30816 llvm-svn: 298366
* Factor out function to determine whether we're performing a templateRichard Smith2017-02-211-1/+1
| | | | | | | | | instantiation. In preparation for converting the template stack to a more general context stack (so we can include context notes for other kinds of context). llvm-svn: 295686
* Add an explicit derived class of FunctionDecl to model deduction guides ratherRichard Smith2017-02-171-6/+4
| | | | | | | | than just treating them as FunctionDecls with a funny name. No functionality change intended. llvm-svn: 295491
* [c++1z] Synthesize implicit deduction guides from constructors on demand. RankRichard Smith2017-02-141-0/+8
| | | | | | | | | | | | | | | | | | | such guides below explicit ones, and ensure that references to the class's template parameters are not treated as forwarding references. We make a few tweaks to the wording in the current standard: 1) The constructor parameter list is copied faithfully to the deduction guide, without losing default arguments or a varargs ellipsis (which the standard wording loses by omission). 2) If the class template declares no constructors, we add a T() -> T<...> guide (which will only ever work if T has default arguments for all non-pack template parameters). 3) If the class template declares nothing that looks like a copy or move constructor, we add a T(T<...>) -> T<...> guide. #2 and #3 follow from the "pretend we had a class type with these constructors" philosophy for deduction guides. llvm-svn: 295007
* Change how we handle diagnose_if attributes.George Burgess IV2017-01-281-187/+98
| | | | | | | | | | | | | This patch changes how we handle argument-dependent `diagnose_if` attributes. In particular, we now check them in the same place that we check for things like passing NULL to Nonnull args, etc. This is basically better in every way than how we were handling them before. :) This fixes PR31638, PR31639, and PR31640. Differential Revision: https://reviews.llvm.org/D28889 llvm-svn: 293360
* Fix a typo. NFC.George Burgess IV2017-01-141-1/+1
| | | | llvm-svn: 291997
* PR31606: Generalize our tentative DR resolution for inheriting copy/moveRichard Smith2017-01-131-26/+28
| | | | | | constructors to better match the pre-P0136R1 behavior. llvm-svn: 291955
* Don't try to check implicit conversion sequences for an object argument ifRichard Smith2017-01-101-2/+8
| | | | | | | there is no object argument, when early checking of implicit conversion sequences for a function template fails. llvm-svn: 291597
* Fix conversion index / argument index mismatch when diagnosing overload ↵Richard Smith2017-01-101-32/+18
| | | | | | resolution failure. llvm-svn: 291596
* Implement C++ DR1391 (wg21.link/cwg1391)Richard Smith2017-01-091-77/+184
| | | | | | | | | | | | | | Check for implicit conversion sequences for non-dependent function template parameters between deduction and substitution. The idea is to accept as many cases as possible, on the basis that substitution failure outside the immediate context is much more common during substitution than during implicit conversion sequence formation. This re-commits r290808, reverted in r290811 and r291412, with a couple of fixes for handling of explicitly-specified non-trailing template argument packs. llvm-svn: 291427
* Add the diagnose_if attribute to clang.George Burgess IV2017-01-091-78/+266
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | `diagnose_if` can be used to have clang emit either warnings or errors for function calls that meet user-specified conditions. For example: ``` constexpr int foo(int a) __attribute__((diagnose_if(a > 10, "configurations with a > 10 are " "expensive.", "warning"))); int f1 = foo(9); int f2 = foo(10); // warning: configuration with a > 10 are expensive. int f3 = foo(f2); ``` It currently only emits diagnostics in cases where the condition is guaranteed to always be true. So, the following code will emit no warnings: ``` constexpr int bar(int a) { foo(a); return 0; } constexpr int i = bar(10); ``` We hope to support optionally emitting diagnostics for cases like that (and emitting runtime checks) in the future. Release notes will appear shortly. :) Differential Revision: https://reviews.llvm.org/D27424 llvm-svn: 291418
* Revert r291410 and r291411.Richard Smith2017-01-091-183/+75
| | | | | | The test-suite bots are still failing even after r291410's fix. llvm-svn: 291412
* Implement C++ DR1391 (wg21.link/cwg1391)Richard Smith2017-01-091-75/+183
| | | | | | | | | | | | | Check for implicit conversion sequences for non-dependent function template parameters between deduction and substitution. The idea is to accept as many cases as possible, on the basis that substitution failure outside the immediate context is much more common during substitution than during implicit conversion sequence formation. This re-commits r290808, reverted in r290811, with a fix for handling of explicitly-specified template argument packs. llvm-svn: 291410
* PR30305: Implement proposed DR resolution to prevent slicing via inherited ↵Richard Smith2017-01-081-0/+31
| | | | | | | | | | | | constructor. The rule we use is that a construction of a class type T from an argument of type U cannot use an inherited constructor if U is the same as T or is derived from T (or if the initialization would first convert it to such a type). This (approximately) matches the rule in use by GCC, and matches the current proposed DR resolution. llvm-svn: 291403
* Add missing "original call argument has same type as deduced parameter type"Richard Smith2017-01-051-6/+18
| | | | | | check for deductions from elements of a braced-init-list. llvm-svn: 291190
* Fix failure to treat overloaded function in braced-init-list as a ↵Richard Smith2017-01-041-26/+0
| | | | | | | | | | | | | non-deduced context. Previously, if an overloaded function in a braced-init-list was encountered in template argument deduction, and the overload set couldn't be resolved to a particular function, we'd immediately produce a deduction failure. That's not correct; this situation is supposed to result in that particular P/A pair being treated as a non-deduced context, and deduction can still succeed if the type can be deduced from elsewhere. llvm-svn: 291014
* [Sema] Replace remove_if+erase with erase_if. NFC.George Burgess IV2017-01-041-3/+1
| | | | llvm-svn: 290991
* Revert "DR1391: Check for implicit conversion sequences for non-dependent ↵Renato Golin2017-01-021-182/+75
| | | | | | | | | | | | | | function template parameters between deduction and substitution. The idea is to accept as many cases as possible, on the basis that substitution failure outside the immediate context is much more common during substitution than during implicit conversion sequence formation." This reverts commit r290808, as it broken all ARM and AArch64 test-suite test: MultiSource/UnitTests/C++11/frame_layout Also, please, next time, try to write a commit message in according to our guidelines: http://llvm.org/docs/DeveloperPolicy.html#commit-messages llvm-svn: 290811
* DR1391: Check for implicit conversion sequences for non-dependent functionRichard Smith2017-01-021-75/+182
| | | | | | | | | | | | template parameters between deduction and substitution. The idea is to accept as many cases as possible, on the basis that substitution failure outside the immediate context is much more common during substitution than during implicit conversion sequence formation. This does not implement the partial ordering portion of DR1391, which so far appears to be misguided. llvm-svn: 290808
* Check and build conversion sequences for non-type template arguments inRichard Smith2016-12-271-1/+1
| | | | | | | dependent contexts when processing the template in C++11 and C++14, just like we do in C++98 and C++1z. This allows us to diagnose invalid templates earlier. llvm-svn: 290567
* Fix problems in "[OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare ↵Egor Churaev2016-12-231-0/+6
| | | | | | | | | | | | | | operand." Summary: Fixed warnings in commit: https://reviews.llvm.org/rL290171 Reviewers: djasper, Anastasia Subscribers: yaxunl, cfe-commits, bader Differential Revision: https://reviews.llvm.org/D27981 llvm-svn: 290431
* When merging two deduced non-type template arguments for the same parameter,Richard Smith2016-12-231-2/+18
| | | | | | | | | | | | | | | | | | | fail the merge if the arguments have different types (except if one of them was deduced from an array bound, in which case take the type from the other). This is correct because (except in the array bound case) the type of the template argument in each deduction must match the type of the parameter, so at least one of the two deduced arguments must have a mismatched type. This is necessary because we would otherwise lose the type information for the discarded template argument in the merge, and fail to diagnose the mismatch. In order to power this, we now properly retain the type of a deduced non-type template argument deduced from a declaration, rather than giving it the type of the template parameter; we'll convert it to the template parameter type when checking the deduced arguments. llvm-svn: 290399
* Sema: print qualified name for overload candidatesSaleem Abdulrasool2016-12-221-1/+1
| | | | | | | | | | | | | Print the fully qualified names for the overload candidates. This makes it easier to tell what the ambiguity is. Especially if a template is instantiated after a using namespace, it will not inherit the namespace where it was declared. The specialization will give a message about a partial order being ambiguous for the same (unqualified) name, which does not help identify the failure. Addresses PR31450! llvm-svn: 290315
* Perform type-checking for a converted constant expression in a templateRichard Smith2016-12-211-0/+23
| | | | | | | | | | | argument even if the expression is value-dependent (we need to suppress the final portion of the narrowing check, but the rest of the checking can still be done eagerly). This affects template template argument validity and partial ordering under p0522r0. llvm-svn: 290276
* [c++1z] P0195R2: Support pack-expansion of using-declarations.Richard Smith2016-12-201-1/+7
| | | | | | | | | | | | | | This change introduces UsingPackDecl as a marker for the set of UsingDecls produced by pack expansion of a single (unresolved) using declaration. This is not strictly necessary (we just need to be able to map from the original using declaration to its expansions somehow), but it's useful to maintain the invariant that each declaration reference instantiates to refer to one declaration. This is a re-commit of r290080 (reverted in r290092) with a fix for a use-after-lifetime bug. llvm-svn: 290203
OpenPOWER on IntegriCloud