[PATCH] D62944: [Driver] Fix wchar_t and wint_t definitions on Solaris
Rainer Orth via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 6 03:13:54 PDT 2019
ro created this revision.
ro added reviewers: rsmith, fedor.sergeev.
Herald added a subscriber: jyknight.
Herald added a project: clang.
`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.
Repository:
rC Clang
https://reviews.llvm.org/D62944
Files:
lib/Basic/Targets/OSTargets.h
test/Preprocessor/wchar_t.c
test/Sema/wchar.c
Index: test/Sema/wchar.c
===================================================================
--- test/Sema/wchar.c
+++ test/Sema/wchar.c
@@ -9,7 +9,11 @@
#elif defined(__arm) || defined(__aarch64__)
#define WCHAR_T_TYPE unsigned int
#elif defined(__sun)
- #define WCHAR_T_TYPE long
+ #if defined(__LP64__)
+ #define WCHAR_T_TYPE int
+ #else
+ #define WCHAR_T_TYPE long
+ #endif
#else /* Solaris. */
#define WCHAR_T_TYPE int
#endif
Index: test/Preprocessor/wchar_t.c
===================================================================
--- test/Preprocessor/wchar_t.c
+++ test/Preprocessor/wchar_t.c
@@ -1,8 +1,13 @@
// RUN: %clang_cc1 -triple i386-pc-solaris -dM -E %s -o - | FileCheck %s -check-prefix CHECK-SOLARIS
// CHECK-SOLARIS-DAG: #define __WCHAR_MAX__ 2147483647
-// CHECK-SOLARIS-DAG: #define __WCHAR_TYPE__ int
+// CHECK-SOLARIS-DAG: #define __WCHAR_TYPE__ long int
// CHECK-SOLARIS-NOT: #define __WCHAR_UNSIGNED__ 0
+// RUN: %clang_cc1 -triple x86_64-pc-solaris -dM -E %s -o - | FileCheck %s -check-prefix CHECK-SOLARIS64
+// CHECK-SOLARIS64-DAG: #define __WCHAR_MAX__ 2147483647
+// CHECK-SOLARIS64-DAG: #define __WCHAR_TYPE__ int
+// CHECK-SOLARIS64-NOT: #define __WCHAR_UNSIGNED__ 0
+
// RUN: %clang_cc1 -triple avr-unknown-unknown -fwchar-type=int -fsigned-wchar -dM -E %s -o - | FileCheck %s -check-prefix CHECK-AVR
// CHECK-AVR-DAG: #define __WCHAR_MAX__ 32767
// CHECK-AVR-DAG: #define __WCHAR_TYPE__ int
Index: lib/Basic/Targets/OSTargets.h
===================================================================
--- lib/Basic/Targets/OSTargets.h
+++ lib/Basic/Targets/OSTargets.h
@@ -632,7 +632,11 @@
public:
SolarisTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: OSTargetInfo<Target>(Triple, Opts) {
- // FIXME: WIntType should be SignedLong
+ if (this->PointerWidth == 64) {
+ this->WCharType = this->WIntType = this->SignedInt;
+ } else {
+ this->WCharType = this->WIntType = this->SignedLong;
+ }
switch (Triple.getArch()) {
default:
break;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62944.203311.patch
Type: text/x-patch
Size: 2059 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190606/eff1b755/attachment.bin>
More information about the cfe-commits
mailing list