1# Copyright (c) 2016, 2021, Oracle and/or its affiliates.
2#
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License, version 2.0,
5# as published by the Free Software Foundation.
6#
7# This program is also distributed with certain software (including
8# but not limited to OpenSSL) that is licensed under separate terms,
9# as designated in a particular file or component or in included license
10# documentation.  The authors of MySQL hereby grant you an additional
11# permission to link the program and your derivative works with the
12# separately licensed software that they have included with MySQL.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17# GNU General Public License, version 2.0, for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
22
23INCLUDE(CheckCSourceRuns)
24INCLUDE(CheckCXXSourceRuns)
25
26SET(SAVE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
27SET(CMAKE_REQUIRED_FLAGS
28  "${CMAKE_REQUIRED_FLAGS} -O3 -fexpensive-optimizations"
29)
30
31# Below code is known to fail for GCC 5.3.0 on sparc solaris 11.
32# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67781
33SET(code "
34  struct X
35  {
36    int i;
37    unsigned short s;
38  };
39
40  unsigned __attribute__((noinline)) f(struct X x)
41  {
42    return x.s | (x.i << 16);
43  }
44
45  int
46  main()
47  {
48    struct X x;
49    x.i = 0x00001234;
50    x.s = 0x5678;
51    unsigned y = f(x);
52    /* Succeed (return 0) if compiler have bug */
53    return y == 0x12345678 ? 1 : 0;
54  }
55")
56
57IF(CMAKE_COMPILER_IS_GNUCC)
58  CHECK_C_SOURCE_RUNS("${code}" HAVE_C_SHIFT_OR_OPTIMIZATION_BUG)
59ENDIF()
60
61IF(CMAKE_COMPILER_IS_GNUCXX)
62  CHECK_CXX_SOURCE_RUNS("${code}" HAVE_CXX_SHIFT_OR_OPTIMIZATION_BUG)
63ENDIF()
64
65SET(CMAKE_REQUIRED_FLAGS "${SAVE_CMAKE_REQUIRED_FLAGS}")
66