1
0
Fork 0

added __attribute__((unused)) and other minor tweaks to silence some of the warnings (#6035)

This commit is contained in:
Frank Celler 2018-08-01 13:22:45 +02:00 committed by GitHub
parent 29ab2fdbe3
commit da7ef0a025
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 74 additions and 89 deletions

View File

@ -246,6 +246,14 @@
#define UNUSED(par) (void)(par)
#ifndef AGB_IGNORE_UNUSED
#if defined(__GNUC__)
#define ADB_IGNORE_UNUSED __attribute__((unused))
#else
#define ADB_IGNORE_UNUSED /* unused */
#endif
#endif
#define NS_BEGIN(ns) namespace ns {
#define NS_LOCAL namespace {
#define NS_ROOT NS_BEGIN(iresearch)

View File

@ -56,25 +56,25 @@ class type_id: public irs::type_id, private util::noncopyable {
/// @class CSV format type https://en.wikipedia.org/wiki/Comma-separated_values
////////////////////////////////////////////////////////////////////////////////
IRESEARCH_API const type_id& csv_t();
static const auto& csv = csv_t();
ADB_IGNORE_UNUSED static const auto& csv = csv_t();
////////////////////////////////////////////////////////////////////////////////
/// @class jSON format type https://en.wikipedia.org/wiki/JSON
////////////////////////////////////////////////////////////////////////////////
IRESEARCH_API const type_id& json_t();
static const auto& json = json_t();
ADB_IGNORE_UNUSED static const auto& json = json_t();
////////////////////////////////////////////////////////////////////////////////
/// @class raw text format type without any specific encoding
////////////////////////////////////////////////////////////////////////////////
IRESEARCH_API const type_id& text_t();
static const auto& text = text_t();
ADB_IGNORE_UNUSED static const auto& text = text_t();
////////////////////////////////////////////////////////////////////////////////
/// @class XML format type https://en.wikipedia.org/wiki/XML
////////////////////////////////////////////////////////////////////////////////
IRESEARCH_API const type_id& xml_t();
static const auto& xml = xml_t();
ADB_IGNORE_UNUSED static const auto& xml = xml_t();
#if !defined(_MSC_VER)
#pragma GCC diagnostic pop
@ -83,4 +83,4 @@ static const auto& xml = xml_t();
NS_END // text_format
NS_END // ROOT
#endif
#endif

View File

@ -43,13 +43,15 @@ const std::codecvt<wchar_t, char, std::mbstate_t>& fs_codecvt() {
typedef irs::basic_string_ref<wchar_t> wstring_ref;
bool append_path(std::string& buf, const irs::string_ref& value) {
// use inline to avoid GCC warning
inline bool append_path(std::string& buf, const irs::string_ref& value) {
buf.append(value.c_str(), value.size());
return true;
}
bool append_path(std::string& buf, const wstring_ref& value) {
// use inline to avoid GCC warning
inline bool append_path(std::string& buf, const wstring_ref& value) {
static auto& fs_cvt = fs_codecvt();
auto size = value.size() * 4; // same ratio as boost::filesystem
auto start = buf.size();
@ -85,7 +87,8 @@ bool append_path(std::string& buf, const wstring_ref& value) {
#pragma GCC diagnostic ignored "-Wunused-function"
#endif
bool append_path(std::wstring& buf, const irs::string_ref& value) {
// use inline to avoid GCC warning
inline bool append_path(std::wstring& buf, const irs::string_ref& value) {
static auto& fs_cvt = fs_codecvt();
auto size = value.size() * 3; // same ratio as boost::filesystem
auto start = buf.size();
@ -116,7 +119,8 @@ bool append_path(std::wstring& buf, const irs::string_ref& value) {
return true;
}
bool append_path(std::wstring& buf, const wstring_ref& value) {
// use inline to avoid GCC warning
inline bool append_path(std::wstring& buf, const wstring_ref& value) {
buf.append(value.c_str(), value.size());
return true;
@ -403,4 +407,4 @@ NS_END
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------

View File

@ -1701,7 +1701,7 @@ compute_size_with_overflow(bool may_overflow, dynamic_opts_t *dopts,
}
/* A size_t with its high-half bits all set to 1. */
const static size_t high_bits = SIZE_T_MAX << (sizeof(size_t) * 8 / 2);
static const size_t high_bits = SIZE_T_MAX << (sizeof(size_t) * 8 / 2);
*size = dopts->item_size * dopts->num_items;

View File

@ -15,8 +15,7 @@ if (USE_MAINTAINER_MODE AND NOT MSVC)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/Aql/tokens.cpp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMAND ${CMAKE_SOURCE_DIR}/utils/flex-c++.sh
${FLEX_EXECUTABLE} Aql/tokens.cpp Aql/tokens.ll
COMMAND ${FLEX_EXECUTABLE} -L -oAql/tokens.cpp Aql/tokens.ll
MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/Aql/tokens.ll
VERBATIM
)
@ -38,6 +37,10 @@ if (USE_MAINTAINER_MODE AND NOT MSVC)
set(CLEAN_AUTOGENERATED_FILES ${CLEAN_AUTOGENERATED_FILES} PARENT_SCOPE)
endif ()
if (CMAKE_COMPILER_IS_GNUCC)
set_source_files_properties(Aql/tokens.cpp PROPERTIES COMPILE_FLAGS -Wno-sign-compare)
endif ()
################################################################################
## IResearch
################################################################################

View File

@ -33,8 +33,8 @@ namespace iresearch {
arangodb::LogicalDataSource::Type const& dataSourceType();
arangodb::LogTopic& logTopic();
static auto& DATA_SOURCE_TYPE = dataSourceType();
static auto& TOPIC = logTopic();
ADB_IGNORE_UNUSED static auto& DATA_SOURCE_TYPE = dataSourceType();
ADB_IGNORE_UNUSED static auto& TOPIC = logTopic();
struct StaticStrings {
////////////////////////////////////////////////////////////////////////////////
@ -53,4 +53,4 @@ struct StaticStrings {
} // iresearch
} // arangodb
#endif
#endif

View File

@ -413,7 +413,7 @@ bool Worker<V, E, M>::_processVertices(
}
// ==================== send messages to other shards ====================
outCache->flushMessages();
if (TRI_UNLIKELY(!_writeCache)) { // ~Worker was called
if (ADB_UNLIKELY(!_writeCache)) { // ~Worker was called
LOG_TOPIC(WARN, Logger::PREGEL) << "Execution aborted prematurely.";
return false;
}

View File

@ -198,7 +198,7 @@ typedef long suseconds_t;
#define TRI_ASSERT(expr) \
do { \
if (!(TRI_LIKELY(expr))) { \
if (!(ADB_LIKELY(expr))) { \
TRI_FlushDebugging(__FILE__, __LINE__, #expr); \
TRI_PrintBacktrace(); \
std::abort(); \

View File

@ -81,7 +81,7 @@ inline T atoi_positive_unchecked(char const* p, char const* e) noexcept {
// this function will not modify errno.
template<typename T>
inline T atoi_unchecked(char const* p, char const* e) noexcept {
if (TRI_UNLIKELY(p == e)) {
if (ADB_UNLIKELY(p == e)) {
return T();
}
@ -91,7 +91,7 @@ inline T atoi_unchecked(char const* p, char const* e) noexcept {
}
return atoi_negative_unchecked<T>(++p, e);
}
if (TRI_UNLIKELY(*p == '+')) {
if (ADB_UNLIKELY(*p == '+')) {
++p;
}
@ -109,7 +109,7 @@ inline T atoi_unchecked(char const* p, char const* e) noexcept {
// this function will not modify errno.
template<typename T>
inline T atoi_negative(char const* p, char const* e, bool& valid) noexcept {
if (TRI_UNLIKELY(p == e)) {
if (ADB_UNLIKELY(p == e)) {
valid = false;
return T();
}
@ -121,14 +121,14 @@ inline T atoi_negative(char const* p, char const* e, bool& valid) noexcept {
do {
char c = *p;
// we expect only '0' to '9'. everything else is unexpected
if (TRI_UNLIKELY(c < '0' || c > '9')) {
if (ADB_UNLIKELY(c < '0' || c > '9')) {
valid = false;
return result;
}
c -= '0';
// we expect the bulk of values to not hit the bounds restrictions
if (TRI_UNLIKELY(result < cutoff || (result == cutoff && c > cutlim))) {
if (ADB_UNLIKELY(result < cutoff || (result == cutoff && c > cutlim))) {
valid = false;
return result;
}
@ -151,7 +151,7 @@ inline T atoi_negative(char const* p, char const* e, bool& valid) noexcept {
// this function will not modify errno.
template<typename T>
inline T atoi_positive(char const* p, char const* e, bool& valid) noexcept {
if (TRI_UNLIKELY(p == e)) {
if (ADB_UNLIKELY(p == e)) {
valid = false;
return T();
}
@ -164,14 +164,14 @@ inline T atoi_positive(char const* p, char const* e, bool& valid) noexcept {
char c = *p;
// we expect only '0' to '9'. everything else is unexpected
if (TRI_UNLIKELY(c < '0' || c > '9')) {
if (ADB_UNLIKELY(c < '0' || c > '9')) {
valid = false;
return result;
}
c -= '0';
// we expect the bulk of values to not hit the bounds restrictions
if (TRI_UNLIKELY(result > cutoff || (result == cutoff && c > cutlim))) {
if (ADB_UNLIKELY(result > cutoff || (result == cutoff && c > cutlim))) {
valid = false;
return result;
}
@ -196,7 +196,7 @@ inline T atoi_positive(char const* p, char const* e, bool& valid) noexcept {
// this function will not modify errno.
template<typename T>
inline typename std::enable_if<std::is_signed<T>::value, T>::type atoi(char const* p, char const* e, bool& valid) noexcept {
if (TRI_UNLIKELY(p == e)) {
if (ADB_UNLIKELY(p == e)) {
valid = false;
return T();
}
@ -204,7 +204,7 @@ inline typename std::enable_if<std::is_signed<T>::value, T>::type atoi(char cons
if (*p == '-') {
return atoi_negative<T>(++p, e, valid);
}
if (TRI_UNLIKELY(*p == '+')) {
if (ADB_UNLIKELY(*p == '+')) {
++p;
}
@ -213,7 +213,7 @@ inline typename std::enable_if<std::is_signed<T>::value, T>::type atoi(char cons
template<typename T>
inline typename std::enable_if<std::is_unsigned<T>::value, T>::type atoi(char const* p, char const* e, bool& valid) noexcept {
if (TRI_UNLIKELY(p == e)) {
if (ADB_UNLIKELY(p == e)) {
valid = false;
return T();
}
@ -222,7 +222,7 @@ inline typename std::enable_if<std::is_unsigned<T>::value, T>::type atoi(char co
valid = false;
return T();
}
if (TRI_UNLIKELY(*p == '+')) {
if (ADB_UNLIKELY(*p == '+')) {
++p;
}

View File

@ -28,38 +28,45 @@
#error use <Basics/Common.h>
#endif
/// @brief warn if return value is unused
// warn if return value is unused
#if defined(__GNUC__) || defined(__GNUG__)
#define TRI_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#define ADB_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#elif defined(__clang__)
#define TRI_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#define ADB_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
#else
#define TRI_WARN_UNUSED_RESULT /* unused */
#define ADB_WARN_UNUSED_RESULT /* unused */
#endif
/// @brief unreachable code marker
// suppress unused variable warning
#if defined(__GNUC__)
#define ADB_IGNORE_UNUSED __attribute__((unused))
#else
#define ADB_IGNORE_UNUSED /* unused */
#endif
// unreachable code marker
#if defined(_MSC_VER)
#define TRI_UNREACHABLE __assume(false)
#define ADB_UNREACHABLE __assume(false)
#elif defined(__GNUC__) || defined(__GNUG__)
#define TRI_UNREACHABLE __builtin_unreachable()
#define ADB_UNREACHABLE __builtin_unreachable()
#elif defined(__clang__)
#define TRI_UNREACHABLE __builtin_unreachable()
#define ADB_UNREACHABLE __builtin_unreachable()
#else
#define TRI_UNREACHABLE TRI_ASSERT(false); std::abort()
#define ADB_UNREACHABLE TRI_ASSERT(false); std::abort()
#endif
/// @brief likely/unlikely branch indicator
/// macro definitions similar to the ones at
/// https://kernelnewbies.org/FAQ/LikelyUnlikely
// likely/unlikely branch indicator
// macro definitions similar to the ones at
// https://kernelnewbies.org/FAQ/LikelyUnlikely
#if defined(__GNUC__) || defined(__GNUG__)
#define TRI_LIKELY(v) __builtin_expect (!!(v), 1)
#define TRI_UNLIKELY(v) __builtin_expect (!!(v), 0)
#define ADB_LIKELY(v) __builtin_expect (!!(v), 1)
#define ADB_UNLIKELY(v) __builtin_expect (!!(v), 0)
#else
#define TRI_LIKELY(v) v
#define TRI_UNLIKELY(v) v
#define ADB_LIKELY(v) v
#define ADB_UNLIKELY(v) v
#endif
/// @brief sizetint_t
// sizetint_t
#if defined(TRI_OVERLOAD_FUNCS_SIZE_T)
#if TRI_SIZEOF_SIZE_T == 8
#define sizetint_t uint64_t

View File

@ -13,8 +13,7 @@ if (USE_MAINTAINER_MODE AND NOT MSVC)
add_custom_command(
OUTPUT ${CMAKE_SOURCE_DIR}/lib/V8/v8-json.cpp
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND ${CMAKE_SOURCE_DIR}/utils/flex-c++.sh
${FLEX_EXECUTABLE} lib/V8/v8-json.cpp lib/V8/v8-json.ll
COMMAND ${FLEX_EXECUTABLE} -L -olib/V8/v8-json.cpp lib/V8/v8-json.ll
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/lib/V8/v8-json.ll
VERBATIM
)
@ -27,6 +26,9 @@ if (USE_MAINTAINER_MODE AND NOT MSVC)
endif ()
if (CMAKE_COMPILER_IS_GNUCC)
set_source_files_properties(V8/v8-json.cpp PROPERTIES COMPILE_FLAGS -Wno-sign-compare)
endif ()
################################################################################
## LIB_ARANGO
@ -83,7 +85,7 @@ set(LIB_ARANGO_VPACK
${PROJECT_SOURCE_DIR}/lib/Basics/xxhash.cpp
)
add_definitions ("-DARCHITECTURE_OPTIMIZATIONS=${ARCHITECTURE_OPTIMIZATIONS}")
add_definitions("-DARCHITECTURE_OPTIMIZATIONS=${ARCHITECTURE_OPTIMIZATIONS}")
if (ASM_OPTIMIZATIONS AND CMAKE_TARGET_ARCHITECTURE_CODE MATCHES "x86_64")
if (DARWIN)

View File

@ -1,39 +0,0 @@
#!/bin/sh
FLEX="$1"
OUTPUT="$2"
INPUT="$3"
if test "x$FLEX" = "x" -o "x$OUTPUT" = "x" -o "x$INPUT" = "x"; then
echo "usage: $0 <flex> <output> <input>"
exit 1
fi
#############################################################################
## flex
#############################################################################
${FLEX} -L -o${OUTPUT} ${INPUT}
#############################################################################
## sanity checks
#############################################################################
test -f ${OUTPUT} || exit 1
#############################################################################
## fix casts
#############################################################################
cat ${OUTPUT} \
| sed -e 's:yy_n_chars, (size_t) num_to_read );:yy_n_chars, (int) num_to_read );:' \
| sed -e 's:int yyl;:size_t yyl;:' \
| sed -e 's:(int) (yyg->yy_n_chars + number_to_move):(yy_size_t) (yyg->yy_n_chars + number_to_move):' \
| sed -e 's:register ::g' \
> ${OUTPUT}.tmp
# give some information
# diff -u ${OUTPUT} ${OUTPUT}.tmp
# and move the files to the final destination
mv ${OUTPUT}.tmp ${OUTPUT} || exit 1