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]

Re: 3.0 PATCH: Fix wchar_t definition for bi-arch Solaris 7/8 and IRIX 6


Neil Booth writes:

> Hmmm.  David's problem on MIPS with -mabi=64 is fixed - we patched for
> that a while ago.  That may not impact the correctness of your patch,
> but wide charconsts on MIPS/mabi=64 are fine I think (right, David?)

I've now constructed a small testcase, but don't know how correctly to
integrate it into the testsuite:

/* Compile with -Wall to get a warning if built-in and system wchar_t don't
   match.  */

#define _STDDEF_H
#include <wchar.h>

__WCHAR_TYPE__ __wc_t__;
wchar_t *wc_t_p;

void
wct (void)
{
  wc_t_p = &__wc_t__;
}

The (obvious, I hope) intent is to determine of gcc's idea of wchar_t's
type (i.e. __WCHAR_TYPE__) is identical to what the system headers
provide.  I need to define _STDDEF_H (one of the inclusion guards of gcc's
stdef.h) to avoid including this one, since it's definition is obviously
consistent with itself :-)

#ifndef __cplusplus
typedef __WCHAR_TYPE__ wchar_t;
#endif

So I define the inclusion guard and include another header (wchar.h,
present on Solaris 2, IRIX 6 and Tru64 UNIX V4/V5) that defines wchar_t to
get the vendor definition.

If the types are different, gcc -Wall warns about the assignment above.

Solaris 2 has

#if defined(_LP64)
typedef int     wchar_t;
#else
typedef long    wchar_t;
#endif

IRIX 6 has

#if (_MIPS_SZLONG == 32)
typedef long wchar_t;
#endif
#if (_MIPS_SZLONG == 64)
typedef __int32_t wchar_t;
#endif

Without my patch, I get this:

* bi-arch (32x64) Solaris 8 gcc 3.0 20010523:

% ./xgcc -B./ -m32 -Wall -c wchar_t.c
% ./xgcc -B./ -m64 -Wall -c wchar_t.c
wchar_t.c: In function `wct':
wchar_t.c:13: warning: assignment from incompatible pointer type

* bi-arch (32x64) IRIX 6.2 gcc 3.0 20010523:

% ./xgcc -B./ -mabi=n32 -Wall -c wchar_t.c
wchar_t.c: In function `wct':
wchar_t.c:13: warning: assignment from incompatible pointer type
% ./xgcc -B./ -mabi=64 -Wall -c wchar_t.c

With my patch applied, I get no warnings as expected.

I have no idea how/where to correctly integrate this into the testsuite,
though, or if there are better (i.e. more portable, without relying on
wchar.h) ways to achive the same effect.

If my patch is considered appropriate, I'll fire off another full bootstrap
with just this patch applied (I had some other unrelated stuff in my tree
when trying the above) and re-submit the exact patch used.  The iris6.h
patch needs two fixes:

* WCHAR_TYPE must be "long int", not "int" in the -mabi=64 case

* a definition of __WCHAR_TYPE__ must be added to SUBTARGET_CPP_SIZE_SPEC

as I discovered during the last bootstrap.

	Rainer

-----------------------------------------------------------------------------
Rainer Orth, Faculty of Technology, Bielefeld University

Email: ro@TechFak.Uni-Bielefeld.DE


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