Skip to content

Commit

Permalink
Fix clang-5+ and gcc-5+ compilation issues
Browse files Browse the repository at this point in the history
Pull Request resolved: facebook#1076

Reviewed By: lth

Differential Revision: D19301431

Pulled By: lth

fbshipit-source-id: d302e8d
  • Loading branch information
inikep committed Oct 5, 2020
1 parent ae1ffe8 commit 528ad31
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 28 deletions.
5 changes: 5 additions & 0 deletions cmake/maintainer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ IF(MY_COMPILER_IS_CLANG)
STRING_APPEND(MY_CXX_WARNING_FLAGS " -Wnon-virtual-dtor")
STRING_APPEND(MY_CXX_WARNING_FLAGS " -Wundefined-reinterpret-cast")

# clang-5 or older: disable "suggest braces around initialization of subobject" warnings
IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6)
STRING_APPEND(MY_CXX_WARNING_FLAGS " -Wno-missing-braces")
ENDIF()

MY_ADD_CXX_WARNING_FLAG("Winconsistent-missing-destructor-override")
MY_ADD_CXX_WARNING_FLAG("Wshadow-field")

Expand Down
5 changes: 3 additions & 2 deletions include/m_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,9 @@ static inline void human_readable_num_bytes(char *buf, int buf_len,
unsigned int i;
for (i = 0; dbl_val > 1024 && i < sizeof(size) - 1; i++) dbl_val /= 1024;
const char mult = size[i];
// 18446744073709551615 Yottabytes should be enough for most ...
if (dbl_val > ULLONG_MAX)
// ULLONG_MAX (18446744073709551615) should be enough for most ...
// static_cast<double>(ULLONG_MAX) is equal 18446744073709551616.0
if (dbl_val >= static_cast<double>(ULLONG_MAX))
snprintf(buf, buf_len, "+INF");
else
snprintf(buf, buf_len, "%llu%c", (unsigned long long)dbl_val, mult);
Expand Down
4 changes: 2 additions & 2 deletions libmysql/libmysql.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3120,8 +3120,8 @@ static void fetch_long_with_conversion(MYSQL_BIND *param, MYSQL_FIELD *field,
volatile double data;
if (is_unsigned) {
data = ulonglong2double(value);
*param->error =
data >= ULLONG_MAX || ((ulonglong)value) != ((ulonglong)data);
*param->error = data >= static_cast<double>(ULLONG_MAX) ||
((ulonglong)value) != ((ulonglong)data);
} else {
data = (double)value;
*param->error = value != ((longlong)data);
Expand Down
7 changes: 7 additions & 0 deletions router/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

# Disable ld.gold for clang-7 and clang-8
IF(USE_LD_LLD AND CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND
NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0 AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
STRING(REPLACE "-fuse-ld=gold" "" CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS}")
STRING(REPLACE "-fuse-ld=gold" "" CMAKE_CXX_LINK_FLAGS "${CMAKE_CXX_LINK_FLAGS}")
ENDIF()

INCLUDE(cmake/version.cmake)
SET(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
Expand Down
4 changes: 2 additions & 2 deletions sql/auth/sql_authorization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1064,14 +1064,14 @@ void make_database_privilege_statement(THD *thd, ACL_USER *role,
*/
Mem_root_array<std::pair<std::string, ulong>> restrictions_array(
thd->mem_root);
for (const auto rl_itr : restrictions.get()) {
for (const auto &rl_itr : restrictions.get()) {
restrictions_array.push_back({rl_itr.first, rl_itr.second});
}
std::sort(restrictions_array.begin(), restrictions_array.end(),
[](const auto &p1, const auto &p2) -> bool {
return (p1.first.compare(p2.first) <= 0);
});
for (const auto rl_itr : restrictions_array) {
for (const auto &rl_itr : restrictions_array) {
String db;
db.length(0);
db.append(STRING_WITH_LEN("REVOKE "));
Expand Down
3 changes: 1 addition & 2 deletions sql/geometry_rtree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ struct Rtree_value_maker_bggeom {
typedef std::pair<BG_box, size_t> result_type;
template <typename T>
result_type operator()(T const &v) const {
BG_box box;
boost::geometry::envelope(v.value(), box);
BG_box box = boost::geometry::return_envelope<BG_box>(v.value());

return result_type(box, v.index());
}
Expand Down
6 changes: 4 additions & 2 deletions sql/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -4878,12 +4878,14 @@ class Item_result_field : public Item {
}

longlong llrint_with_overflow_check(double realval) {
if (realval < LLONG_MIN || realval > LLONG_MAX) {
if (realval < static_cast<double>(LLONG_MIN) ||
realval > static_cast<double>(LLONG_MAX)) {
raise_integer_overflow();
return error_int();
}
// Rounding error, llrint() may return LLONG_MIN.
const longlong retval = realval == LLONG_MAX ? LLONG_MAX : llrint(realval);
const longlong retval =
realval == static_cast<double>(LLONG_MAX) ? LLONG_MAX : llrint(realval);
return retval;
}

Expand Down
3 changes: 2 additions & 1 deletion sql/opt_explain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1462,7 +1462,8 @@ bool Explain_join::explain_rows_and_filtered() {
// Print cost-related info
double prefix_rows = pos->prefix_rowcount;
ulonglong prefix_rows_ull =
prefix_rows >= std::numeric_limits<ulonglong>::max()
prefix_rows >=
static_cast<double>(std::numeric_limits<ulonglong>::max())
? std::numeric_limits<ulonglong>::max()
: static_cast<ulonglong>(prefix_rows);
fmt->entry()->col_prefix_rows.set(prefix_rows_ull);
Expand Down
12 changes: 6 additions & 6 deletions sql/rpl_binlog_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,12 @@ void Binlog_sender::run() {
if (reader.is_open()) {
if (is_fatal_error()) {
/* output events range to error message */
snprintf(error_text, sizeof(error_text),
"%s; the first event '%s' at %lld, "
"the last event read from '%s' at %lld, "
"the last byte read from '%s' at %lld.",
m_errmsg, m_start_file, m_start_pos, m_last_file, m_last_pos,
log_file, reader.position());
my_snprintf_8bit(nullptr, error_text, sizeof(error_text),
"%s; the first event '%s' at %lld, "
"the last event read from '%s' at %lld, "
"the last byte read from '%s' at %lld.",
m_errmsg, m_start_file, m_start_pos, m_last_file,
m_last_pos, log_file, reader.position());
set_fatal_error(error_text);
}

Expand Down
2 changes: 1 addition & 1 deletion sql/sql_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ static bool find_db_tables(THD *thd, const dd::Schema &schema, const char *db,
&sch_tables))
return true;

for (const dd::String_type table_name : sch_tables) {
for (const dd::String_type &table_name : sch_tables) {
TABLE_LIST *table_list = new (thd->mem_root) TABLE_LIST;
if (table_list == nullptr) return true; /* purecov: inspected */

Expand Down
18 changes: 10 additions & 8 deletions sql/sql_planner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -879,10 +879,11 @@ double Optimize_table_order::calculate_scan_cost(
tab->records() - *rows_after_filtering));

trace_access_scan->add("using_join_cache", true);
trace_access_scan->add("buffers_needed",
buffer_count >= std::numeric_limits<ulong>::max()
? std::numeric_limits<ulong>::max()
: static_cast<ulong>(buffer_count));
trace_access_scan->add(
"buffers_needed",
buffer_count >= static_cast<double>(std::numeric_limits<ulong>::max())
? std::numeric_limits<ulong>::max()
: static_cast<ulong>(buffer_count));
}
}

Expand Down Expand Up @@ -2550,10 +2551,11 @@ bool Optimize_table_order::consider_plan(uint idx,
(Similar code in best_extension_by_li...)
*/
join->best_read = cost - 0.001;
join->best_rowcount = join->positions[idx].prefix_rowcount >=
std::numeric_limits<ha_rows>::max()
? std::numeric_limits<ha_rows>::max()
: (ha_rows)join->positions[idx].prefix_rowcount;
join->best_rowcount =
join->positions[idx].prefix_rowcount >=
static_cast<double>(std::numeric_limits<ha_rows>::max())
? std::numeric_limits<ha_rows>::max()
: (ha_rows)join->positions[idx].prefix_rowcount;
join->sort_cost = sort_cost;
join->windowing_cost = windowing_cost;
found_plan_with_allowed_sj = plan_uses_allowed_sj;
Expand Down
3 changes: 2 additions & 1 deletion unittest/gunit/m_string-t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ TEST(MString, HumanReadableSize) {
human_readable_num_bytes(data_size_str, 32, data_size);
EXPECT_STREQ("1025000000Y", data_size_str);

data_size *= std::numeric_limits<unsigned long long>::max();
data_size *=
static_cast<double>(std::numeric_limits<unsigned long long>::max());
human_readable_num_bytes(data_size_str, 32, data_size);
EXPECT_STREQ("+INF", data_size_str);
}
Expand Down
2 changes: 1 addition & 1 deletion unittest/gunit/xplugin/xpl/sql_statement_builder_t.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ template <typename T>
class Sql_statement_builder_test_base : public testing::TestWithParam<T> {
public:
Query_string_builder m_qb;
Sql_statement_builder m_builder{{&m_qb}};
Sql_statement_builder m_builder{&m_qb};
};

struct Param_sql_statement_builder {
Expand Down

0 comments on commit 528ad31

Please sign in to comment.