mach: Use if constexpr to wrap protected exception handling cases [crashpad/crashpad : main]

5 views
Skip to first unread message

Justin Cohen (Gerrit)

unread,
May 28, 2026, 7:58:14 PM (8 days ago) May 28
to Mark Mentovai, David Benjamin, crashp...@chromium.org
Attention needed from David Benjamin and Mark Mentovai

Justin Cohen added 1 comment

Patchset-level comments
File-level comment, Patchset 2 (Latest):
Justin Cohen . resolved

I don't love this. Is there a better way to do this?

Open in Gerrit

Related details

Attention is currently required from:
  • David Benjamin
  • Mark Mentovai
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: crashpad/crashpad
Gerrit-Branch: main
Gerrit-Change-Id: I1d4ae2d46d91d87aa67d5a5a5e445d1f9e2dc067
Gerrit-Change-Number: 7880932
Gerrit-PatchSet: 2
Gerrit-Owner: Justin Cohen <justi...@google.com>
Gerrit-Reviewer: David Benjamin <davi...@chromium.org>
Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
Gerrit-Attention: Mark Mentovai <ma...@chromium.org>
Gerrit-Attention: David Benjamin <davi...@chromium.org>
Gerrit-Comment-Date: Thu, 28 May 2026 23:58:12 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Mark Mentovai (Gerrit)

unread,
May 29, 2026, 11:24:01 AM (8 days ago) May 29
to Justin Cohen, Dave Tapuska, David Benjamin, crashp...@chromium.org
Attention needed from David Benjamin and Justin Cohen

Mark Mentovai added 9 comments

Patchset-level comments
Mark Mentovai . resolved

Was davidben right? Maybe this should have been dtapuska?

Justin Cohen . unresolved

I don't love this. Is there a better way to do this?

Mark Mentovai

I don't love this. Is there a better way to do this?

What do you think of this suggestion?

Commit Message
Line 18, Patchset 2 (Latest):Wrap the bodies of these cases in a compile-time if constexpr check
so they are only compiled and instantiated when Traits = MachExcTraits,
resolving compile-time type-safety issues.
Mark Mentovai . unresolved

When the changes are made, adjust this accordingly.

