This is an archive of the discontinued LLVM Phabricator instance.

[libc++][hardening] Don't trigger uncategorized assertions in the hardened mode.
ClosedPublic

Authored by var-const on Jul 20 2023, 10:21 AM.

Details

Summary

The hardened mode is intended to only include security-critical,
relatively low-overhead checks that are intended to be usable in
production. By default, assertions are excluded from this mode.

Diff Detail

Event Timeline

var-const created this revision.Jul 20 2023, 10:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2023, 10:21 AM
var-const requested review of this revision.Jul 20 2023, 10:21 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2023, 10:21 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript

Run the tests intended for debug mode in hardened mode, but x-fail them.

Mordante added inline comments.
libcxx/include/__config
287

I noticed there are quite a number of cheap tests in this category. For example nullptr guards in std::string. Would it make sense to put them in a "cheap-to-test-category". Maybe a _LIBCPP_ASSERT_PRECONDITION?

ldionne accepted this revision.Jul 20 2023, 11:37 AM
ldionne added a subscriber: ldionne.

LGTM w/ UNSUPPORTED and green CI! Thanks!

libcxx/include/__config
287

I suggest we discuss this in D155873.

libcxx/test/libcxx/algorithms/alg.sorting/assert.min.max.pass.cpp
13 ↗(On Diff #542587)

As a follow-up patch, I think we could do this:

# This,
AddFeature("libcpp-has-hardened-mode")             if hardening_mode == "hardened" else None,
AddFeature("libcpp-has-debug-mode")                if hardening_mode == "debug" else None,
AddFeature("libcpp-has-unchecked-mode")            if hardening_mode == "unchecked" else None,

# Or that
AddFeature(f"libcpp-hardening-mode={hardening_mode}")

And then we could switch to // UNSUPPORTED: libcpp-has-unchecked-mode (or the other syntax). This would be a bit easier to understand.

15 ↗(On Diff #542587)

In this patch, I would use UNSUPPORTED here. Using XFAIL is really nice in theory because it will notify us if we forget to un-XFAIL a test after adding an assertion to the hardened mode, but unfortunately the test is UB when it's run outside of the debug mode. So in practice I think the only thing we can use consistently is UNSUPPORTED. For example you mentioned one of the barrier tests timing out.

This revision is now accepted and ready to land.Jul 20 2023, 11:37 AM
var-const updated this revision to Diff 542726.Jul 20 2023, 5:21 PM
var-const marked 2 inline comments as done.

Address feedback and fix the CI.

var-const marked an inline comment as done.Jul 20 2023, 6:07 PM
var-const added inline comments.
libcxx/include/__config
287

@Mordante I think it would be easier to discuss in the other patch like @ldionne suggested above because it deals with some of those assertions (including the nullptr guards in string).

libcxx/test/libcxx/algorithms/alg.sorting/assert.min.max.pass.cpp
13 ↗(On Diff #542587)
var-const marked an inline comment as done.Jul 20 2023, 10:50 PM
Mordante added inline comments.Jul 21 2023, 10:38 AM
libcxx/include/__config
287

That's fine by me.