From bd0e9c90e2c345ca12fedbb7ceb8ef7335591fe9 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 30 Jul 2019 16:58:16 +0200 Subject: [PATCH] Merge #15134: tests: Switch one of the Travis jobs to an unsigned char environment (-funsigned-char) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 0c78e49be3a258695b7f363f2d5b1cfdb93f9522 tests: Switch one of the Travis jobs to an unsigned char environment (-funsigned-char) (practicalswift) Pull request description: Switch one of the Travis jobs to an unsigned char environment (`-funsigned-char`). This will help us catch errors due to code written under the assumption that `char` has the same value range as `signed char`. The signedness of `char` is implementation-defined. Example: ``` $ uname -a Linux […] x86_64 x86_64 x86_64 GNU/Linux $ cat foo.cpp #include int main() { char c; std::cin >> c; int i = (unsigned char)c; std::cout << i << "\n"; } $ clang++ -o foo foo.cpp $ echo -e "\xff" | ./foo 255 $ clang++ -fsigned-char -o foo foo.cpp $ echo -e "\xff" | ./foo 255 $ clang++ -funsigned-char -o foo foo.cpp $ echo -e "\xff" | ./foo 255 $ cat bar.cpp #include int main() { char c; std::cin >> c; int i = c; std::cout << i << "\n"; } $ clang++ -o bar bar.cpp $ echo -e "\xff" | ./bar -1 $ clang++ -fsigned-char -o bar bar.cpp $ echo -e "\xff" | ./bar -1 $ clang++ -funsigned-char -o bar bar.cpp $ echo -e "\xff" | ./bar 255 ``` `gcc` chars: * signed: alpha, hppa, ia64, m68k, mips, sh, sparc, x86 * unsigned: arm, powerpc, s390 About `-funsigned-char`: > Let the type "char" be unsigned, like "unsigned char". > > Each kind of machine has a default for what "char" should be. It is either like "unsigned char" by default or like "signed char" by default. > > Ideally, a portable program should always use "signed char" or "unsigned char" when it depends on the signedness of an object. But many programs have been written to use plain "char" and expect it to be signed, or expect it to be unsigned, depending on the machines they were written for. > > This option, and its inverse, let you make such a program work with the opposite default. The type "char" is always a distinct type from each of "signed char" or "unsigned char", even though its behavior is always just like one of those two. ACKs for top commit: laanwj: ACK 0c78e49be3a258695b7f363f2d5b1cfdb93f9522 Tree-SHA512: ba04590415c0bb9a0bbd348623e57068f75274f53da7247d5c5ecad82e365a5b45893a4a491d318e82a8feb6a25f019d46e01990afb33162e2c9740d33a343d7 --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7ea3b7dc67..59731a9e37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -232,13 +232,13 @@ after_success: CONFIG_SHELL="/bin/dash" - stage: test - name: 'x86_64 Linux [GOAL: install] [bionic] [uses qt5 dev package instead of depends Qt to speed up build and avoid timeout]' + name: 'x86_64 Linux [GOAL: install] [bionic] [uses qt5 dev package instead of depends Qt to speed up build and avoid timeout] [unsigned char]' env: >- HOST=x86_64-unknown-linux-gnu PACKAGES="python3-zmq qtbase5-dev qttools5-dev-tools protobuf-compiler libdbus-1-dev libharfbuzz-dev libprotobuf-dev" DEP_OPTS="NO_QT=1 NO_UPNP=1 DEBUG=1 ALLOW_HOST_PACKAGES=1" GOAL="install" - BITCOIN_CONFIG="--enable-zmq --with-gui=qt5 --enable-glibc-back-compat --enable-reduce-exports --enable-debug CXXFLAGS=\"-g0 -O2\"" + BITCOIN_CONFIG="--enable-zmq --with-gui=qt5 --enable-glibc-back-compat --enable-reduce-exports --enable-debug CFLAGS=\"-g0 -O2 -funsigned-char\" CXXFLAGS=\"-g0 -O2 -funsigned-char\"" - stage: test name: 'x86_64 Linux [GOAL: install] [trusty] [depends for now]'