Page MenuHomePhabricator

[Driver] Fix wchar_t and wint_t definitions on Solaris
ClosedPublic

Authored by ro on Jun 6 2019, 3:13 AM.

Details

Summary

Clang :: Sema/wchar.c has long been failing on Solaris:

error: 'error' diagnostics expected but not seen: 
  File /vol/llvm/src/clang/local/test/Sema/wchar.c Line 22: initializing wide char array with non-wide string literal
error: 'error' diagnostics seen but not expected: 
  File /vol/llvm/src/clang/local/test/Sema/wchar.c Line 20: array initializer must be an initializer list
  File /vol/llvm/src/clang/local/test/Sema/wchar.c Line 22: array initializer must be an initializer list

It turns out the definition is wrong, as can be seen in GCC's gcc/config/sol2.h:

/* wchar_t is called differently in <wchar.h> for 32 and 64-bit
   compilations.  This is called for by SCD 2.4.1, p. 6-83, Figure 6-65
   (32-bit) and p. 6P-10, Figure 6.38 (64-bit).  */

#undef WCHAR_TYPE
#define WCHAR_TYPE (TARGET_64BIT ? "int" : "long int")

The following patch implements this, and at the same time corrects the wint_t
definition which is the same:

/* Same for wint_t.  See SCD 2.4.1, p. 6-83, Figure 6-66 (32-bit).  There's
   no corresponding 64-bit definition, but this is what Solaris 8
   <iso/wchar_iso.h> uses.  */

#undef WINT_TYPE
#define WINT_TYPE (TARGET_64BIT ? "int" : "long int")

Clang :: Preprocessor/wchar_t.c needs to be adjusted to account for that, however
there's one regesssion in Clang :: Sema/format-strings.c I don't know how best to handle:

error: 'warning' diagnostics seen but not expected:
  File /vol/llvm/src/clang/local/test/Sema/format-strings.c Line 332: format specifies type 'int' but the argument has type 'wchar_t' (aka 'long')

void test_unicode_conversions(wchar_t *s) {
[...]
  printf("%c", s[0]);

and

  File /vol/llvm/src/clang/local/test/Sema/format-strings.c Line 405: format specifies type 'wint_t' (aka 'long') but the argument has type 'char'

void pr7981(wint_t c, wchar_t c2) {
  printf("%lc", c); // no-warning
  printf("%lc", 1.0); // expected-warning{{the argument has type 'double'}}
#if __WINT_WIDTH__ == 32
  printf("%lc", (char) 1); // no-warning
#else
  printf("%lc", (char) 1); // expected-warning{{the argument has type 'char'}}
#endif

WINT_WIDTH is 32 before and after my change, just the name of the type
changes.

Tested so far on i386-pc-solaris2.11. Will need testing on Solaris/SPARC and
Linux/x86_64 after the remaining test failure has been adressed.

Diff Detail

Repository
rL LLVM

Event Timeline

ro created this revision.Jun 6 2019, 3:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 6 2019, 3:13 AM
Herald added a subscriber: jyknight. · View Herald Transcript
ro added a comment.Jun 13 2019, 2:14 AM

Ping? This has been a week, too. According to gcc/config headers, there are quite a number of targets with long int for wchar_t/wint_t,
so there should be some generic way to handle the Clang :: Sema/format-strings.c failure. Suggestions?

For format-strings.c, I'm not really happy suggesting #if defined(__sun) && !defined(__LP64__), but I don't think the alternative is better. We could restrict the test so it doesn't run using a Solaris target triple, but we actually want coverage here: the difference in wint_t affects the semantics of "%lc", so we want some coverage of that path.

The other changes look okay.

ro updated this revision to Diff 205012.Jun 17 2019, 3:44 AM

Adapt Sema/format-strings.c.

ro added a comment.Jun 17 2019, 4:51 AM

For format-strings.c, I'm not really happy suggesting #if defined(__sun) && !defined(__LP64__), but I don't think the alternative is better. We could restrict the test so it doesn't run using a Solaris target triple, but we actually want coverage here: the difference in wint_t affects the semantics of "%lc", so we want some coverage of that path.

Agreed. While gcc supports quite a number of targets with long int for wchar_t/wint_t, Solaris is the only one in clang. I've now adapted
the test accordingly. Should there be more in the future, we can look for a more generic solution.

Tested on i386-pc-solaris2.11, x86_64-pc-solaris2.11, and x86_64-pc-linux-gnu. Ok for trunk now?

This revision is now accepted and ready to land.Jun 17 2019, 12:52 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 17 2019, 1:18 PM