Title: [279073] trunk
Revision
279073
Author
[email protected]
Date
2021-06-21 11:48:29 -0700 (Mon, 21 Jun 2021)

Log Message

makeUnique cannot be used to instantiate function-local classes
https://bugs.webkit.org/show_bug.cgi?id=227163

Patch by Kimmo Kinnunen <[email protected]> on 2021-06-21
Reviewed by Antti Koivisto.

Source/bmalloc:

Make WTF_MAKE_FAST_ALLOCATED and similar macros work in function
local classes. Mark the typedef that is used to enforce semicolon
after the macro as unused to avoid unused typedef warning.
Fixes cases where the compiler is able to prove that it sees all the
use sites of the class and the typedef is not used.

* bmalloc/BCompiler.h:
* bmalloc/BMalloced.h:
* bmalloc/IsoHeap.h:
* bmalloc/IsoHeapInlines.h:

Source/_javascript_Core:

Make JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED
consistent with WTF_MAKE_FAST_ALLOCATED behavior
with respect to unused typedefs inside the macro.

* parser/Nodes.h:

Source/WTF:

Make WTF_MAKE_FAST_ALLOCATED and similar macros work in function
local classes. Mark the typedef that is used to enforce semicolon
after the macro as unused to avoid unused typedef warning.
Fixes cases where the compiler is able to prove that it sees all the
use sites of the class and the typedef is not used.

* wtf/Compiler.h:
* wtf/FastMalloc.h:

Tools:

Test that WTF_MAKE_FAST_ALLOCATED and similar macros work in function
local classes.

* TestWebKitAPI/Tests/WTF/StdLibExtras.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/ChangeLog (279072 => 279073)


--- trunk/Source/_javascript_Core/ChangeLog	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-06-21 18:48:29 UTC (rev 279073)
@@ -1,3 +1,16 @@
+2021-06-21  Kimmo Kinnunen  <[email protected]>
+
+        makeUnique cannot be used to instantiate function-local classes
+        https://bugs.webkit.org/show_bug.cgi?id=227163
+
+        Reviewed by Antti Koivisto.
+
+        Make JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED
+        consistent with WTF_MAKE_FAST_ALLOCATED behavior
+        with respect to unused typedefs inside the macro.
+
+        * parser/Nodes.h:
+
 2021-06-20  Yusuke Suzuki  <[email protected]>
 
         [JSC] Add ValueOf fast path in toPrimitive

Modified: trunk/Source/_javascript_Core/parser/Nodes.h (279072 => 279073)


--- trunk/Source/_javascript_Core/parser/Nodes.h	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Source/_javascript_Core/parser/Nodes.h	2021-06-21 18:48:29 UTC (rev 279073)
@@ -129,7 +129,7 @@
     public: \
         JSC_MAKE_PARSER_ARENA_DELETABLE_ALLOCATED_IMPL(__classToNew) \
     private: \
