Bug 88753 - [9 Regression] Wrong code since r265463 in tree switch conversion
Summary: [9 Regression] Wrong code since r265463 in tree switch conversion
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 9.0
: P1 normal
Target Milestone: 9.0
Assignee: Martin Liška
URL:
Keywords: wrong-code
: 88609 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-01-08 11:15 UTC by Martin Liška
Modified: 2019-01-21 22:07 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 8.2.0
Known to fail: 9.0
Last reconfirmed: 2019-01-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2019-01-08 11:15:35 UTC
As reported in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84436#c12:

Romain Geissler 2019-01-07 14:41:34 UTC
Hi,

I have tried the following script directly inside docker using the official "debian:buster" docker image, so I hope it will not require much more dependencies than what is written here.

Tested with x86-64.

<<END_OF_SCRIPT
#!/bin/bash

set -e

# Install a few dependencies
apt-get update
apt-get install -y curl tar build-essential cmake python

LLVM_DIRECTORY=/llvm

LLVM_TAR="http://releases.llvm.org/7.0.1/llvm-7.0.1.src.tar.xz"
CLANG_TAR="http://releases.llvm.org/7.0.1/cfe-7.0.1.src.tar.xz"
COMPILER_RT_TAR="http://releases.llvm.org/7.0.1/compiler-rt-7.0.1.src.tar.xz"

mkdir -p "${LLVM_DIRECTORY}/src"
mkdir -p "${LLVM_DIRECTORY}/build"

cd "${LLVM_DIRECTORY}/src"
curl "${LLVM_TAR}" | tar -Jx --strip-components=1 -f -
mkdir -p "${LLVM_DIRECTORY}/src/tools/clang"
cd "${LLVM_DIRECTORY}/src/tools/clang"
curl "${CLANG_TAR}" | tar -Jx --strip-components=1 -f -
mkdir -p "${LLVM_DIRECTORY}/src/projects/compiler-rt"
cd "${LLVM_DIRECTORY}/src/projects/compiler-rt"
curl "${COMPILER_RT_TAR}" | tar -Jx --strip-components=1 -f -

cd "${LLVM_DIRECTORY}/build"
cmake -G "Unix Makefiles" -C "${LLVM_DIRECTORY}/src/tools/clang/cmake/caches/PGO.cmake" "${LLVM_DIRECTORY}/src"
make -j 32 stage2-instrumented-generate-profdata
END_OF_SCRIPT

in order to use your own gcc, make sure that you update the $PATH environment variable when running cmake/make.

I suggest you build clang both with and without your fix in gcc, then explore the whole build tree and find all *.o files which differ (I hope there aren't a lot), to check why they behave differently.

Note that it seems like gcc had an earlier regression, making the clang bootstrap fail a bit later after building compiler-rt, with an error like:

FAILED: tools/clang/include/clang/AST/StmtNodes.inc 

cd /workdir/build/final-system/llvm-build/tools/clang/stage2-instrumented-bins && /workdir/build/final-system/llvm-build/tools/clang/stage2-instrumented-bins/bin/clang-tblgen -gen-clang-stmt-nodes -I /workdir/src/llvm-8.0.0/clang/include/clang/AST -I /workdir/src/llvm-8.0.0/llvm/include /workdir/src/llvm-8.0.0/clang/include/clang/AST/../Basic/StmtNodes.td -o tools/clang/include/clang/AST/StmtNodes.inc -d tools/clang/include/clang/AST/StmtNodes.inc.d

This is an unrelated error, which I think comes from a gcc regression too, and which I will bisect as well.

If you need more info, just ask.

Cheers,
Romain
Comment 1 Martin Liška 2019-01-08 11:16:31 UTC
Mine. Also
Comment 2 Martin Liška 2019-01-08 11:16:59 UTC
Mine, also seen in libzip package.
Comment 3 Martin Liška 2019-01-08 11:41:08 UTC
Reduced test-case:

$ cat zip.c
typedef unsigned short int uint16_t;
typedef unsigned char uint8_t;

uint16_t length;
uint16_t enc_method_global;

uint8_t
__attribute__((noipa))
_zip_buffer_get_8(int buffer)
{
  return buffer;
}

  int
  __attribute__((noipa))
foo(int v)
{
  uint16_t enc_method;
  switch (_zip_buffer_get_8(v)) {
    case 1:
      enc_method = 0x0101;
      break;
    case 2:
      enc_method = 0x0102;
      break;
    case 3:
      enc_method = 0x0103;
      break;
    default:
      __builtin_abort ();
  }

  enc_method_global = enc_method;
}

int main(int argc, char **argv)
{
  foo (1);
  if (enc_method_global != 0x0101)
    __builtin_abort ();

  return 0;
}
Comment 4 Martin Liška 2019-01-08 12:00:25 UTC
I'm testing patch for that.
Comment 5 Martin Liška 2019-01-08 14:46:38 UTC
Author: marxin
Date: Tue Jan  8 14:45:28 2019
New Revision: 267728

URL: https://gcc.gnu.org/viewcvs?rev=267728&root=gcc&view=rev
Log:
Use proper type in linear transformation in tree-switch-conversion (PR tree-optimization/88753).

2019-01-08  Martin Liska  <mliska@suse.cz>

	PR tree-optimization/88753
	* tree-switch-conversion.c (switch_conversion::build_one_array):
	Come up with local variable constructor.  Convert first to
	type of constructor values.
2019-01-08  Martin Liska  <mliska@suse.cz>

	PR tree-optimization/88753
	* gcc.dg/tree-ssa/pr88753.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/pr88753.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-switch-conversion.c
Comment 6 Martin Liška 2019-01-08 14:47:11 UTC
Fixed.
Comment 7 Dimitar Dimitrov 2019-01-21 22:07:55 UTC
*** Bug 88609 has been marked as a duplicate of this bug. ***