Bug #99221 clang-10 compilation warnings
Submitted: 9 Apr 2020 15:47 Modified: 11 May 2020 15:41
Reporter: Przemysław Skibiński (OCA) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Compiling Severity:S5 (Performance)
Version:8.0.19 OS:Any
Assigned to: CPU Architecture:Any

[9 Apr 2020 15:47] Przemysław Skibiński
Description:
There is a lot of new compilation warnings with clang-10. For example:
1.
/data/mysql-server/mysql-8.0/include/m_string.h:345:17: error: implicit conversion from 'unsigned long long' to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion]
  if (dbl_val > ULLONG_MAX)
              ~ ^~~~~~~~~~
/usr/lib/llvm-10/lib/clang/10.0.0/include/limits.h:84:43: note: expanded from macro 'ULLONG_MAX'
#define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
2.
/data/mysql-server/mysql-8.0/sql/item.h:4602:42: error: implicit conversion from 'long long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-int-float-conversion]
    if (realval < LLONG_MIN || realval > LLONG_MAX) {
                                       ~ ^~~~~~~~~
/usr/lib/llvm-10/lib/clang/10.0.0/include/limits.h:82:20: note: expanded from macro 'LLONG_MAX'
3.
/data/mysql-server/mysql-8.0/sql/item.h:4607:40: error: implicit conversion from 'long long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-int-float-conversion]
    const longlong retval = realval == LLONG_MAX ? LLONG_MAX : llrint(realval);
                                    ~~ ^~~~~~~~~
/usr/lib/llvm-10/lib/clang/10.0.0/include/limits.h:82:20: note: expanded from macro 'LLONG_MAX'
#define LLONG_MAX  __LONG_LONG_MAX__
                   ^~~~~~~~~~~~~~~~~
<built-in>:77:27: note: expanded from here
#define __LONG_LONG_MAX__ 9223372036854775807LL
4.
/data/mysql-server/mysql-8.0/libmysql/libmysql.cc:3121:21: error: implicit conversion from 'unsigned long long' to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion]
            data >= ULLONG_MAX || ((ulonglong)value) != ((ulonglong)data);
                 ~~ ^~~~~~~~~~
/usr/lib/llvm-10/lib/clang/10.0.0/include/limits.h:84:43: note: expanded from macro 'ULLONG_MAX'
#define ULLONG_MAX (__LONG_LONG_MAX__*2ULL+1ULL)
5.
/data/mysql-server/mysql-8.0/plugin/x/client/xsession_impl.cc:462:19: error: loop variable 'value' of type 'const std::__cxx11::basic_string<char>' creates a copy from type 'const std::__cxx11::basic_string<char>' [-Werror,-Wrange-loop-construct]
  for (const auto value : values_list) {
6.
/data/mysql-server/mysql-8.0/unittest/gunit/m_string-t.cc:91:16: error: implicit conversion from 'unsigned long long' to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion]
  data_size *= std::numeric_limits<unsigned long long>::max();
7.
/data/mysql-server/mysql-8.0/router/src/router/src/config_generator.cc:2230:26: error: loop variable 'a' of type 'const std::string' (aka 'const basic_string<char>') creates a copy from type 'const std::string' [-Werror,-Wrange-loop-construct]
  for (const std::string a : accounts) {
8.
/data/mysql-server/mysql-8.0/unittest/gunit/xplugin/xpl/sql_statement_builder_t.cc:43:35: error: braces around scalar initializer [-Werror,-Wbraced-scalar-init]
  Sql_statement_builder m_builder{{&m_qb}};
9.
/data/mysql-server/mysql-8.0/sql/auth/sql_authorization.cc:1072:23: error: loop variable 'rl_itr' of type 'const std::pair<const std::__cxx11::basic_string<char>, unsigned long>' creates a copy from type 'const std::pair<const std::__cxx11::basic_string<char>, unsigned long>' [-Werror,-Wrange-loop-construct]
      for (const auto rl_itr : restrictions.get()) {
10.
/data/mysql-server/mysql-8.0/router/tests/component/test_bootstrap.cc:1715:28: error: loop variable 'output' of type 'const std::string' (aka 'const basic_string<char>') creates a copy from type 'const std::string' [-Werror,-Wrange-loop-construct]
    for (const std::string output : exp_output) {

11.
/data/mysql-server/mysql-8.0/sql/opt_explain.cc:1471:24: error: implicit conversion from 'unsigned long long' to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion]
        prefix_rows >= std::numeric_limits<ulonglong>::max()
12.
/data/mysql-server/mysql-8.0/sql/sql_db.cc:879:30: error: loop variable 'table_name' of type 'const dd::String_type' (aka 'const basic_string<char, std::char_traits<char>, Stateless_allocator<char, dd::String_type_alloc, My_free_functor> >') creates a copy from type 'const dd::String_type' [-Werror,-Wrange-loop-construct]
  for (const dd::String_type table_name : sch_tables) {
13.
/data/mysql-server/mysql-8.0/sql/sql_planner.cc:882:46: error: implicit conversion from 'unsigned long' to 'double' changes value from 18446744073709551615 to 18446744073709551616 [-Werror,-Wimplicit-int-float-conversion]
                             buffer_count >= std::numeric_limits<ulong>::max()
14.
/data/mysql-server/mysql-8.0/storage/innobase/lock/lock0lock.cc:2333:21: error: loop variable 'new_granted_lock' of type 'const std::pair<ib_lock_t *, unsigned long>' creates a copy from type 'const std::pair<ib_lock_t *, unsigned long>' [-Werror,-Wrange-loop-construct]
    for (const auto new_granted_lock : new_granted) { 

How to repeat:
Compile a server with clang-10

Suggested fix:
Will be attached.
[9 Apr 2020 15:53] Przemysław Skibiński
A patch for mysql-8.0.19

Attachment: clang10_for_8-0-19.patch (text/x-patch), 10.05 KiB.

[14 Apr 2020 9:58] MySQL Verification Team
Please provide the cmake command you applied. Thanks.
[14 Apr 2020 10:59] Przemysław Skibiński
A patch for mysql-8.0.19 (fixed)

Attachment: clang10_for_8-0-19_fixed.patch (text/x-patch), 9.86 KiB.

[14 Apr 2020 11:03] Przemysław Skibiński
I used the following command:
CC=clang-10 CXX=clang++-10 cmake -DCMAKE_BUILD_TYPE=Debug -DMYSQL_MAINTAINER_MODE=ON -DBUILD_CONFIG=mysql_release -DFEATURE_SET=community -DREPRODUCIBLE_BUILD=OFF -DENABLE_DOWNLOADS=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=../deps -DWITH_SYSTEM_LIBS=ON -DWITH_MECAB=system -DWITH_NUMA=ON
[14 Apr 2020 12:53] MySQL Verification Team
Hi,

Thanks for the report and the patch. Confirmed both.

all best
Bogdan
[16 Apr 2020 9:23] Stefan Hinz
Posted by developer:
 
What's supposed to be documented about the bug/the fix?
[16 Apr 2020 11:32] Ståle Deraas
Fixed in bug#98758
[11 May 2020 15:41] Przemysław Skibiński
Where was it fixed? 8.0.20 has the same issues.
[11 May 2020 16:05] Ståle Deraas
Posted by developer:
 
The basebug is fixed in 8.0.21.
[12 May 2020 6:14] MySQL Verification Team
Clang isssues are fixed in 8.0.21 and 8.0.22

all best
b.