-        typedef int __thisIsHereToForceASemicolonAfterThisMacro
+        typedef int __thisIsHereToForceASemicolonAfterThisMacro UNUSED_TYPE_ALIAS
 
     DECLARE_ALLOCATOR_WITH_HEAP_IDENTIFIER(ParserArenaRoot);
     class ParserArenaRoot {

Modified: trunk/Source/WTF/ChangeLog (279072 => 279073)


--- trunk/Source/WTF/ChangeLog	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Source/WTF/ChangeLog	2021-06-21 18:48:29 UTC (rev 279073)
@@ -1,3 +1,19 @@
+2021-06-21  Kimmo Kinnunen  <[email protected]>
+
+        makeUnique cannot be used to instantiate function-local classes
+        https://bugs.webkit.org/show_bug.cgi?id=227163
+
+        Reviewed by Antti Koivisto.
+
+        Make WTF_MAKE_FAST_ALLOCATED and similar macros work in function
+        local classes. Mark the typedef that is used to enforce semicolon
+        after the macro as unused to avoid unused typedef warning.
+        Fixes cases where the compiler is able to prove that it sees all the
+        use sites of the class and the typedef is not used.
+
+        * wtf/Compiler.h:
+        * wtf/FastMalloc.h:
+
 2021-06-21  Philippe Normand  <[email protected]>
 
         Unreviewed build fix after r279062

Modified: trunk/Source/WTF/wtf/Compiler.h (279072 => 279073)


--- trunk/Source/WTF/wtf/Compiler.h	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Source/WTF/wtf/Compiler.h	2021-06-21 18:48:29 UTC (rev 279073)
@@ -352,6 +352,16 @@
 #define UNUSED_FUNCTION
 #endif
 
+/* UNUSED_TYPE_ALIAS */
+
+#if !defined(UNUSED_TYPE_ALIAS) && COMPILER(GCC_COMPATIBLE)
+#define UNUSED_TYPE_ALIAS __attribute__((unused))
+#endif
+
+#if !defined(UNUSED_TYPE_ALIAS)
+#define UNUSED_TYPE_ALIAS
+#endif
+
 /* REFERENCED_FROM_ASM */
 
 #if !defined(REFERENCED_FROM_ASM) && COMPILER(GCC_COMPATIBLE)

Modified: trunk/Source/WTF/wtf/FastMalloc.h (279072 => 279073)


--- trunk/Source/WTF/wtf/FastMalloc.h	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Source/WTF/wtf/FastMalloc.h	2021-06-21 18:48:29 UTC (rev 279073)
@@ -400,11 +400,11 @@
 public: \
     WTF_MAKE_FAST_ALLOCATED_IMPL \
 private: \
-using __thisIsHereToForceASemicolonAfterThisMacro = int
+using __thisIsHereToForceASemicolonAfterThisMacro UNUSED_TYPE_ALIAS = int
 
 #define WTF_MAKE_STRUCT_FAST_ALLOCATED \
     WTF_MAKE_FAST_ALLOCATED_IMPL \
-using __thisIsHereToForceASemicolonAfterThisMacro = int
+using __thisIsHereToForceASemicolonAfterThisMacro UNUSED_TYPE_ALIAS = int
 
 #if ENABLE(MALLOC_HEAP_BREAKDOWN)
 
@@ -443,7 +443,7 @@
     WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER_IMPL(classname) \
 private: \
     WTF_EXPORT_PRIVATE static WTF::DebugHeap& debugHeap(const char*); \
-using __thisIsHereToForceASemicolonAfterThisMacro = int
+using __thisIsHereToForceASemicolonAfterThisMacro UNUSED_TYPE_ALIAS = int
 
 #define WTF_MAKE_STRUCT_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(className) \
 private: \
@@ -450,7 +450,7 @@
     WTF_EXPORT_PRIVATE static WTF::DebugHeap& debugHeap(const char*); \
 public: \
     WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER_IMPL(className) \
-using __thisIsHereToForceASemicolonAfterThisMacro = int
+using __thisIsHereToForceASemicolonAfterThisMacro UNUSED_TYPE_ALIAS = int
 
 #else
 
@@ -461,11 +461,11 @@
 public: \
     WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER_IMPL(classname) \
 private: \
-using __thisIsHereToForceASemicolonAfterThisMacro = int
+using __thisIsHereToForceASemicolonAfterThisMacro UNUSED_TYPE_ALIAS = int
 
 #define WTF_MAKE_STRUCT_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(className) \
 public: \
     WTF_MAKE_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER_IMPL(className) \
-using __thisIsHereToForceASemicolonAfterThisMacro = int
+using __thisIsHereToForceASemicolonAfterThisMacro UNUSED_TYPE_ALIAS = int
 
 #endif

Modified: trunk/Source/WTF/wtf/JSValueMalloc.h (279072 => 279073)


--- trunk/Source/WTF/wtf/JSValueMalloc.h	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Source/WTF/wtf/JSValueMalloc.h	2021-06-21 18:48:29 UTC (rev 279073)
@@ -64,7 +64,7 @@
         return location; \
     } \
 private: \
-typedef int __thisIsHereToForceASemicolonAfterThisMacro
+typedef int __thisIsHereToForceASemicolonAfterThisMacro UNUSED_TYPE_ALIAS
 
 
 struct JSValueMalloc {

Modified: trunk/Source/bmalloc/ChangeLog (279072 => 279073)


--- trunk/Source/bmalloc/ChangeLog	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Source/bmalloc/ChangeLog	2021-06-21 18:48:29 UTC (rev 279073)
@@ -1,3 +1,21 @@
+2021-06-21  Kimmo Kinnunen  <[email protected]>
+
+        makeUnique cannot be used to instantiate function-local classes
+        https://bugs.webkit.org/show_bug.cgi?id=227163
+
+        Reviewed by Antti Koivisto.
+
+        Make WTF_MAKE_FAST_ALLOCATED and similar macros work in function
+        local classes. Mark the typedef that is used to enforce semicolon
+        after the macro as unused to avoid unused typedef warning.
+        Fixes cases where the compiler is able to prove that it sees all the
+        use sites of the class and the typedef is not used.
+
+        * bmalloc/BCompiler.h:
+        * bmalloc/BMalloced.h:
+        * bmalloc/IsoHeap.h:
+        * bmalloc/IsoHeapInlines.h:
+
 2021-06-17  Mark Lam  <[email protected]>
 
         Define MacroAssemblerARM64E::numberOfPACBits based on OS_CONSTANT(EFFECTIVE_ADDRESS_WIDTH).

Modified: trunk/Source/bmalloc/bmalloc/BCompiler.h (279072 => 279073)


--- trunk/Source/bmalloc/bmalloc/BCompiler.h	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Source/bmalloc/bmalloc/BCompiler.h	2021-06-21 18:48:29 UTC (rev 279073)
@@ -79,3 +79,13 @@
 #if !defined(BFALLTHROUGH)
 #define BFALLTHROUGH
 #endif
+
+/* BUNUSED_TYPE_ALIAS */
+
+#if !defined(BUNUSED_TYPE_ALIAS) && BCOMPILER(GCC_COMPATIBLE)
+#define BUNUSED_TYPE_ALIAS __attribute__((unused))
+#endif
+
+#if !defined(BUNUSED_TYPE_ALIAS)
+#define BUNUSED_TYPE_ALIAS
+#endif

Modified: trunk/Source/bmalloc/bmalloc/BMalloced.h (279072 => 279073)


--- trunk/Source/bmalloc/bmalloc/BMalloced.h	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Source/bmalloc/bmalloc/BMalloced.h	2021-06-21 18:48:29 UTC (rev 279073)
@@ -52,5 +52,5 @@
         ::bmalloc::api::freeOutOfLine(p); \
     } \
 private: \
