-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++][hardening] Always enable all checks during constant evaluation #107713
base: main
Are you sure you want to change the base?
Changes from all commits
c115b14
817d019
9320bb2
c1c4505
006e98d
c9ac5fe
a05ff10
d80a2ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
// Make sure that both `_LIBCPP_ASSERT(false, ...)` and `_LIBCPP_ASSUME(false)` | ||
// mean that a constant expression cannot be formed. | ||
|
||
#include <__assert> | ||
#include "test_macros.h" | ||
|
||
// expected-note@*:* 0+ {{expanded from macro}} | ||
|
||
static_assert((_LIBCPP_ASSERT(false, "message"), true), ""); | ||
// expected-error@-1 {{static assertion expression is not an integral constant expression}} | ||
|
||
static_assert((_LIBCPP_ASSUME(false), true), ""); | ||
// expected-error@-1 {{static assertion expression is not an integral constant expression}} | ||
Comment on lines
+17
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's enough to have a single check that asserts always fire during constant evaluation. There's no way to differentiate between the different ways of getting into constant evaluation AFAIK. We can also use |
||
|
||
static_assert(!__builtin_constant_p(_LIBCPP_ASSERT(false, "message")), ""); | ||
static_assert(!__builtin_constant_p(_LIBCPP_ASSUME(false)), ""); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,8 +40,8 @@ | |
#ifndef TEST_HAS_NO_NASTY_STRING | ||
// Make sure the char-like operations in strings do not depend on the char-like type. | ||
struct nasty_char { | ||
template <typename T> | ||
friend auto operator<=>(T, T) = delete; | ||
template <typename T, typename U> | ||
friend auto operator<=>(T, U) = delete; | ||
Comment on lines
+43
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change looks a bit like something that should be in a separate patch. Is this change required as part of this patch? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some tests fail with the unstable ABI (See #107747). This is the easiest remedy to make It would make sense as a separate patch too, since these tests currently fail with unstable ABI + hardening right now. |
||
|
||
template <typename T> | ||
friend void operator+(T&&) = delete; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What exactly are you guarding against here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#107715 means that an unguarded:
doesn't actually ignore the diagnostic (The diagnostic being an assertion used in a consteval function or the true branch of a consteval if or some other manifestly constant evaluated context)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant where this is diagnosed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be diagnosed if used in a manifestly constant evaluated context. This is mainly in an
if consteval
branch orconsteval
function. Noif consteval
currently exists in libc++ and noconsteval
libc++ functions contain any assertions, but in the future they might.Also more exotic cases, like when the assertion is directly in a constinit initialiser, array bound or static_assert, like in the added test. But these will never happen in real libc++ code.