Commit Graph

20 Commits

Author SHA1 Message Date
George Burgess IV 432ed0e4a6 [Sema] Make typeof(OverloadedFunctionName) not a pointer.
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.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302506 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-09 04:06:24 +00:00
George Burgess IV 3915a28878 Fix PR31934: forming refs to functions with enable_if attrs.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@300283 91177308-0d34-0410-b5e6-96231b3b80d8
2017-04-13 23:47:08 +00:00
Sylvestre Ledru 4113595f39 Update the tests to match the typo fix done in r292015
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@292016 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-14 12:00:40 +00:00
Richard Smith 8c96c95c2a Consistently use a ConstantEvaluated context for expressions in attributes,
except for those with the "attributes are unevaluated contexts" flag.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@291358 91177308-0d34-0410-b5e6-96231b3b80d8
2017-01-07 19:42:26 +00:00
George Burgess IV 62c5024ae0 [Sema] Fix a bug in enable_if condition instantiation.
During template instantiation, we currently fall back to just calling
Sema::SubstExpr for enable_if attributes that aren't value-dependent or
type-dependent. Since Sema::SubstExpr strips off any implicit casts
we've added to an expression, it's possible that this behavior will
leave us with an enable_if condition that's just a DeclRefExpr.
Conditions like that deeply confuse Sema::CheckEnableIf.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@287187 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-17 01:33:54 +00:00
George Burgess IV 7f520610a9 Use the member function location in enable_if diagnostics.
Before:
<stdin>:3:3: error: no matching member function for call to 'bar'
  Foo().bar();
  ^

After:
<stdin>:3:9: error: no matching member function for call to 'bar'
  Foo().bar();
        ^


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@287154 91177308-0d34-0410-b5e6-96231b3b80d8
2016-11-16 21:31:25 +00:00
George Burgess IV d6290c5e5b [Sema] Fix a crash on variadic enable_if functions.
Currently, when trying to evaluate an enable_if condition, we try to
evaluate all arguments a user passes to a function. Given that we can't
use variadic arguments from said condition anyway, not converting them
is a reasonable thing to do. So, this patch makes us ignore any varargs
when attempting to check an enable_if condition.

We'd crash because, in order to convert an argument, we need its
ParmVarDecl. Variadic arguments don't have ParmVarDecls.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@278471 91177308-0d34-0410-b5e6-96231b3b80d8
2016-08-12 04:12:31 +00:00
George Burgess IV ddc91cf172 [Sema] Fix value-dependent enable_if bug.
This patch fixes a bug where we would assume all value-dependent
enable_if conditions give successful results.

Instead, we consider value-dependent enable_if conditions to always
fail. While this isn't ideal, this is the best we can realistically do
without changing both enable_if's semantics and large parts of Sema
(specifically, all of the parts that don't expect type dependence to
come out of nowhere, and that may interact with overload resolution).

Differential Revision: http://reviews.llvm.org/D20130


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@269154 91177308-0d34-0410-b5e6-96231b3b80d8
2016-05-11 01:38:27 +00:00
George Burgess IV 7bbc253b7d [Sema] Fix PR27122: ICE with enable_if+ill-formed call.
In some cases, when we encounter a direct function call with an
incorrect number of arguments, we'll emit a diagnostic, and pretend that
the call to the function was valid. For example, in C:

int foo();
int a = foo(1);

Prior to this patch, we'd get an ICE if foo had an enable_if attribute,
because CheckEnableIf assumes that the number of arguments it gets
passed is valid for the function it's passed. Now, we check that the
number of args looks valid prior to checking enable_if conditions.

This fix was not done inside of CheckEnableIf because the problem
presently can only occur in one caller of CheckEnableIf (ActOnCallExpr).
Additionally, checking inside of CheckEnableIf would make us emit
multiple diagnostics for the same error (one "enable_if failed", one
"you gave this function the wrong number of arguments"), which seems
worse than just complaining about the latter.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264975 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-31 00:16:25 +00:00
George Burgess IV e754ecb43b [Sema] Allow casting of some overloaded functions
Some functions can't have their address taken. If we encounter an
overload set where only one of the candidates can have its address
taken, we should automatically select that candidate in cast
expressions.