File util/mach/exc_server_variants.cc
Line 487, Patchset 2 (Latest): case MachExcTraits::kMachMessageIDExceptionRaiseIdentityProtected: {
Mark Mentovai . unresolved

Here’s what I suggest:

1. Remove the `default:` label from this `switch` statement. See (5) below for the new way to handle that case.
2. After this `switch` statement, introduce _a new_ `switch` statement, but put it inside a single `if constexpr` (as on your line 490, modified by my comment there).
3. Move the handling of these two message types into that new `switch` statement.
4. This `case` line, and the one for `kMachMessageIDExceptionRaiseIdentityProtected`, will now be “protected” by the `if constexpr`, so you can rewrite `MachExcTraits` to the more natural and correct `Traits`.
5. Instead of ` default:` label in either `switch` statement, this function will change to put the code formerly in the `default:` label to be beyond both `switch` statements, outside of the `if constexpr`.

It’s a small amount of additional hoisting, but I bet that the diff will remain essentially as clean as it is now, with primarily only whitespace indentation changes. The structure of the code will be cleaner and much more logical. The abuse of `MachExcTraits` values for `exc`-subsystem requests will come to an end.

The new structure may even enable further cleanups.

Line 490, Patchset 2 (Latest): if constexpr (!std::is_same_v<Traits, MachExcTraits>) {
Mark Mentovai . unresolved

Frame this in the affirmative instead: you want to bail out here if `Traits` is `ExcTraits`.

Line 495, Patchset 2 (Latest): typename MachExcTraits::ExceptionRaiseIdentityProtectedRequest;
Mark Mentovai . unresolved

This can go back to being `Traits` now.

Line 498, Patchset 2 (Latest): MachExcTraits::MIGCheckRequestExceptionRaiseIdentityProtected(
Mark Mentovai . unresolved

This too.

Line 557, Patchset 2 (Latest): typename MachExcTraits::ExceptionRaiseIdentityProtectedReply;
Mark Mentovai . unresolved

And this.

Line 590, Patchset 2 (Latest): if constexpr (!std::is_same_v<Traits, MachExcTraits>) {
Mark Mentovai . unresolved

Same here, and also with the `MachExcTraits`/`Traits` changes that follow.

Open in Gerrit

Related details

Attention is currently required from:
  • David Benjamin
  • Justin Cohen
Submit Requirements:
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: crashpad/crashpad
    Gerrit-Branch: main
    Gerrit-Change-Id: I1d4ae2d46d91d87aa67d5a5a5e445d1f9e2dc067
    Gerrit-Change-Number: 7880932
    Gerrit-PatchSet: 2
    Gerrit-Owner: Justin Cohen <justi...@google.com>
    Gerrit-Reviewer: David Benjamin <davi...@chromium.org>
    Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
    Gerrit-CC: Dave Tapuska <dtap...@chromium.org>
    Gerrit-Attention: Justin Cohen <justi...@google.com>
    Gerrit-Attention: David Benjamin <davi...@chromium.org>
    Gerrit-Comment-Date: Fri, 29 May 2026 15:23:57 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Justin Cohen <justi...@google.com>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    Mark Mentovai (Gerrit)

    unread,
    May 29, 2026, 11:26:27 AM (8 days ago) May 29
    to Justin Cohen, David Benjamin, crashp...@chromium.org
    Attention needed from David Benjamin and Justin Cohen

    Mark Mentovai added 1 comment

    Patchset-level comments
    Mark Mentovai . resolved

    Was davidben right? Maybe this should have been dtapuska?

    Mark Mentovai
    Open in Gerrit

    Related details

    Attention is currently required from:
    • David Benjamin
    • Justin Cohen
    Submit Requirements:
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: crashpad/crashpad
    Gerrit-Branch: main
    Gerrit-Change-Id: I1d4ae2d46d91d87aa67d5a5a5e445d1f9e2dc067
    Gerrit-Change-Number: 7880932
    Gerrit-PatchSet: 2
    Gerrit-Owner: Justin Cohen <justi...@google.com>
    Gerrit-Reviewer: David Benjamin <davi...@chromium.org>
    Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
    Gerrit-Attention: Justin Cohen <justi...@google.com>
    Gerrit-Attention: David Benjamin <davi...@chromium.org>
    Gerrit-Comment-Date: Fri, 29 May 2026 15:26:25 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Mark Mentovai <ma...@chromium.org>
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy

    David Benjamin (Gerrit)

    unread,
    May 29, 2026, 11:43:59 AM (8 days ago) May 29
    to Justin Cohen, Mark Mentovai, crashp...@chromium.org
    Attention needed from Justin Cohen

    David Benjamin added 1 comment

    Patchset-level comments
    Mark Mentovai . resolved

    Was davidben right? Maybe this should have been dtapuska?

    Mark Mentovai

    davidben was right. Context: [link](https://chromium-review.googlesource.com/c/7204428/21#message-b5a9b7b32b6a279f2d5759278aa8abc97f4beb75). Sorry for the noise. Dave.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Justin Cohen
    Submit Requirements:
    • requirement satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement is not satisfiedNo-Unresolved-Comments
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: crashpad/crashpad
    Gerrit-Branch: main
    Gerrit-Change-Id: I1d4ae2d46d91d87aa67d5a5a5e445d1f9e2dc067
    Gerrit-Change-Number: 7880932
    Gerrit-PatchSet: 2
    Gerrit-Owner: Justin Cohen <justi...@google.com>
    Gerrit-Reviewer: David Benjamin <davi...@chromium.org>
    Gerrit-Reviewer: Mark Mentovai <ma...@chromium.org>
    Gerrit-Attention: Justin Cohen <justi...@google.com>
    Gerrit-Comment-Date: Fri, 29 May 2026 15:43:57 +0000
    satisfied_requirement
    unsatisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages