[libcxx-commits] [libcxxabi] 8d31392 - [libc++abi] Get rid of warnings when running the tests with GCC

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 2 07:19:55 PST 2020


Author: Louis Dionne
Date: 2020-11-02T10:19:39-05:00
New Revision: 8d313927539de66808e5bf3566fbd844aa78a916

URL: https://github.com/llvm/llvm-project/commit/8d313927539de66808e5bf3566fbd844aa78a916
DIFF: https://github.com/llvm/llvm-project/commit/8d313927539de66808e5bf3566fbd844aa78a916.diff

LOG: [libc++abi] Get rid of warnings when running the tests with GCC

Added: 
    

Modified: 
    libcxxabi/src/cxa_guard_impl.h
    libcxxabi/src/demangle/ItaniumDemangle.h
    libcxxabi/test/catch_class_03.pass.cpp
    libcxxabi/test/catch_class_04.pass.cpp
    libcxxabi/test/catch_pointer_reference.pass.cpp
    libcxxabi/test/catch_ptr.pass.cpp
    libcxxabi/test/catch_ptr_02.pass.cpp
    libcxxabi/test/cxa_bad_cast.pass.cpp
    libcxxabi/test/cxa_bad_typeid.pass.cpp
    libcxxabi/test/dynamic_cast.pass.cpp
    libcxxabi/test/dynamic_cast3.pass.cpp
    libcxxabi/test/dynamic_cast5.pass.cpp
    libcxxabi/test/guard_test_basic.pass.cpp
    libcxxabi/test/inherited_exception.pass.cpp
    libcxxabi/test/test_vector3.pass.cpp
    libcxxabi/test/unwind_06.pass.cpp

Removed: 
    


################################################################################
diff  --git a/libcxxabi/src/cxa_guard_impl.h b/libcxxabi/src/cxa_guard_impl.h
index f6a698e23acb..6f873f241fad 100644
--- a/libcxxabi/src/cxa_guard_impl.h
+++ b/libcxxabi/src/cxa_guard_impl.h
@@ -54,6 +54,14 @@
 #endif
 #endif
 
+#if defined(__clang__)
+# pragma clang diagnostic push
+# pragma clang diagnostic ignored "-Wtautological-pointer-compare"
+#elif defined(__GNUC__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Waddress"
+#endif
+
 // To make testing possible, this header is included from both cxa_guard.cpp
 // and a number of tests.
 //
@@ -112,25 +120,25 @@ class AtomicInt {
 public:
   using MemoryOrder = std::__libcpp_atomic_order;
 
-  explicit AtomicInt(IntType *b) : b(b) {}
+  explicit AtomicInt(IntType *b) : b_(b) {}
   AtomicInt(AtomicInt const&) = delete;
   AtomicInt& operator=(AtomicInt const&) = delete;
 
   IntType load(MemoryOrder ord) {
-    return std::__libcpp_atomic_load(b, ord);
+    return std::__libcpp_atomic_load(b_, ord);
   }
   void store(IntType val, MemoryOrder ord) {
-    std::__libcpp_atomic_store(b, val, ord);
+    std::__libcpp_atomic_store(b_, val, ord);
   }
   IntType exchange(IntType new_val, MemoryOrder ord) {
-    return std::__libcpp_atomic_exchange(b, new_val, ord);
+    return std::__libcpp_atomic_exchange(b_, new_val, ord);
   }
   bool compare_exchange(IntType *expected, IntType desired, MemoryOrder ord_success, MemoryOrder ord_failure) {
-    return std::__libcpp_atomic_compare_exchange(b, expected, desired, ord_success, ord_failure);
+    return std::__libcpp_atomic_compare_exchange(b_, expected, desired, ord_success, ord_failure);
   }
 
 private:
-  IntType *b;
+  IntType *b_;
 };
 
 //===----------------------------------------------------------------------===//
@@ -154,14 +162,7 @@ constexpr uint32_t (*PlatformThreadID)() = nullptr;
 
 
 constexpr bool PlatformSupportsThreadID() {
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
-#endif
   return +PlatformThreadID != nullptr;
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
 }
 
 //===----------------------------------------------------------------------===//
@@ -375,18 +376,18 @@ struct InitByteGlobalMutex
     LockGuard& operator=(LockGuard const&) = delete;
 
     explicit LockGuard(const char* calling_func)
