Skip to content

[Clang] Fix a crash in the diagnostic emission of invalid immediate calls #66699

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 1 commit into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ Bug Fixes to C++ Support
definition the specialization was instantiated from.
(`#26057 <https://github.com/llvm/llvm-project/issues/26057>`_`)

- Fix a crash when a default member initializer of a base aggregate
makes an invalid call to an immediate function.
(`#66324 <https://github.com/llvm/llvm-project/issues/66324>`_)

Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
- Fixed an import failure of recursive friend class template.
Expand Down
7 changes: 5 additions & 2 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2514,12 +2514,15 @@ void Sema::DiagnoseImmediateEscalatingReason(FunctionDecl *FD) {
Range = CurrentInit->isWritten() ? CurrentInit->getSourceRange()
: SourceRange();
}

FieldDecl* InitializedField = CurrentInit ? CurrentInit->getAnyMember() : nullptr;

SemaRef.Diag(Loc, diag::note_immediate_function_reason)
<< ImmediateFn << Fn << Fn->isConsteval() << IsCall
<< isa<CXXConstructorDecl>(Fn) << ImmediateFnIsConstructor
<< (CurrentInit != nullptr)
<< (InitializedField != nullptr)
<< (CurrentInit && !CurrentInit->isWritten())
<< (CurrentInit ? CurrentInit->getAnyMember() : nullptr) << Range;
<< InitializedField << Range;
}
bool TraverseCallExpr(CallExpr *E) {
if (const auto *DR =
Expand Down
23 changes: 23 additions & 0 deletions clang/test/SemaCXX/cxx2b-consteval-propagate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,26 @@ struct S {
S s(0); // expected-note {{in the default initializer of 'j'}}

}

namespace GH66324 {

consteval int allocate(); // expected-note 2{{declared here}}

struct _Vector_base {
int b = allocate(); // expected-note 2{{undefined function 'allocate' cannot be used in a constant expression}} \
// expected-error {{call to consteval function 'GH66324::allocate' is not a constant expression}} \
// expected-note {{declared here}}
};

template <typename>
struct vector : _Vector_base {
constexpr vector()
// expected-note@-1 {{'vector' is an immediate constructor because its body contains a call to a consteval function 'allocate' and that call is not a constant expression}}
: _Vector_base{} {} // expected-note {{in the default initializer of 'b'}}
};

vector<void> v{};
// expected-error@-1 {{call to immediate function 'GH66324::vector<void>::vector' is not a constant expression}}
// expected-note@-2 {{in call to 'vector()'}}

}