Differential Revision: http://reviews.llvm.org/D17701


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@263887 91177308-0d34-0410-b5e6-96231b3b80d8
2016-03-19 21:36:10 +00:00
George Burgess IV f13bdea040 Add tests for `&enable_if_function` diagnostics.
The introduction of pass_object_size fixed a few bugs related to taking
the address of a function with enable_if attributes. This patch adds
tests for the cases that were fixed.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254646 91177308-0d34-0410-b5e6-96231b3b80d8
2015-12-03 20:54:58 +00:00
Richard Smith a5042dfafa [modules] Rationalize the behavior of Decl::declarationReplaces, and in
particular don't assume that two declarations of the same kind in the same
context are declaring the same entity. That's not true when the same name is
declared multiple times as internal-linkage symbols within a module.
(getCanonicalDecl is cheap now, so we can just use it here.)


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@251898 91177308-0d34-0410-b5e6-96231b3b80d8
2015-11-03 03:13:11 +00:00
George Burgess IV 3947fa32ce [Sema] Fix address-of + enable_if overloading logic
Previously, our logic when taking the address of an overloaded function
would not consider enable_if attributes, so long as all of the enable_if
conditions on a given candidate were true. So, two functions with
identical signatures (one with enable_if attributes, the other without),
would be considered equally good overloads. If we were calling the
function instead of taking its address, then the function with enable_if
attributes would be preferred.

This patch makes us prefer the candidate with enable_if regardless of if
we're calling or taking the address of an overloaded function.

Differential Revision: http://reviews.llvm.org/D13795


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250486 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-16 01:17:38 +00:00
George Burgess IV ef378def97 [Sema] Make `&function_with_enable_if_attrs` an error
This fixes a bug where one can take the address of a conditionally
enabled function to drop its enable_if guards. For example:

  int foo(int a) __attribute__((enable_if(a > 0, "")));
  int (*p)(int) = &foo;
  int result = p(-1); // compilation succeeds; calls foo(-1)

Overloading logic has been updated to reflect this change, as well.

Functions with enable_if attributes that are always true are still
allowed to have their address taken.

Differential Revision: http://reviews.llvm.org/D13607


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@250090 91177308-0d34-0410-b5e6-96231b3b80d8
2015-10-12 19:57:04 +00:00
George Burgess IV 696b42a4c2 Make incomplete type errors better with enable_if
This patch fixes the order in which we evaluate the different ways that
a function call could be disallowed. Now, if you call a non-overloaded
function with an incomplete type and failing enable_if, we'll prioritize
reporting the more obvious error (use of incomplete type) over reporting
the failing enable_if.

Thanks to Ettore Speziale for the patch!



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248595 91177308-0d34-0410-b5e6-96231b3b80d8
2015-09-25 17:53:16 +00:00
Nick Lewycky 51b3ec3821 Make sure that we evaluate __attribute__((enable_if)) on a method with no overloads. Patch by Ettore Speziale!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245985 91177308-0d34-0410-b5e6-96231b3b80d8
2015-08-25 22:33:16 +00:00
Nick Lewycky 801b1a5ab4 Improve handling of value dependent expressions in __attribute__((enable_if)), both in the condition expression and at the call site. Fixes PR20988!
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@224320 91177308-0d34-0410-b5e6-96231b3b80d8
2014-12-16 06:12:01 +00:00
Nick Lewycky 16487a6e0e Fix crash with enable_if on constructors.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202467 91177308-0d34-0410-b5e6-96231b3b80d8
2014-02-28 05:26:13 +00:00
Nick Lewycky eb9453dbbe Neither attribute overloadable nor enable_if are supported by GCC. Disable the
GCC warning about attributes on function definitions for both of them.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@199710 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-21 04:31:12 +00:00
Nick Lewycky c8cd634957 Add a new attribute 'enable_if' which can be used to control overload resolution based on the values of the function arguments at the call site.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@198996 91177308-0d34-0410-b5e6-96231b3b80d8
2014-01-11 02:50:57 +00:00