-        : calling_func(calling_func)  {
+        : calling_func_(calling_func)  {
       if (global_mutex.lock())
-        ABORT_WITH_MESSAGE("%s failed to acquire mutex", calling_func);
+        ABORT_WITH_MESSAGE("%s failed to acquire mutex", calling_func_);
     }
 
     ~LockGuard() {
       if (global_mutex.unlock())
-        ABORT_WITH_MESSAGE("%s failed to release mutex", calling_func);
+        ABORT_WITH_MESSAGE("%s failed to release mutex", calling_func_);
     }
 
   private:
-    const char* const calling_func;
+    const char* const calling_func_;
   };
 };
 
@@ -411,14 +412,7 @@ constexpr void (*PlatformFutexWake)(int*) = nullptr;
 #endif
 
 constexpr bool PlatformSupportsFutex() {
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wtautological-pointer-compare"
-#endif
   return +PlatformFutexWait != nullptr;
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
 }
 
 /// InitByteFutex - Manages initialization using atomics and the futex syscall
@@ -589,4 +583,10 @@ using SelectedImplementation =
 } // end namespace
 } // end namespace __cxxabiv1
 
+#if defined(__clang__)
+# pragma clang diagnostic pop
+#elif defined(__GNUC__)
+# pragma GCC diagnostic pop
+#endif
+
 #endif // LIBCXXABI_SRC_INCLUDE_CXA_GUARD_IMPL_H

