Commit Graph

13 Commits

Author SHA1 Message Date
Sylvestre Ledru 1f63b7e099 Update the tests to match the typo fix done in r292015
llvm-svn: 292016
2017-01-14 12:00:40 +00:00
George Burgess IV 53b938da5a [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.

llvm-svn: 278471
2016-08-12 04:12:31 +00:00
Aaron Ballman 781fda9387 Add the Pure attribute to C99 builtin functions from ctype.h. This is a corrected version of r266199 with test case fixes.
Patch by Taewook Oh.

llvm-svn: 268553
2016-05-04 21:08:13 +00:00
Aaron Ballman fd00f48fba Reverting r266199; it causes build bot failures.
http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/3255
http://lab.llvm.org:8011/builders/clang-ppc64be-linux/builds/3517  

llvm-svn: 266201
2016-04-13 14:53:52 +00:00
Aaron Ballman 4fb7f509fd Add functions declared in ctype.h to builtin function database. All functions are annotated with nothrow and pure attribute, which enables better optimization.
Patch by Taewook Oh.

llvm-svn: 266199
2016-04-13 13:55:58 +00:00
George Burgess IV 21d3bffe29 [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.

llvm-svn: 264975
2016-03-31 00:16:25 +00:00
George Burgess IV c3ec9508ea 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.

llvm-svn: 254646
2015-12-03 20:54:58 +00:00
George Burgess IV 2a6150d932 [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

llvm-svn: 250486
2015-10-16 01:17:38 +00:00
George Burgess IV 5f21c71800 [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

llvm-svn: 250090
2015-10-12 19:57:04 +00:00
Ulrich Weigand ef5aa29e12 Support alternate attribute spelling __enable_if__
Attribute names usually support an alternate spelling that uses double
underscores before and after the attribute name, like e.g. attribute
((__aligned__)) for attribute ((aligned)). This is necessary to allow
use of attributes in system headers without polluting the name space.

However, for attribute ((enable_if)) that alternate spelling does not
work correctly. This is because of code in Parser::ParseGNUAttributeArgs
(ParseDecl.cpp) that specifically checks for the "enable_if" spelling
without allowing the alternate spelling.

Similar code in ParseDecl.cpp uses the normalizeAttrName helper to allow
both spellings. This patch adds use of that helper for the "enable_if"
check as well, which fixes attribute ((__enable_if__)).

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

llvm-svn: 242029
2015-07-13 14:13:01 +00:00
David Blaikie ea3e51d73f Account for calling convention specifiers in function definitions in IR test cases
Several tests wouldn't pass when executed on an armv7a_pc_linux triple
due to the non-default arm_aapcs calling convention produced on the
function definitions in the IR output. Account for this with the
application of a little regex.

Patch by Ying Yi.

llvm-svn: 240971
2015-06-29 17:29:50 +00:00
Nick Lewycky 36e9b3ccff Neither attribute overloadable nor enable_if are supported by GCC. Disable the
GCC warning about attributes on function definitions for both of them.

llvm-svn: 199710
2014-01-21 04:31:12 +00:00
Nick Lewycky 35a6ef4c35 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.
llvm-svn: 198996
2014-01-11 02:50:57 +00:00