WebKit Bugzilla
Attachment 343813 Details for
Bug 186536
: WTF's internal std::optional implementation should abort() on bad optional access
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch (defines a new ASSERT macro without asm statement)
186536.patch (text/plain), 4.29 KB, created by
Frédéric Wang (:fredw)
on 2018-06-28 09:40:21 PDT
(
hide
)
Description:
Patch (defines a new ASSERT macro without asm statement)
Filename:
MIME Type:
Creator:
Frédéric Wang (:fredw)
Created:
2018-06-28 09:40:21 PDT
Size:
4.29 KB
patch
obsolete
>diff --git a/Source/WTF/ChangeLog b/Source/WTF/ChangeLog >index 326ba6f5c26..ab876dc4647 100644 >--- a/Source/WTF/ChangeLog >+++ b/Source/WTF/ChangeLog >@@ -1,3 +1,18 @@ >+2018-06-28 Frederic Wang <fwang@igalia.com> >+ >+ WTF's internal std::optional implementation should abort() on bad optional access >+ https://bugs.webkit.org/show_bug.cgi?id=186536 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ * wtf/Assertions.h: >+ * wtf/Optional.h: >+ (std::optional::operator ->): >+ (std::optional::operator *): >+ (std::optional::value const): >+ (std::optional::value): >+ (std::optional<T::value const): >+ > 2018-06-27 Jonathan Bedard <jbedard@apple.com> > > Enable WebKit iOS 12 build >diff --git a/Source/WTF/wtf/Assertions.h b/Source/WTF/wtf/Assertions.h >index 5e06eaa6e61..f38ff387d51 100644 >--- a/Source/WTF/wtf/Assertions.h >+++ b/Source/WTF/wtf/Assertions.h >@@ -287,6 +287,8 @@ WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH void WTFCrashWithSecurityImplication(v > > #define ASSERT_UNUSED(variable, assertion) ((void)variable) > >+#define ASSERT_UNDER_CONSTEXPR_CONTEXT(assertion) ((void)0) >+ > #if ENABLE(SECURITY_ASSERTIONS) > #define ASSERT_WITH_SECURITY_IMPLICATION(assertion) \ > (!(assertion) ? \ >@@ -337,6 +339,18 @@ WTF_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH void WTFCrashWithSecurityImplication(v > > #define NO_RETURN_DUE_TO_ASSERT NO_RETURN_DUE_TO_CRASH > >+/* ASSERT_UNDER_CONSTEXPR_CONTEXT >+ >+ This is a special version of ASSERT(assertion) that can be used in constexpr context. >+ */ >+#define ASSERT_UNDER_CONSTEXPR_CONTEXT(assertion) do { \ >+ if (!(assertion)) { \ >+ WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, #assertion); \ >+ __builtin_trap(); \ >+ __builtin_unreachable(); \ >+ } \ >+} while (0) >+ > /* ASSERT_WITH_SECURITY_IMPLICATION > > Failure of this assertion indicates a possible security vulnerability. >diff --git a/Source/WTF/wtf/Optional.h b/Source/WTF/wtf/Optional.h >index 67ee27752ff..d182dc8daa1 100644 >--- a/Source/WTF/wtf/Optional.h >+++ b/Source/WTF/wtf/Optional.h >@@ -530,8 +530,7 @@ public: > } > > OPTIONAL_MUTABLE_CONSTEXPR T* operator ->() { >- // FIXME: We need to offer special assert function that can be used under the contexpr context. >- // CONSTEXPR_ASSERT(initialized()); >+ ASSERT_UNDER_CONSTEXPR_CONTEXT(initialized()); > return dataptr(); > } > >@@ -540,32 +539,27 @@ public: > } > > OPTIONAL_MUTABLE_CONSTEXPR T& operator *() & { >- // FIXME: We need to offer special assert function that can be used under the contexpr context. >- // CONSTEXPR_ASSERT(initialized()); >+ ASSERT_UNDER_CONSTEXPR_CONTEXT(initialized()); > return contained_val(); > } > > OPTIONAL_MUTABLE_CONSTEXPR T&& operator *() && { >- // FIXME: We need to offer special assert function that can be used under the contexpr context. >- // CONSTEXPR_ASSERT(initialized()); >+ ASSERT_UNDER_CONSTEXPR_CONTEXT(initialized()); > return detail_::constexpr_move(contained_val()); > } > > constexpr T const& value() const& { >- // FIXME: We need to offer special assert function that can be used under the contexpr context. >- // return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); >+ ASSERT_UNDER_CONSTEXPR_CONTEXT(initialized()); > return contained_val(); > } > > OPTIONAL_MUTABLE_CONSTEXPR T& value() & { >- // FIXME: We need to offer special assert function that can be used under the contexpr context. >- // return initialized() ? contained_val() : (throw bad_optional_access("bad optional access"), contained_val()); >+ ASSERT_UNDER_CONSTEXPR_CONTEXT(initialized()); > return contained_val(); > } > > OPTIONAL_MUTABLE_CONSTEXPR T&& value() && { >- // FIXME: We need to offer special assert function that can be used under the contexpr context. >- // if (!initialized()) __THROW_EXCEPTION(bad_optional_access("bad optional access")); >+ ASSERT_UNDER_CONSTEXPR_CONTEXT(initialized()); > return std::move(contained_val()); > } > >@@ -683,8 +677,7 @@ public: > } > > constexpr T& value() const { >- // FIXME: We need to offer special assert function that can be used under the contexpr context. >- // return ref ? *ref : (throw bad_optional_access("bad optional access"), *ref); >+ ASSERT_UNDER_CONSTEXPR_CONTEXT(ref()); > return *ref; > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 186536
:
342475
|
342491
|
342505
|
343716
|
343763
|
343812
|
343813
|
343840
|
343898
|
344000
|
344007
|
344009
|
344010
|
344081
|
344412
|
344420