This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]: Add wctype builtin functions [take 2]


This version of my patch incorporates suggestions by Joseph regarding
the wctype functions and C94.

Bootstrapped on sparc-sun-solaris2.7, the new testcase passes.
Full regtest underway.

Assuming no regressions, ok for mainline?

		Thanks,
		--Kaveh


2004-03-25  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* builtin-types.def (BT_WINT, BT_FN_INT_WINT, BT_FN_WINT_WINT): New.
	* builtins.def (DEF_C94_BUILTIN): New.  Add wctype builtins.
	* doc/extend.texi: Likewise.
testsuite:
	* gcc.dg/torture/builtin-wctype-1.c: New test.
	
diff -rup orig/egcc-CVS20040325/gcc/builtin-types.def egcc-CVS20040325/gcc/builtin-types.def
--- orig/egcc-CVS20040325/gcc/builtin-types.def	2004-02-09 20:01:46.000000000 -0500
+++ egcc-CVS20040325/gcc/builtin-types.def	2004-03-26 08:15:13.157236036 -0500
@@ -82,6 +82,7 @@ DEF_PRIMITIVE_TYPE (BT_DOUBLE_PTR, doubl
 DEF_PRIMITIVE_TYPE (BT_LONGDOUBLE_PTR, long_double_ptr_type_node)
 DEF_PRIMITIVE_TYPE (BT_SIZE, size_type_node)
 DEF_PRIMITIVE_TYPE (BT_SSIZE, signed_size_type_node)
+DEF_PRIMITIVE_TYPE (BT_WINT, wint_type_node)
 DEF_PRIMITIVE_TYPE (BT_STRING, string_type_node)
 DEF_PRIMITIVE_TYPE (BT_CONST_STRING, const_string_type_node)
 
@@ -144,6 +145,8 @@ DEF_FUNCTION_TYPE_1 (BT_FN_LONGDOUBLE_CO
 		     BT_LONGDOUBLE, BT_CONST_STRING)
 DEF_FUNCTION_TYPE_1 (BT_FN_STRING_CONST_STRING, BT_STRING, BT_CONST_STRING)
 DEF_FUNCTION_TYPE_1 (BT_FN_WORD_PTR, BT_WORD, BT_PTR)
+DEF_FUNCTION_TYPE_1 (BT_FN_INT_WINT, BT_INT, BT_WINT)
+DEF_FUNCTION_TYPE_1 (BT_FN_WINT_WINT, BT_WINT, BT_WINT)
 
 DEF_FUNCTION_TYPE_2 (BT_FN_VOID_PTR_INT, BT_VOID, BT_PTR, BT_INT)
 DEF_FUNCTION_TYPE_2 (BT_FN_STRING_STRING_CONST_STRING, 
diff -rup orig/egcc-CVS20040325/gcc/builtins.def egcc-CVS20040325/gcc/builtins.def
--- orig/egcc-CVS20040325/gcc/builtins.def	2004-03-25 12:52:04.000000000 -0500
+++ egcc-CVS20040325/gcc/builtins.def	2004-03-26 08:20:30.750618658 -0500
@@ -92,6 +92,13 @@ Software Foundation, 59 Temple Place - S
    	       true, true, true, ATTRS, false)
 
 /* Like DEF_LIB_BUILTIN, except that the function is only a part of
+   the standard in C94 or above.  */
+#undef DEF_C94_BUILTIN					
+#define DEF_C94_BUILTIN(ENUM, NAME, TYPE, ATTRS)	\
+  DEF_BUILTIN (ENUM, "__builtin_" NAME, BUILT_IN_NORMAL, TYPE, TYPE,	\
+   	       true, true, !flag_isoc94, ATTRS, TARGET_C99_FUNCTIONS)
+
+/* Like DEF_LIB_BUILTIN, except that the function is only a part of
    the standard in C99 or above.  */
 #undef DEF_C99_BUILTIN					
 #define DEF_C99_BUILTIN(ENUM, NAME, TYPE, ATTRS)	\
@@ -509,6 +516,22 @@ DEF_EXT_LIB_BUILTIN    (BUILT_IN_TOASCII
 DEF_LIB_BUILTIN        (BUILT_IN_TOLOWER, "tolower", BT_FN_INT_INT, ATTR_PURE_NOTHROW_LIST)
 DEF_LIB_BUILTIN        (BUILT_IN_TOUPPER, "toupper", BT_FN_INT_INT, ATTR_PURE_NOTHROW_LIST)
 
+/* Category: wctype builtins.  */
+DEF_C94_BUILTIN        (BUILT_IN_ISWALNUM, "iswalnum", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_ISWALPHA, "iswalpha", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C99_BUILTIN        (BUILT_IN_ISWBLANK, "iswblank", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_ISWCNTRL, "iswcntrl", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_ISWDIGIT, "iswdigit", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_ISWGRAPH, "iswgraph", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_ISWLOWER, "iswlower", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_ISWPRINT, "iswprint", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_ISWPUNCT, "iswpunct", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_ISWSPACE, "iswspace", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_ISWUPPER, "iswupper", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_ISWXDIGIT, "iswxdigit", BT_FN_INT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_TOWLOWER, "towlower", BT_FN_WINT_WINT, ATTR_PURE_NOTHROW_LIST)
+DEF_C94_BUILTIN        (BUILT_IN_TOWUPPER, "towupper", BT_FN_WINT_WINT, ATTR_PURE_NOTHROW_LIST)
+
 /* Category: miscellaneous builtins.  */
 DEF_LIB_BUILTIN        (BUILT_IN_ABORT, "abort", BT_FN_VOID, ATTR_NORETURN_NOTHROW_LIST)
 DEF_LIB_BUILTIN        (BUILT_IN_ABS, "abs", BT_FN_INT_INT, ATTR_CONST_NOTHROW_LIST)
diff -rup orig/egcc-CVS20040325/gcc/doc/extend.texi egcc-CVS20040325/gcc/doc/extend.texi
--- orig/egcc-CVS20040325/gcc/doc/extend.texi	2004-03-25 12:52:04.000000000 -0500
+++ egcc-CVS20040325/gcc/doc/extend.texi	2004-03-26 08:37:43.943386207 -0500
@@ -4898,6 +4898,18 @@ v4si f (v4si a, v4si b, v4si c)
 @findex ispunct
 @findex isspace
 @findex isupper
+@findex iswalnum
+@findex iswalpha
+@findex iswblank
+@findex iswcntrl
+@findex iswdigit
+@findex iswgraph
+@findex iswlower
+@findex iswprint
+@findex iswpunct
+@findex iswspace
+@findex iswupper
+@findex iswxdigit
 @findex isxdigit
 @findex j0
 @findex j0f
@@ -5042,6 +5054,8 @@ v4si f (v4si a, v4si b, v4si c)
 @findex toascii
 @findex tolower
 @findex toupper
+@findex towlower
+@findex towupper
 @findex trunc
 @findex truncf
 @findex truncl
@@ -5127,13 +5141,13 @@ The ISO C99 functions
 @code{fmaxf}, @code{fmaxl}, @code{fmax}, @code{fma}, @code{fminf},
 @code{fminl}, @code{fmin}, @code{hypotf}, @code{hypotl}, @code{hypot},
 @code{ilogbf}, @code{ilogbl}, @code{ilogb}, @code{imaxabs},
-@code{isblank}, @code{lgammaf}, @code{lgammal}, @code{lgamma},
-@code{llabs}, @code{llrintf}, @code{llrintl}, @code{llrint},
-@code{llroundf}, @code{llroundl}, @code{llround}, @code{log1pf},
-@code{log1pl}, @code{log1p}, @code{log2f}, @code{log2l}, @code{log2},
-@code{logbf}, @code{logbl}, @code{logb}, @code{lrintf}, @code{lrintl},
-@code{lrint}, @code{lroundf}, @code{lroundl}, @code{lround},
-@code{nearbyintf}, @code{nearbyintl}, @code{nearbyint},
+@code{isblank}, @code{iswblank}, @code{lgammaf}, @code{lgammal},
+@code{lgamma}, @code{llabs}, @code{llrintf}, @code{llrintl},
+@code{llrint}, @code{llroundf}, @code{llroundl}, @code{llround},
+@code{log1pf}, @code{log1pl}, @code{log1p}, @code{log2f}, @code{log2l},
+@code{log2}, @code{logbf}, @code{logbl}, @code{logb}, @code{lrintf},
+@code{lrintl}, @code{lrint}, @code{lroundf}, @code{lroundl},
+@code{lround}, @code{nearbyintf}, @code{nearbyintl}, @code{nearbyint},
 @code{nextafterf}, @code{nextafterl}, @code{nextafter},
 @code{nexttowardf}, @code{nexttowardl}, @code{nexttoward},
 @code{remainderf}, @code{remainderl}, @code{remainder}, @code{remquof},
@@ -5160,6 +5174,14 @@ that are recognized in any mode since IS
 the purpose to which ISO C99 puts them.  All these functions have
 corresponding versions prefixed with @code{__builtin_}.
 
+The ISO C94 functions
+@code{iswalnum}, @code{iswalpha}, @code{iswcntrl}, @code{iswdigit},
+@code{iswgraph}, @code{iswlower}, @code{iswprint}, @code{iswpunct},
+@code{iswspace}, @code{iswupper}, @code{iswxdigit}, @code{towlower} and
+@code{towupper}
+are handled as built-in functions
+except in strict ISO C90 mode (@option{-ansi} or @option{-std=c89}).
+
 The ISO C90 functions
 @code{abort}, @code{abs}, @code{acos}, @code{asin}, @code{atan2},
 @code{atan}, @code{calloc}, @code{ceil}, @code{cosh}, @code{cos},
diff -rup orig/egcc-CVS20040325/gcc/testsuite/gcc.dg/torture/builtin-wctype-1.c egcc-CVS20040325/gcc/testsuite/gcc.dg/torture/builtin-wctype-1.c
--- orig/egcc-CVS20040325/gcc/testsuite/gcc.dg/torture/builtin-wctype-1.c	2004-03-26 08:25:35.734936736 -0500
+++ egcc-CVS20040325/gcc/testsuite/gcc.dg/torture/builtin-wctype-1.c	2004-03-26 08:15:13.197236410 -0500
@@ -0,0 +1,42 @@
+/* Copyright (C) 2004  Free Software Foundation.
+
+   Verify that built-in wctype function attributes are correctly set
+   by the compiler.
+
+   Written by Kaveh Ghazi, 2004-03-25.  */
+
+/* { dg-do link } */
+
+
+void test(int i)
+{
+  /* All of these ctype functions should be const/pure and thus
+     eliminated.  */
+#define TEST_CTYPE(FN) \
+  extern int FN(int); \
+  extern void link_failure_##FN(void); \
+  if (FN(i) != FN(i)) \
+    link_failure_##FN()
+  
+#ifdef __OPTIMIZE__
+  TEST_CTYPE(iswalnum);
+  TEST_CTYPE(iswalpha);
+  TEST_CTYPE(iswblank);
+  TEST_CTYPE(iswcntrl);
+  TEST_CTYPE(iswdigit);
+  TEST_CTYPE(iswgraph);
+  TEST_CTYPE(iswlower);
+  TEST_CTYPE(iswprint);
+  TEST_CTYPE(iswpunct);
+  TEST_CTYPE(iswspace);
+  TEST_CTYPE(iswupper);
+  TEST_CTYPE(iswxdigit);
+  TEST_CTYPE(towlower);
+  TEST_CTYPE(towupper);
+#endif /* __OPTIMIZE__ */
+}
+
+int main (void)
+{
+  return 0;
+}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]