diff  --git a/libcxxabi/src/demangle/ItaniumDemangle.h b/libcxxabi/src/demangle/ItaniumDemangle.h
index ede9c6d27d32..fd6e5cf0fe58 100644
--- a/libcxxabi/src/demangle/ItaniumDemangle.h
+++ b/libcxxabi/src/demangle/ItaniumDemangle.h
@@ -2313,9 +2313,9 @@ template <typename Derived, typename Alloc> struct AbstractManglingParser {
     TemplateParamList Params;
 
   public:
-    ScopedTemplateParamList(AbstractManglingParser *Parser)
-        : Parser(Parser),
-          OldNumTemplateParamLists(Parser->TemplateParams.size()) {
+    ScopedTemplateParamList(AbstractManglingParser *TheParser)
+        : Parser(TheParser),
+          OldNumTemplateParamLists(TheParser->TemplateParams.size()) {
       Parser->TemplateParams.push_back(&Params);
     }
     ~ScopedTemplateParamList() {
@@ -5103,7 +5103,7 @@ Node *AbstractManglingParser<Derived, Alloc>::parseEncoding() {
     decltype(TemplateParams) OldParams;
 
   public:
-    SaveTemplateParams(AbstractManglingParser *Parser) : Parser(Parser) {
+    SaveTemplateParams(AbstractManglingParser *TheParser) : Parser(TheParser) {
       OldParams = std::move(Parser->TemplateParams);
       Parser->TemplateParams.clear();
     }

diff  --git a/libcxxabi/test/catch_class_03.pass.cpp b/libcxxabi/test/catch_class_03.pass.cpp
index d7e1e765de16..0d00c7451e24 100644
--- a/libcxxabi/test/catch_class_03.pass.cpp
+++ b/libcxxabi/test/catch_class_03.pass.cpp
@@ -14,6 +14,12 @@
 
 // UNSUPPORTED: no-exceptions
 
+// FIXME: GCC doesn't allow turning off the warning for exceptions being caught
+//        by earlier handlers, which this test is exercising. We have to disable
+//        warnings altogether to remove the error.
+//        See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97675.
+// ADDITIONAL_COMPILE_FLAGS: -Wno-error
+
 #include <exception>
 #include <stdlib.h>
 #include <assert.h>

diff  --git a/libcxxabi/test/catch_class_04.pass.cpp b/libcxxabi/test/catch_class_04.pass.cpp
index 174f07fb597c..7946963e392b 100644
--- a/libcxxabi/test/catch_class_04.pass.cpp
+++ b/libcxxabi/test/catch_class_04.pass.cpp
@@ -14,6 +14,12 @@
 
 // UNSUPPORTED: no-exceptions
 
+// FIXME: GCC doesn't allow turning off the warning for exceptions being caught
+//        by earlier handlers, which this test is exercising. We have to disable
+//        warnings altogether to remove the error.
+//        See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97675.
+// ADDITIONAL_COMPILE_FLAGS: -Wno-error
+
 #include <exception>
 #include <stdlib.h>
 #include <assert.h>

diff  --git a/libcxxabi/test/catch_pointer_reference.pass.cpp b/libcxxabi/test/catch_pointer_reference.pass.cpp
index 5ebcc122bc3f..e50135e729d0 100644
--- a/libcxxabi/test/catch_pointer_reference.pass.cpp
+++ b/libcxxabi/test/catch_pointer_reference.pass.cpp
@@ -14,11 +14,11 @@
 //        (ignoring the top-level cv-qualifiers), or
 //     *  the handler is of type cv T or cv T& and T is an unambiguous base
 //        class of E, or
-//  /  *  the handler is of type cv1 T* cv2 and E is a pointer type that can   \
-//  |     be converted to the type of the handler by either or both of         |
-//  |       o  a standard pointer conversion (4.10 [conv.ptr]) not involving   |
-//  |          conversions to private or protected or ambiguous classes        |
-//  \       o  a qualification conversion                                      /
+//  >  *  the handler is of type cv1 T* cv2 and E is a pointer type that can   <
+//  >     be converted to the type of the handler by either or both of         <
+//  >       o  a standard pointer conversion (4.10 [conv.ptr]) not involving   <
+//  >          conversions to private or protected or ambiguous classes        <
+//  >       o  a qualification conversion                                      <
 //     *  the handler is a pointer or pointer to member type and E is
 //        std::nullptr_t
 //

diff  --git a/libcxxabi/test/catch_ptr.pass.cpp b/libcxxabi/test/catch_ptr.pass.cpp
index 5a409db9af0f..7fac517db673 100644
--- a/libcxxabi/test/catch_ptr.pass.cpp
+++ b/libcxxabi/test/catch_ptr.pass.cpp
@@ -14,6 +14,12 @@
 
 // UNSUPPORTED: no-exceptions
 
+// FIXME: GCC doesn't allow turning off the warning for exceptions being caught
+//        by earlier handlers, which this test is exercising. We have to disable
+//        warnings altogether to remove the error.
+//        See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97675.
+// ADDITIONAL_COMPILE_FLAGS: -Wno-error
+
 #include <exception>
 #include <stdlib.h>
 #include <assert.h>
@@ -72,11 +78,11 @@ struct A
 
 int A::count = 0;
 
-A a(5);
+A global_a(5);
 
 void f1()
 {
-    throw &a;
+    throw &global_a;
     assert(false);
 }
 

diff  --git a/libcxxabi/test/catch_ptr_02.pass.cpp b/libcxxabi/test/catch_ptr_02.pass.cpp
index 1908a499b07e..a9914cc83520 100644
--- a/libcxxabi/test/catch_ptr_02.pass.cpp
+++ b/libcxxabi/test/catch_ptr_02.pass.cpp
@@ -8,6 +8,12 @@
 
 // UNSUPPORTED: no-exceptions
 
+// FIXME: GCC doesn't allow turning off the warning for exceptions being caught
+//        by earlier handlers, which this test is exercising. We have to disable
+//        warnings altogether to remove the error.
+//        See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97675.
+// ADDITIONAL_COMPILE_FLAGS: -Wno-error
+
 #include <cassert>
 
 // Clang emits  warnings about exceptions of type 'Child' being caught by

diff  --git a/libcxxabi/test/cxa_bad_cast.pass.cpp b/libcxxabi/test/cxa_bad_cast.pass.cpp
index 5ff64e8b078a..69ff2745be03 100644
--- a/libcxxabi/test/cxa_bad_cast.pass.cpp
+++ b/libcxxabi/test/cxa_bad_cast.pass.cpp
@@ -43,7 +43,7 @@ int main ()
         assert(false);
         ((void)d);
 #ifndef TEST_HAS_NO_EXCEPTIONS
-    } catch (std::bad_cast) {
+    } catch (std::bad_cast const&) {
         // success
         return 0;
     } catch (...) {

diff  --git a/libcxxabi/test/cxa_bad_typeid.pass.cpp b/libcxxabi/test/cxa_bad_typeid.pass.cpp
index a1afe5280c0c..326c6088529a 100644
--- a/libcxxabi/test/cxa_bad_typeid.pass.cpp
+++ b/libcxxabi/test/cxa_bad_typeid.pass.cpp
@@ -41,7 +41,7 @@ int main ()
         test_bad_typeid(nullptr);
         assert(false);
 #ifndef TEST_HAS_NO_EXCEPTIONS
-    } catch (std::bad_typeid) {
+    } catch (std::bad_typeid const&) {
         // success
         return 0;
     } catch (...) {

diff  --git a/libcxxabi/test/dynamic_cast.pass.cpp b/libcxxabi/test/dynamic_cast.pass.cpp
index 669814b04226..49ecddb4177b 100644
--- a/libcxxabi/test/dynamic_cast.pass.cpp
+++ b/libcxxabi/test/dynamic_cast.pass.cpp
@@ -11,7 +11,9 @@
 // This test explicitly tests dynamic cast with types that have inaccessible
 // bases.
 #if defined(__clang__)
-#pragma clang diagnostic ignored "-Winaccessible-base"
+#   pragma clang diagnostic ignored "-Winaccessible-base"
+#elif defined(__GNUC__)
+#   pragma GCC diagnostic ignored "-Winaccessible-base"
 #endif
 
 typedef char Pad1[43981];

diff  --git a/libcxxabi/test/dynamic_cast3.pass.cpp b/libcxxabi/test/dynamic_cast3.pass.cpp
index 2aa8b03fe4c7..9c25cac865b9 100644
--- a/libcxxabi/test/dynamic_cast3.pass.cpp
+++ b/libcxxabi/test/dynamic_cast3.pass.cpp
@@ -12,7 +12,9 @@
 // This test explicitly tests dynamic cast with types that have inaccessible
 // bases.
 #if defined(__clang__)
-#pragma clang diagnostic ignored "-Winaccessible-base"
+#   pragma clang diagnostic ignored "-Winaccessible-base"
+#elif defined(__GNUC__)
+#   pragma GCC diagnostic ignored "-Winaccessible-base"
 #endif
 
 /*

diff  --git a/libcxxabi/test/dynamic_cast5.pass.cpp b/libcxxabi/test/dynamic_cast5.pass.cpp
index 4d6c94c4141d..0a9689c23d6b 100644
--- a/libcxxabi/test/dynamic_cast5.pass.cpp
+++ b/libcxxabi/test/dynamic_cast5.pass.cpp
@@ -12,7 +12,9 @@
 // This test explicitly tests dynamic cast with types that have inaccessible
 // bases.
 #if defined(__clang__)
-#pragma clang diagnostic ignored "-Winaccessible-base"
+#   pragma clang diagnostic ignored "-Winaccessible-base"
+#elif defined(__GNUC__)
+#   pragma GCC diagnostic ignored "-Winaccessible-base"
 #endif
 
 namespace t1

diff  --git a/libcxxabi/test/guard_test_basic.pass.cpp b/libcxxabi/test/guard_test_basic.pass.cpp
index e03dd183c3da..4cd11fdc11f2 100644
--- a/libcxxabi/test/guard_test_basic.pass.cpp
+++ b/libcxxabi/test/guard_test_basic.pass.cpp
@@ -12,6 +12,11 @@
 #include "../src/cxa_guard_impl.h"
 #include <cassert>
 
+// Disable GCC warning about tautological comparison of a function's address
+#if defined(__GNUC__) && !defined(__clang__)
+# pragma GCC diagnostic ignored "-Waddress"
+#endif
+
 using namespace __cxxabiv1;
 
 template <class GuardType, class Impl>

diff  --git a/libcxxabi/test/inherited_exception.pass.cpp b/libcxxabi/test/inherited_exception.pass.cpp
index 1e3089c7da55..ab3fc0785b58 100644
--- a/libcxxabi/test/inherited_exception.pass.cpp
+++ b/libcxxabi/test/inherited_exception.pass.cpp
@@ -10,10 +10,10 @@
 //
 //  C++ ABI 15.3:
 //  A handler is a match for an exception object of type E if
-//  /  *  The handler is of type cv T or cv T& and E and T are the same type   \
-//  |     (ignoring the top-level cv-qualifiers), or                           |
-//  |  *  the handler is of type cv T or cv T& and T is an unambiguous base    |
-//  \     class of E, or                                                       /
+//  >  *  The handler is of type cv T or cv T& and E and T are the same type   <
+//  >     (ignoring the top-level cv-qualifiers), or                           <
+//  >  *  the handler is of type cv T or cv T& and T is an unambiguous base    <
+//  >     class of E, or                                                       <
 //     *  the handler is of type cv1 T* cv2 and E is a pointer type that can
 //        be converted to the type of the handler by either or both of
 //          o  a standard pointer conversion (4.10 [conv.ptr]) not involving
@@ -26,6 +26,12 @@
 
 // UNSUPPORTED: no-exceptions
 
+// FIXME: GCC doesn't allow turning off the warning for exceptions being caught
+//        by earlier handlers, which this test is exercising. We have to disable
+//        warnings altogether to remove the error.
+//        See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97675.
+// ADDITIONAL_COMPILE_FLAGS: -Wno-error
+
 // Clang emits  warnings about exceptions of type 'Child' being caught by
 // an earlier handler of type 'Base'. Congrats clang, you've just
 // diagnosed the behavior under test.

diff  --git a/libcxxabi/test/test_vector3.pass.cpp b/libcxxabi/test/test_vector3.pass.cpp
index 928788f98679..13117f11dbb8 100644
--- a/libcxxabi/test/test_vector3.pass.cpp
+++ b/libcxxabi/test/test_vector3.pass.cpp
@@ -17,6 +17,11 @@
 
 #include <memory>
 
+// Disable warning about throw always calling terminate.
+#if defined(__GNUC__) && !defined(__clang__)
+# pragma GCC diagnostic ignored "-Wterminate"
+#endif
+
 // use dtors instead of try/catch
 namespace test1 {
     struct B {

diff  --git a/libcxxabi/test/unwind_06.pass.cpp b/libcxxabi/test/unwind_06.pass.cpp
index c4f23d85e9df..0c34c4949376 100644
--- a/libcxxabi/test/unwind_06.pass.cpp
+++ b/libcxxabi/test/unwind_06.pass.cpp
@@ -13,6 +13,11 @@
 #include <assert.h>
 #include <stdio.h>
 
+// Suppress diagnostics about deprecated volatile operations
+#if defined(__GNUC__) && !defined(__clang__)
+# pragma GCC diagnostic ignored "-Wvolatile"
+#endif
+
 // Compile with -Os to get compiler uses float registers to hold float variables
 
 double get_(int x) { return (double)x; }
@@ -138,7 +143,7 @@ double foo()
   try {
     try1(true);
   }
-  catch (int e) {
+  catch (int) {
   }
   assert(a == get(1));
   assert(b == get(2));
@@ -152,7 +157,7 @@ double foo()
   try {
     try2(true);
   }
-  catch (int e) {
+  catch (int) {
   }
   assert(a == get(1));
   assert(b == get(2));
@@ -166,7 +171,7 @@ double foo()
   try {
     try3(true);
   }
-  catch (int e) {
+  catch (int) {
   }
   assert(a == get(1));
   assert(b == get(2));
@@ -180,7 +185,7 @@ double foo()
   try {
     try4(true);
   }
-  catch (int e) {
+  catch (int) {
   }
   assert(a == get(1));
   assert(b == get(2));
@@ -194,7 +199,7 @@ double foo()
   try {
     try5(true);
   }
-  catch (int e) {
+  catch (int) {
   }
   assert(a == get(1));
   assert(b == get(2));
@@ -208,7 +213,7 @@ double foo()
   try {
     try6(true);
   }
-  catch (int e) {
+  catch (int) {
   }
   assert(a == get(1));
   assert(b == get(2));
@@ -222,7 +227,7 @@ double foo()
   try {
     try7(true);
   }
-  catch (int e) {
+  catch (int) {
   }
   assert(a == get(1));
   assert(b == get(2));
@@ -236,7 +241,7 @@ double foo()
   try {
     try8(true);
   }
-  catch (int e) {
+  catch (int) {
   }
   assert(a == get(1));
   assert(b == get(2));


        


More information about the libcxx-commits mailing list