[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#859116: GCC miscompiles following code, unlike clang



Package: g++-6
Version: 6.3.0-11
Severity: normal
Tags: upstream

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi.

Yes, this issue should be sent upstream. But i'm unable to do that
because their bugzilla does not want to reset my password.

The attached testcase was minimized.
With gcc (6), the exit code is 10.
With clang (tried with current svn version), the exit code is 0.
As it should be pretty clear from the code, 0 is the correct answer.

$ ./test.sh
0 compilation passed, GOOD
1 expected output, GOOD
2 compilation passed, GOOD
3 expected output, GOOD
ALL GOOD, valid testcase

- -- System Information:
Debian Release: 9.0
  APT prefers unstable
  APT policy: (990, 'unstable'), (500, 'unstable-debug'), (1, 'experimental-debug'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 4.9.0-2-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages g++-6 depends on:
ii  gcc-6            6.3.0-11
ii  gcc-6-base       6.3.0-11
ii  libc6            2.24-9
ii  libgmp10         2:6.1.2+dfsg-1
ii  libisl15         0.18-1
ii  libmpc3          1.0.3-1+b2
ii  libmpfr4         3.1.5-1
ii  libstdc++-6-dev  6.3.0-11
ii  zlib1g           1:1.2.8.dfsg-5

g++-6 recommends no packages.

Versions of packages g++-6 suggests:
pn  g++-6-multilib    <none>
ii  gcc-6-doc         6.1.0-1
ii  libstdc++6-6-dbg  6.3.0-11

- -- no debconf information

*** buffer.cpp
struct a {
  int b;
  int c = 0;
  a(int d) : b(d) {}
  int e() { return b - c; }
  void *f(int d) {
    c = d;
    return 0;
  }
};
int g(void *, int h) { return h; }
a i(10);
int j = i.e();
int main() { return g(i.f(j), i.e()); }

*** test.sh
#!/bin/bash

# gcc -E, no -P
# $ creduce --n 16 test.sh ${FILE}

GCC=/usr/bin/gcc-6
CLANG=/usr/bin/clang++-5.0

FILE=buffer.cpp

FLAGS="-std=c++11 -Wall -Wextra -Werror -o buffer"

$GCC $FLAGS $FILE #>/dev/null 2>&1

if [ $? -ne 0 ]
then
  echo "0 compilation failed, bad"
  exit 1;
else
  echo "0 compilation passed, GOOD"
fi

./buffer >/dev/null 2>&1

if [ $? -ne 10 ]
then
  echo "1 unexpected output, bad"
  exit 1;
else
  echo "1 expected output, GOOD"
fi


$CLANG $FLAGS $FILE >/dev/null 2>&1

if [ $? -ne 0 ]
then
  echo "2 compilation failed, bad"
  exit 1;
else
  echo "2 compilation passed, GOOD"
fi

./buffer >/dev/null 2>&1

if [ $? -ne 0 ]
then
  echo "3 unexpected output, bad"
  exit 1;
else
  echo "3 expected output, GOOD"
fi

echo "ALL GOOD, valid testcase"

exit 0;

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEjkF6151RK40WXe2HCDw+u0oWieAFAljdBtoACgkQCDw+u0oW
ieAvlA//V9PKOBrrgTehdUO2mhCvpUGh12LNvFijlGTHX3WY40OYOyx5armM29v2
LFixGheiv3VCukX2RPQDYHdi45FyBqHw7wuz7XSb/AtWtA2JqO+XYosOp6BbOGuQ
LfPKDX/8sDP6gtTHGMSey4ZVJor6t8JLleBvxgU04ezIBBsM8WT9Bz9uGeIdxG98
YVS2j+wj4DObLTFhS4PKfZygjiFPWbbIt272so2v6g6kg5tOO3NIUWZ3m3M29EB1
o8pQb2X8myJNU6yEjUjZfPeVK9BLfy0Su3iqucuZD31XxdKCSBd+j4gzfoVyIkbu
raElPZkwv1u71wiyjSr2+WU8xqp/a+5J8vPFnb6x5PZEfzcgLCXZlP7p5PiqHjbP
009bgLxrt8f6Xb46EBnPBoTl2wn786alk0budU2CxJzMO9g6uzjHLATkHqhwXpgM
5xFQzTMwCMFXdQF2yg2jnaLi++8V9gK4+EG6tF4BTQqWVPUr57myShaoJnZAppwh
K2tRmNJhcWp8OzQMBjufkKXoZnmvH7NApgeUF4/8ynZb9ULb1TsBK5pvUeOwYYDi
VczHeUSFpKGsWQfMW5Zt623arWxzFUJlHEvhnkg2f3AhCb1HKnPel901EzMadfU1
6XONa9m3xLvHYbz8jnl3kBL6xXG8ImZJ/yLyEFP0OiBacxi/esM=
=+7ZW
-----END PGP SIGNATURE-----


Reply to: