]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
builtins.c (fold_builtin_1): Verify the argument types of BUILT_IN_ISNORMAL.
authorRichard Guenther <rguenther@suse.de>
Tue, 27 Nov 2007 12:30:15 +0000 (12:30 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 27 Nov 2007 12:30:15 +0000 (12:30 +0000)
2007-11-27  Richard Guenther  <rguenther@suse.de>

* builtins.c (fold_builtin_1): Verify the argument types
of BUILT_IN_ISNORMAL.
(fold_builtin_n): Verify the number of arguments to variadic
built-in functions.

* gcc.dg/builtins-error.c: New testcase.

From-SVN: r130465

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/builtins-error.c [new file with mode: 0644]

index 0916b1c7d9256cceb356a6b31af260e2cf5c571a..86f1f6978b929938bb4cedc17385c2a797cea350 100644 (file)
@@ -1,3 +1,10 @@
+2007-11-27  Richard Guenther  <rguenther@suse.de>
+
+       * builtins.c (fold_builtin_1): Verify the argument types
+       of BUILT_IN_ISNORMAL.
+       (fold_builtin_n): Verify the number of arguments to variadic
+       built-in functions.
+
 2007-11-27  Bernd Schmidt  <bernd.schmidt@analog.com>
 
        * config/bfin/elf.h (SUBTARGET_DRIVER_SELF_SPECS): New macro.
index 1eb6cfc3d6e1c9114f8b1ab26637ca8b63a0c6ed..5befd422bb0b931299fd601c1edc50f3fffa5afb 100644 (file)
@@ -10063,6 +10063,15 @@ fold_builtin_1 (tree fndecl, tree arg0, bool ignore)
     case BUILT_IN_ISNAND128:
       return fold_builtin_classify (fndecl, arg0, BUILT_IN_ISNAN);
 
+    case BUILT_IN_ISNORMAL:
+      if (!validate_arg (arg0, REAL_TYPE))
+       {
+         error ("non-floating-point argument to function %qs",
+                IDENTIFIER_POINTER (DECL_NAME (fndecl)));
+         return error_mark_node;
+       }
+      break;
+
     case BUILT_IN_PRINTF:
     case BUILT_IN_PRINTF_UNLOCKED:
     case BUILT_IN_VPRINTF:
@@ -10408,7 +10417,55 @@ fold_builtin_4 (tree fndecl, tree arg0, tree arg1, tree arg2, tree arg3,
 static tree
 fold_builtin_n (tree fndecl, tree *args, int nargs, bool ignore)
 {
+  enum built_in_function fcode = DECL_FUNCTION_CODE (fndecl);
   tree ret = NULL_TREE;
+
+  /* Verify the number of arguments for type-generic and thus variadic
+     builtins.  */
+  switch (fcode)
+    {
+    case BUILT_IN_ISFINITE:
+    case BUILT_IN_ISINF:
+    case BUILT_IN_ISNAN:
+    case BUILT_IN_ISNORMAL:
+      if (nargs < 1)
+       {
+         error ("too few arguments to function %qs",
+                IDENTIFIER_POINTER (DECL_NAME (fndecl)));
+         return error_mark_node;
+       }
+      else if (nargs > 1)
+       {
+         error ("too many arguments to function %qs",
+                IDENTIFIER_POINTER (DECL_NAME (fndecl)));
+         return error_mark_node;
+       }
+      break;
+
+    case BUILT_IN_ISGREATER:
+    case BUILT_IN_ISGREATEREQUAL:
+    case BUILT_IN_ISLESS:
+    case BUILT_IN_ISLESSEQUAL:
+    case BUILT_IN_ISLESSGREATER:
+    case BUILT_IN_ISUNORDERED:
+      if (nargs < 2)
+       {
+         error ("too few arguments to function %qs",
+                IDENTIFIER_POINTER (DECL_NAME (fndecl)));
+         return error_mark_node;
+       }
+      else if (nargs > 2)
+       {
+         error ("too many arguments to function %qs",
+                IDENTIFIER_POINTER (DECL_NAME (fndecl)));
+         return error_mark_node;
+       }
+      break;
+
+    default:
+      break;
+    }
+
   switch (nargs)
     {
     case 0:
index 10ce3a5a4c202eadbcb1a600b4a02fa5075a0790..a3c26bfce0cc76f6a4d4ce742a857139572a8335 100644 (file)
@@ -1,3 +1,7 @@
+2007-11-27  Richard Guenther  <rguenther@suse.de>
+
+       * gcc.dg/builtins-error.c: New testcase.
+
 2007-11-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/34213
diff --git a/gcc/testsuite/gcc.dg/builtins-error.c b/gcc/testsuite/gcc.dg/builtins-error.c
new file mode 100644 (file)
index 0000000..6acc215
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+
+struct X { int x; };
+
+int test1(struct X x)
+{
+  return __builtin_isnormal(x); /* { dg-error "non-floating-point argument" } */
+}
+
+int test2(double x)
+{
+  return __builtin_isgreater(x); /* { dg-error "too few arguments" } */
+}
+
+int test3(double x)
+{
+  return __builtin_isinf(x, x); /* { dg-error "too many arguments" } */
+}