-typedef int __thisIsHereToForceASemicolonAfterThisMacro
+typedef int __thisIsHereToForceASemicolonAfterThisMacro BUNUSED_TYPE_ALIAS
 

Modified: trunk/Source/bmalloc/bmalloc/IsoHeap.h (279072 => 279073)


--- trunk/Source/bmalloc/bmalloc/IsoHeap.h	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Source/bmalloc/bmalloc/IsoHeap.h	2021-06-21 18:48:29 UTC (rev 279073)
@@ -96,6 +96,6 @@
     void operator delete[](void* p) = delete; \
 using webkitFastMalloced = int; \
 private: \
-using __makeBisoMallocedMacroSemicolonifier = int
+using __makeBisoMallocedMacroSemicolonifier BUNUSED_TYPE_ALIAS = int
 
 } } // namespace bmalloc::api

Modified: trunk/Source/bmalloc/bmalloc/IsoHeapInlines.h (279072 => 279073)


--- trunk/Source/bmalloc/bmalloc/IsoHeapInlines.h	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Source/bmalloc/bmalloc/IsoHeapInlines.h	2021-06-21 18:48:29 UTC (rev 279073)
@@ -136,7 +136,7 @@
     void operator delete[](void* p) = delete; \
 using webkitFastMalloced = int; \
 private: \
-using __makeBisoMallocedInlineMacroSemicolonifier = int
+using __makeBisoMallocedInlineMacroSemicolonifier BUNUSED_TYPE_ALIAS = int
 
 #define MAKE_BISO_MALLOCED_IMPL(isoType) \
 ::bmalloc::api::IsoHeap<isoType>& isoType::bisoHeap() \

Modified: trunk/Tools/ChangeLog (279072 => 279073)


--- trunk/Tools/ChangeLog	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Tools/ChangeLog	2021-06-21 18:48:29 UTC (rev 279073)
@@ -1,3 +1,16 @@
+2021-06-21  Kimmo Kinnunen  <[email protected]>
+
+        makeUnique cannot be used to instantiate function-local classes
+        https://bugs.webkit.org/show_bug.cgi?id=227163
+
+        Reviewed by Antti Koivisto.
+
+        Test that WTF_MAKE_FAST_ALLOCATED and similar macros work in function
+        local classes.
+
+        * TestWebKitAPI/Tests/WTF/StdLibExtras.cpp:
+        (TestWebKitAPI::TEST):
+
 2021-06-21  Alex Christensen  <[email protected]>
 
         REGRESSION (r275496): WebSocket Message too long when message is larger than 1mb

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/StdLibExtras.cpp (279072 => 279073)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/StdLibExtras.cpp	2021-06-21 18:46:31 UTC (rev 279072)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/StdLibExtras.cpp	2021-06-21 18:48:29 UTC (rev 279073)
@@ -111,4 +111,20 @@
 TEST(WTF_StdLibExtras, findBitInWord_uint32_t) { testFindBitInWord<uint32_t>(); }
 TEST(WTF_StdLibExtras, findBitInWord_uint64_t) { testFindBitInWord<uint64_t>(); }
 
+// Tests that function-local types can be instantiated with makeUnique.
+// Style check would complain about use of std::make_unique, enforcing use of
+// makeUnique. The makeUnique needs WTF_..._MAKE_FAST_ALLOCATED.
+// There used to be a warn-unused-typedef errors when using these.
+TEST(WTF_StdLibExtras, MakeUniqueFunctionLocalTypeCompiles)
+{
+    struct LocalStruct {
+        WTF_MAKE_STRUCT_FAST_ALLOCATED;
+    };
+    class LocalClass {
+        WTF_MAKE_FAST_ALLOCATED;
+    };
+    auto s = makeUnique<LocalStruct>();
+    auto c = makeUnique<LocalClass>();
+}
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to