/* Checks for a builtin function FNDECL that the number of arguments
NARGS against the required number REQUIRED and issues an error if
there is a mismatch. Returns true if the number of arguments is
- correct, otherwise false. */
+ correct, otherwise false. LOC is the location of FNDECL. */
static bool
-builtin_function_validate_nargs (tree fndecl, int nargs, int required)
+builtin_function_validate_nargs (location_t loc, tree fndecl, int nargs,
+ int required)
{
if (nargs < required)
{
- error_at (input_location,
- "not enough arguments to function %qE", fndecl);
+ error_at (loc, "not enough arguments to function %qE", fndecl);
return false;
}
else if (nargs > required)
{
- error_at (input_location,
- "too many arguments to function %qE", fndecl);
+ error_at (loc, "too many arguments to function %qE", fndecl);
return false;
}
return true;
}
+/* Helper macro for check_builtin_function_arguments. */
+#define ARG_LOCATION(N) \
+ (arg_loc.is_empty () \
+ ? EXPR_LOC_OR_LOC (args[(N)], input_location) \
+ : expansion_point_location (arg_loc[(N)]))
+
/* Verifies the NARGS arguments ARGS to the builtin function FNDECL.
- Returns false if there was an error, otherwise true. */
+ Returns false if there was an error, otherwise true. LOC is the
+ location of the function; ARG_LOC is a vector of locations of the
+ arguments. */
bool
-check_builtin_function_arguments (tree fndecl, int nargs, tree *args)
+check_builtin_function_arguments (location_t loc, vec<location_t> arg_loc,
+ tree fndecl, int nargs, tree *args)
{
if (!DECL_BUILT_IN (fndecl)
|| DECL_BUILT_IN_CLASS (fndecl) != BUILT_IN_NORMAL)
/* The maximum alignment in bits corresponding to the same
maximum in bytes enforced in check_user_alignment(). */
unsigned maxalign = (UINT_MAX >> 1) + 1;
-
+
/* Reject invalid alignments. */
if (align < BITS_PER_UNIT || maxalign < align)
{
- error_at (EXPR_LOC_OR_LOC (args[1], input_location),
+ error_at (ARG_LOCATION (1),
"second argument to function %qE must be a constant "
"integer power of 2 between %qi and %qu bits",
fndecl, BITS_PER_UNIT, maxalign);
return false;
}
- return true;
+ return true;
}
case BUILT_IN_CONSTANT_P:
- return builtin_function_validate_nargs (fndecl, nargs, 1);
+ return builtin_function_validate_nargs (loc, fndecl, nargs, 1);
case BUILT_IN_ISFINITE:
case BUILT_IN_ISINF:
case BUILT_IN_ISNAN:
case BUILT_IN_ISNORMAL:
case BUILT_IN_SIGNBIT:
- if (builtin_function_validate_nargs (fndecl, nargs, 1))
+ if (builtin_function_validate_nargs (loc, fndecl, nargs, 1))
{
if (TREE_CODE (TREE_TYPE (args[0])) != REAL_TYPE)
{
- error ("non-floating-point argument in call to "
- "function %qE", fndecl);
+ error_at (ARG_LOCATION (0), "non-floating-point argument in "
+ "call to function %qE", fndecl);
return false;
}
return true;
case BUILT_IN_ISLESSEQUAL:
case BUILT_IN_ISLESSGREATER:
case BUILT_IN_ISUNORDERED:
- if (builtin_function_validate_nargs (fndecl, nargs, 2))
+ if (builtin_function_validate_nargs (loc, fndecl, nargs, 2))
{
enum tree_code code0, code1;
code0 = TREE_CODE (TREE_TYPE (args[0]));
|| (code0 == REAL_TYPE && code1 == INTEGER_TYPE)
|| (code0 == INTEGER_TYPE && code1 == REAL_TYPE)))
{
- error ("non-floating-point arguments in call to "
- "function %qE", fndecl);
+ error_at (loc, "non-floating-point arguments in call to "
+ "function %qE", fndecl);
return false;
}
return true;
return false;
case BUILT_IN_FPCLASSIFY:
- if (builtin_function_validate_nargs (fndecl, nargs, 6))
+ if (builtin_function_validate_nargs (loc, fndecl, nargs, 6))
{
- unsigned i;
-
- for (i=0; i<5; i++)
+ for (unsigned int i = 0; i < 5; i++)
if (TREE_CODE (args[i]) != INTEGER_CST)
{
- error ("non-const integer argument %u in call to function %qE",
- i+1, fndecl);
+ error_at (ARG_LOCATION (i), "non-const integer argument %u in "
+ "call to function %qE", i + 1, fndecl);
return false;
}
if (TREE_CODE (TREE_TYPE (args[5])) != REAL_TYPE)
{
- error ("non-floating-point argument in call to function %qE",
- fndecl);
+ error_at (ARG_LOCATION (5), "non-floating-point argument in "
+ "call to function %qE", fndecl);
return false;
}
return true;
return false;
case BUILT_IN_ASSUME_ALIGNED:
- if (builtin_function_validate_nargs (fndecl, nargs, 2 + (nargs > 2)))
+ if (builtin_function_validate_nargs (loc, fndecl, nargs, 2 + (nargs > 2)))
{
if (nargs >= 3 && TREE_CODE (TREE_TYPE (args[2])) != INTEGER_TYPE)
{
- error ("non-integer argument 3 in call to function %qE", fndecl);
+ error_at (ARG_LOCATION (2), "non-integer argument 3 in call to "
+ "function %qE", fndecl);
return false;
}
return true;
case BUILT_IN_ADD_OVERFLOW:
case BUILT_IN_SUB_OVERFLOW:
case BUILT_IN_MUL_OVERFLOW:
- if (builtin_function_validate_nargs (fndecl, nargs, 3))
+ if (builtin_function_validate_nargs (loc, fndecl, nargs, 3))
{
unsigned i;
for (i = 0; i < 2; i++)
if (!INTEGRAL_TYPE_P (TREE_TYPE (args[i])))
{
- error ("argument %u in call to function %qE does not have "
- "integral type", i + 1, fndecl);
+ error_at (ARG_LOCATION (i), "argument %u in call to function "
+ "%qE does not have integral type", i + 1, fndecl);
return false;
}
if (TREE_CODE (TREE_TYPE (args[2])) != POINTER_TYPE
|| TREE_CODE (TREE_TYPE (TREE_TYPE (args[2]))) != INTEGER_TYPE)
{
- error ("argument 3 in call to function %qE does not have "
- "pointer to integer type", fndecl);
+ error_at (ARG_LOCATION (2), "argument 3 in call to function %qE "
+ "does not have pointer to integer type", fndecl);
return false;
}
return true;
--- /dev/null
+/* PR c/70859 */
+/* { dg-do compile } */
+
+static void *p;
+static double *d;
+static int r;
+__extension__ static _Bool b;
+
+void
+fn0 (int n)
+{
+ p = __builtin_alloca_with_align (n, 6); /* { dg-error "39:must be a constant integer" } */
+
+ r += __builtin_isfinite (0); /* { dg-error "28:non-floating-point argument in call" } */
+ r += __builtin_isinf (0); /* { dg-error "25:non-floating-point argument in call" } */
+ r += __builtin_isinf_sign (0); /* { dg-error "30:non-floating-point argument in call" } */
+ r += __builtin_isnan (0); /* { dg-error "25:non-floating-point argument in call" } */
+ r += __builtin_isnormal (0); /* { dg-error "28:non-floating-point argument in call" } */
+ r += __builtin_signbit (0); /* { dg-error "27:non-floating-point argument in call" } */
+
+ r += __builtin_isgreater (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */
+ r += __builtin_isgreaterequal (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */
+ r += __builtin_isless (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */
+ r += __builtin_islessequal (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */
+ r += __builtin_islessgreater (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */
+ r += __builtin_isunordered (0, 0); /* { dg-error "8:non-floating-point arguments in call to function" } */
+
+ r += __builtin_fpclassify (1, 2, n, 4, 5, n); /* { dg-error "36:non-const integer argument 3 in call" } */
+ r += __builtin_fpclassify (1, 2, 3, 4, 5, 6); /* { dg-error "45:non-floating-point argument in call" } */
+
+ d = __builtin_assume_aligned (p, n, p); /* { dg-error "39:non-integer argument 3 in call" } */
+
+ b = __builtin_add_overflow (n, *d, &r); /* { dg-error "34:argument 2 in call to function" } */
+ b = __builtin_add_overflow (n, 5, d); /* { dg-error "37:argument 3 in call" } */
+ b = __builtin_sub_overflow (n, *d, &r); /* { dg-error "34:argument 2 in call to function" } */
+ b = __builtin_sub_overflow (n, 5, d); /* { dg-error "37:argument 3 in call" } */
+ b = __builtin_mul_overflow (n, *d, &r); /* { dg-error "34:argument 2 in call to function" } */
+ b = __builtin_mul_overflow (n, 5, d); /* { dg-error "37:argument 3 in call" } */
+}
+
+int
+fn1 (void)
+{
+ if (__builtin_constant_p ()) /* { dg-error "7:not enough" } */
+ return 0;
+ if (__builtin_constant_p (1, 2)) /* { dg-error "7:too many" } */
+ return 1;
+ if (__builtin_isfinite ()) /* { dg-error "7:not enough" } */
+ return 3;
+ if (__builtin_isfinite (1, 2)) /* { dg-error "7:too many" } */
+ return 4;
+ if (__builtin_isless (0)) /* { dg-error "7:not enough" } */
+ return 5;
+ if (__builtin_isless (1, 2, 3)) /* { dg-error "7:too many" } */
+ return 6;
+ if (__builtin_fpclassify (1, 2, 3, 4, 5)) /* { dg-error "7:not enough" } */
+ return 7;
+ if (__builtin_fpclassify (1, 2, 3, 4, 5, r, 6)) /* { dg-error "7:too many" } */
+ return 8;
+ if (__builtin_assume_aligned (p)) /* { dg-error "7:too few" } */
+ return 9;
+ if (__builtin_assume_aligned (p, r, p, p)) /* { dg-error "7:too many" } */
+ return 10;
+ if (__builtin_add_overflow ()) /* { dg-error "7:not enough" } */
+ return 11;
+ if (__builtin_add_overflow (1, 2, 3, &r)) /* { dg-error "7:too many" } */
+ return 12;
+ return -1;
+}