Changeset 248930 in webkit


Ignore:
Timestamp:
Aug 20, 2019, 6:36:41 PM (6 years ago)
Author:
mark.lam@apple.com
Message:

Make it easier to pass pointers to WTFCrashWithInfo.
https://bugs.webkit.org/show_bug.cgi?id=200960

Reviewed by Saam Barati and Yusuke Suzuki.

Now, we don't have to explicitly cast them to uint64_ts first. The template
wrappers will take care of it for us.

  • wtf/Assertions.h:

(wtfCrashArg):
(WTFCrashWithInfo):
(WTF::isIntegralOrPointerType):
(WTF::isIntegralType): Deleted.

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r248913 r248930  
     12019-08-20  Mark Lam  <mark.lam@apple.com>
     2
     3        Make it easier to pass pointers to WTFCrashWithInfo.
     4        https://bugs.webkit.org/show_bug.cgi?id=200960
     5
     6        Reviewed by Saam Barati and Yusuke Suzuki.
     7
     8        Now, we don't have to explicitly cast them to uint64_ts first.  The template
     9        wrappers will take care of it for us.
     10
     11        * wtf/Assertions.h:
     12        (wtfCrashArg):
     13        (WTFCrashWithInfo):
     14        (WTF::isIntegralOrPointerType):
     15        (WTF::isIntegralType): Deleted.
     16
    1172019-08-20  Saam Barati  <sbarati@apple.com>
    218
  • trunk/Source/WTF/wtf/Assertions.h

    r248008 r248930  
    11/*
    2  * Copyright (C) 2003-2017 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2003-2019 Apple Inc.  All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    550550#ifdef __cplusplus
    551551
     552template<typename T>
     553ALWAYS_INLINE uint64_t wtfCrashArg(T* arg) { return reinterpret_cast<uintptr_t>(arg); }
     554
     555template<typename T>
     556ALWAYS_INLINE uint64_t wtfCrashArg(T arg) { return arg; }
     557
     558template<typename T>
     559NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void WTFCrashWithInfo(int line, const char* file, const char* function, int counter, T reason)
     560{
     561    WTFCrashWithInfo(line, file, function, counter, wtfCrashArg(reason));
     562}
     563
     564template<typename T, typename U>
     565NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void WTFCrashWithInfo(int line, const char* file, const char* function, int counter, T reason, U misc1)
     566{
     567    WTFCrashWithInfo(line, file, function, counter, wtfCrashArg(reason), wtfCrashArg(misc1));
     568}
     569
     570template<typename T, typename U, typename V>
     571NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void WTFCrashWithInfo(int line, const char* file, const char* function, int counter, T reason, U misc1, V misc2)
     572{
     573    WTFCrashWithInfo(line, file, function, counter, wtfCrashArg(reason), wtfCrashArg(misc1), wtfCrashArg(misc2));
     574}
     575
     576template<typename T, typename U, typename V, typename W>
     577NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void WTFCrashWithInfo(int line, const char* file, const char* function, int counter, T reason, U misc1, V misc2, W misc3)
     578{
     579    WTFCrashWithInfo(line, file, function, counter, wtfCrashArg(reason), wtfCrashArg(misc1), wtfCrashArg(misc2), wtfCrashArg(misc3));
     580}
     581
     582template<typename T, typename U, typename V, typename W, typename X>
     583NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void WTFCrashWithInfo(int line, const char* file, const char* function, int counter, T reason, U misc1, V misc2, W misc3, X misc4)
     584{
     585    WTFCrashWithInfo(line, file, function, counter, wtfCrashArg(reason), wtfCrashArg(misc1), wtfCrashArg(misc2), wtfCrashArg(misc3), wtfCrashArg(misc4));
     586}
     587
     588template<typename T, typename U, typename V, typename W, typename X, typename Y>
     589NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void WTFCrashWithInfo(int line, const char* file, const char* function, int counter, T reason, U misc1, V misc2, W misc3, X misc4, Y misc5)
     590{
     591    WTFCrashWithInfo(line, file, function, counter, wtfCrashArg(reason), wtfCrashArg(misc1), wtfCrashArg(misc2), wtfCrashArg(misc3), wtfCrashArg(misc4), wtfCrashArg(misc5));
     592}
     593
     594template<typename T, typename U, typename V, typename W, typename X, typename Y, typename Z>
     595NO_RETURN_DUE_TO_CRASH ALWAYS_INLINE void WTFCrashWithInfo(int line, const char* file, const char* function, int counter, T reason, U misc1, V misc2, W misc3, X misc4, Y misc5, Z misc6)
     596{
     597    WTFCrashWithInfo(line, file, function, counter, wtfCrashArg(reason), wtfCrashArg(misc1), wtfCrashArg(misc2), wtfCrashArg(misc3), wtfCrashArg(misc4), wtfCrashArg(misc5), wtfCrashArg(misc6));
     598}
     599
    552600// The combination of line, file, function, and counter should be a unique number per call to this crash. This tricks the compiler into not coalescing calls to WTFCrashWithInfo.
    553601// The easiest way to fill these values per translation unit is to pass __LINE__, __FILE__, WTF_PRETTY_FUNCTION, and __COUNTER__.
     
    570618
    571619namespace WTF {
    572 inline void isIntegralType() { }
     620inline void isIntegralOrPointerType() { }
    573621
    574622template<typename T, typename... Types>
    575 void isIntegralType(T, Types... types)
    576 {
    577     static_assert(std::is_integral<T>::value || std::is_enum<T>::value, "All types need to be integral bitwise_cast to integral type for logging");
    578     isIntegralType(types...);
     623void isIntegralOrPointerType(T, Types... types)
     624{
     625    static_assert(std::is_integral<T>::value || std::is_enum<T>::value || std::is_pointer<T>::value, "All types need to be bitwise_cast-able to integral type for logging");
     626    isIntegralOrPointerType(types...);
    579627}
    580628}
     
    594642#if COMPILER(CLANG) || COMPILER(MSVC)
    595643#define CRASH_WITH_INFO(...) do { \
    596         WTF::isIntegralType(__VA_ARGS__); \
     644        WTF::isIntegralOrPointerType(__VA_ARGS__); \
    597645        compilerFenceForCrash(); \
    598646        WTFCrashWithInfo(__LINE__, __FILE__, WTF_PRETTY_FUNCTION, __COUNTER__, ##__VA_ARGS__); \
Note: See TracChangeset for help on using the changeset viewer.