Explorar el Código

HPCC-18927 Fix various gcc7.2 compiler warnings/errors

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday hace 7 años
padre
commit
508f7dce57

+ 5 - 0
plugins/cassandra/CMakeLists.txt

@@ -67,6 +67,11 @@ if(USE_CASSANDRA)
   set(_SAVE_CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
   if(NOT WIN32)
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format-nonliteral") # Work around cassandra build error
+    if (CMAKE_COMPILER_IS_GNUCXX)
+        if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0)
+          set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wimplicit-fallthrough=0") # Work around cassandra build error
+        endif ()
+    endif ()
   endif()
   set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cpp-driver/cmake/modules/")
   add_subdirectory(cpp-driver ${PROJECT_BINARY_DIR}/cassandra)

+ 7 - 0
plugins/stringlib/stringlib.cpp

@@ -1590,7 +1590,14 @@ STRINGLIB_API void STRINGLIB_CALL slFormatDate(size32_t & __lenResult, char * &
         memset(&tm, 0, sizeof(tm));
         extractDate(tm, date);
         char buf[255];
+#if defined(__clang__) || defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#endif
         strftime(buf, sizeof(buf), format, &tm);
+#if defined(__clang__) || defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
         len = strlen(buf);
         out = static_cast<char *>(CTXMALLOC(parentCtx, len));
         memcpy(out, buf, len);

+ 21 - 0
plugins/timelib/timelib.cpp

@@ -571,7 +571,14 @@ TIMELIB_API void TIMELIB_CALL tlDateToString(size32_t &__lenResult, char* &__res
         tlInsertDateIntoTimeStruct(&timeInfo, date);
         tlMKTime(&timeInfo);
 
+#if defined(__clang__) || defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#endif
         __lenResult = strftime(buffer, kBufferSize, format, &timeInfo);
+#if defined(__clang__) || defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
         if (__lenResult > 0)
         {
             __result = reinterpret_cast<char*>(CTXMALLOC(parentCtx, __lenResult));
@@ -592,7 +599,14 @@ TIMELIB_API void TIMELIB_CALL tlTimeToString(size32_t &__lenResult, char* &__res
     tlInsertTimeIntoTimeStruct(&timeInfo, time);
     tlMKTime(&timeInfo);
 
+#if defined(__clang__) || defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#endif
     __lenResult = strftime(buffer, kBufferSize, format, &timeInfo);
+#if defined(__clang__) || defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
     __result = NULL;
 
     if (__lenResult > 0)
@@ -615,7 +629,14 @@ TIMELIB_API void TIMELIB_CALL tlSecondsToString(size32_t &__lenResult, char* &__
 
     tlGMTime_r(&theTime, &timeInfo);
 
+#if defined(__clang__) || defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-nonliteral"
+#endif
     __lenResult = strftime(buffer, kBufferSize, format, &timeInfo);
+#if defined(__clang__) || defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
     __result = NULL;
 
     if (__lenResult > 0)

+ 12 - 12
system/jlib/jhash.cpp

@@ -85,12 +85,12 @@ unsigned hashc( const unsigned char *k, unsigned length, unsigned initval)
     }
     switch (length)
     {
-    case 7: c = (*k++); HASHONE(hash, c);
-    case 6: c = (*k++); HASHONE(hash, c);
-    case 5: c = (*k++); HASHONE(hash, c);
-    case 4: c = (*k++); HASHONE(hash, c);
-    case 3: c = (*k++); HASHONE(hash, c);
-    case 2: c = (*k++); HASHONE(hash, c);
+    case 7: c = (*k++); HASHONE(hash, c); // fallthrough
+    case 6: c = (*k++); HASHONE(hash, c); // fallthrough
+    case 5: c = (*k++); HASHONE(hash, c); // fallthrough
+    case 4: c = (*k++); HASHONE(hash, c); // fallthrough
+    case 3: c = (*k++); HASHONE(hash, c); // fallthrough
+    case 2: c = (*k++); HASHONE(hash, c); // fallthrough
     case 1: c = (*k++); HASHONE(hash, c);
     }
     return hash;
@@ -143,12 +143,12 @@ unsigned hashnc( const unsigned char *k, unsigned length, unsigned initval)
     }
     switch (length)
     {
-    case 7: c = (*k++)&0xdf; HASHONE(hash, c);
-    case 6: c = (*k++)&0xdf; HASHONE(hash, c);
-    case 5: c = (*k++)&0xdf; HASHONE(hash, c);
-    case 4: c = (*k++)&0xdf; HASHONE(hash, c);
-    case 3: c = (*k++)&0xdf; HASHONE(hash, c);
-    case 2: c = (*k++)&0xdf; HASHONE(hash, c);
+    case 7: c = (*k++)&0xdf; HASHONE(hash, c); // fallthrough
+    case 6: c = (*k++)&0xdf; HASHONE(hash, c); // fallthrough
+    case 5: c = (*k++)&0xdf; HASHONE(hash, c); // fallthrough
+    case 4: c = (*k++)&0xdf; HASHONE(hash, c); // fallthrough
+    case 3: c = (*k++)&0xdf; HASHONE(hash, c); // fallthrough
+    case 2: c = (*k++)&0xdf; HASHONE(hash, c); // fallthrough
     case 1: c = (*k++)&0xdf; HASHONE(hash, c);
     }
     return hash;

+ 3 - 3
system/jlib/jlib.hpp

@@ -237,7 +237,7 @@ public:
     inline void add(TYPE * x, aindex_t pos)     { PointerArray::add(x, pos); }
     inline void append(TYPE * x)                { PointerArray::append(x); }
     inline aindex_t bAdd(TYPE * & newItem, PointerOfCompareFunc f, bool & isNew) { return PointerArray::bAdd(*(void * *)&newItem, (CompareFunc)f, isNew); }
-    inline aindex_t bSearch(const TYPE * & key, PointerOfCompareFunc f) const    { return PointerArray:: bSearch(*(const void * *)&key, (CompareFunc)f); }
+    inline aindex_t bSearch(const TYPE * & key, PointerOfCompareFunc f) const    { return PointerArray:: bSearch(*(void * const *)&key, (CompareFunc)f); }
     inline aindex_t find(TYPE * x) const        { return PointerArray::find(x); }
     inline TYPE **getArray(aindex_t pos = 0)    { return (TYPE **)PointerArray::getArray(pos); }
     inline TYPE **detach()                      { return (TYPE **)PointerArray::detach(); }
@@ -257,8 +257,8 @@ class ConstPointerArrayOf : public ConstPointerArray
 public:
     inline void add(TYPE * x, aindex_t pos)     { ConstPointerArray::add(x, pos); }
     inline void append(TYPE * x)                { ConstPointerArray::append(x); }
-    inline aindex_t bAdd(TYPE * & newItem, PointerOfCompareFunc f, bool & isNew) { return ConstPointerArray::bAdd(*(void * *)&newItem, (CompareFunc)f, isNew); }
-    inline aindex_t bSearch(const TYPE * & key, PointerOfCompareFunc f) const    { return ConstPointerArray:: bSearch(*(const void * *)&key, (CompareFunc)f); }
+    inline aindex_t bAdd(TYPE * & newItem, PointerOfCompareFunc f, bool & isNew) { return ConstPointerArray::bAdd(*(const void * *)&newItem, (CompareFunc)f, isNew); }
+    inline aindex_t bSearch(const TYPE * & key, PointerOfCompareFunc f) const    { return ConstPointerArray:: bSearch(*(const void * const *)&key, (CompareFunc)f); }
     inline aindex_t find(TYPE * x) const        { return ConstPointerArray::find(x); }
     inline TYPE **getArray(aindex_t pos = 0)    { return (TYPE **)ConstPointerArray::getArray(pos); }
     inline TYPE **detach()                      { return (TYPE **)ConstPointerArray::detach(); }

+ 1 - 1
system/jlib/jptree.cpp

@@ -4016,7 +4016,7 @@ protected:
             c++;
         }
     }
-    void error(const char *msg=NULL, bool giveContext=true, PTreeReadExcptCode code=PTreeRead_syntax)
+    void error(const char *msg=NULL, bool giveContext=true, PTreeReadExcptCode code=PTreeRead_syntax) __attribute__((noreturn))
     {
         StringBuffer context;
         if (giveContext)

+ 5 - 3
system/jlib/jqueue.hpp

@@ -398,10 +398,12 @@ protected:
     std::atomic<int> activeReaders;
     std::atomic<int> activeWriters;
     std::atomic<bool> aborted;
-    Semaphore readers __attribute__((aligned(CACHE_LINE_SIZE)));
-    Semaphore writers __attribute__((aligned(CACHE_LINE_SIZE)));
+    Semaphore readers;
+    char readerPadding[CACHE_LINE_SIZE - sizeof(Semaphore)];
+    Semaphore writers;
+    char writerPadding[CACHE_LINE_SIZE - sizeof(Semaphore)];
     //Ensure the state is not on the same cache line as anything else, especially anything that is modified.
-    std::atomic<state_t> state __attribute__((aligned(CACHE_LINE_SIZE)));
+    std::atomic<state_t> state;
 };
 
 #endif

+ 21 - 15
system/jlib/junicode.cpp

@@ -226,9 +226,9 @@ UTF32 readUtf8Char(const void * _data)
     unsigned short extraBytesToRead = getTrailingBytesForUTF8(*ptr);
     UTF32 ch = 0;
     switch (extraBytesToRead) {
-        case 3: ch += *ptr++; ch <<= 6;
-        case 2: ch += *ptr++; ch <<= 6;
-        case 1: ch += *ptr++; ch <<= 6;
+        case 3: ch += *ptr++; ch <<= 6; // fallthrough
+        case 2: ch += *ptr++; ch <<= 6; // fallthrough
+        case 1: ch += *ptr++; ch <<= 6; // fallthrough
         case 0: ch += *ptr++;
     }
     return ch - offsetsFromUTF8[extraBytesToRead];
@@ -242,8 +242,12 @@ inline bool isLegalUTF8(const UTF8 *source, unsigned length)
     {
     default: return false;
         /* Everything else falls through when "true"... */
-    case 4: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
-    case 3: if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
+    case 4:
+        if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
+        // fallthrough
+    case 3:
+        if ((a = (*--srcptr)) < 0x80 || a > 0xBF) return false;
+        // fallthrough
     case 2: if ((a = (*--srcptr)) > 0xBF) return false;
         switch (*source) 
         {
@@ -253,7 +257,9 @@ inline bool isLegalUTF8(const UTF8 *source, unsigned length)
             case 0xF4: if (a > 0x8F) return false; break;
             default:  if (a < 0x80) return false;
         }
-        case 1: if (*source >= 0x80 && *source < 0xC2) return false;
+        // fallthrough
+    case 1:
+        if (*source >= 0x80 && *source < 0xC2) return false;
         if (*source > 0xF4) return false;
     }
     return true;
@@ -279,9 +285,9 @@ UTF32 UtfReader::next8()
      */
     UTF32 ch = 0;
     switch (extraBytesToRead) {
-        case 3: ch += *source++; ch <<= 6;
-        case 2: ch += *source++; ch <<= 6;
-        case 1: ch += *source++; ch <<= 6;
+        case 3: ch += *source++; ch <<= 6; // fallthrough
+        case 2: ch += *source++; ch <<= 6; // fallthrough
+        case 1: ch += *source++; ch <<= 6; // fallthrough
         case 0: ch += *source++;
     }
     cur = (const byte *)source;
@@ -308,9 +314,9 @@ UTF32 readUtf8Character(unsigned len, const byte * & cur)
      */
     UTF32 ch = 0;
     switch (extraBytesToRead) {
-        case 3: ch += *source++; ch <<= 6;
-        case 2: ch += *source++; ch <<= 6;
-        case 1: ch += *source++; ch <<= 6;
+        case 3: ch += *source++; ch <<= 6; // fallthrough
+        case 2: ch += *source++; ch <<= 6; // fallthrough
+        case 1: ch += *source++; ch <<= 6; // fallthrough
         case 0: ch += *source++;
     }
     cur = (const byte *)source;
@@ -349,9 +355,9 @@ unsigned writeUtf8(void * vtarget, unsigned maxLength, UTF32 ch)
 
     UTF8 * target = (UTF8 *)vtarget + bytesToWrite;
     switch (bytesToWrite) { /* note: everything falls through. */
-        case 4: *--target = (ch | byteMark) & byteMask; ch >>= 6;
-        case 3: *--target = (ch | byteMark) & byteMask; ch >>= 6;
-        case 2: *--target = (ch | byteMark) & byteMask; ch >>= 6;
+        case 4: *--target = (ch | byteMark) & byteMask; ch >>= 6; // fallthrough
+        case 3: *--target = (ch | byteMark) & byteMask; ch >>= 6; // fallthrough
+        case 2: *--target = (ch | byteMark) & byteMask; ch >>= 6; // fallthrough
         case 1: *--target =  ch | firstByteMark[bytesToWrite];
     }
     return bytesToWrite;