-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang] fix sema init crashing on initialization sequences #98102
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5576,6 +5576,10 @@ static void TryOrBuildParenListInitialization( | |
ExprResult ER; | ||
ER = IS.Perform(S, SubEntity, SubKind, | ||
Arg ? MultiExprArg(Arg) : std::nullopt); | ||
|
||
if (ER.isInvalid()) | ||
return false; | ||
|
||
if (InitExpr) | ||
*InitExpr = ER.get(); | ||
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. ER.get() is null if we don't apply this fix. |
||
else | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s | ||
// expected-no-diagnostics | ||
|
||
template <bool v> | ||
struct BC { | ||
static constexpr bool value = v; | ||
}; | ||
|
||
template <typename T, typename Arg> | ||
struct Constructible : BC<__is_constructible(T, Arg)> {}; | ||
|
||
template <typename T> | ||
using Requires = T::value; | ||
|
||
template <typename T> | ||
struct optional { | ||
template <typename U, Requires<Constructible<T, U>> = true> | ||
optional(U) {} | ||
}; | ||
|
||
struct MO {}; | ||
struct S : MO {}; | ||
struct TB { | ||
TB(optional<S>) {} | ||
}; | ||
|
||
class TD : TB, MO { | ||
using TB::TB; | ||
}; | ||
|
||
void foo() { | ||
static_assert(Constructible<TD, TD>::value); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Under what circumstances does
IS.Failed()
returnfalse
above but when we perform the initialization we get a null expression back? That seems strange to me -- I would have naively expectedFailed()
to returntrue
in such a case. WDYT?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.
If you look at
InitializationSequence::Perform
(this function is 1000 lines long), it first checksFailed()
then proceed to build a whole bunch of things. There are a couple of places it returnedExprError
. I think it's possible to still be invalid after!Failed()
.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.
Ah you are correct, sorry! I see now that the common code pattern is to check
isInvalid()
on the returned result.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.
For
ExprResult
, I tend to findisUsable
to be more clear, and I thought is slightly more strict, as it also catches cases where the ER is unset. That said, we useisInvalid
all over the place, assuming that it would have been set to SOMETHING.