[clang] Fix crash when handling nested immediate invocations
authorMariya Podchishchaeva <mariya.podchishchaeva@intel.com>
Wed, 5 Apr 2023 09:01:42 +0000 (05:01 -0400)
committerMariya Podchishchaeva <mariya.podchishchaeva@intel.com>
Wed, 5 Apr 2023 09:20:51 +0000 (05:20 -0400)
commita5e1a93ea10ffc06a32df6d9f410e9b297ed136d
treeff5e694621d54fb4cb410d62ca532e70ac5a8272
parent7553bad1ac619d5de72489ec06b63a2ace356c22
[clang] Fix crash when handling nested immediate invocations

Before this patch it was expected that if there was several immediate
invocations they all belong to the same expression evaluation context.
During parsing of non local variable initializer a new evaluation context is
pushed, so code like this
```
namespace scope {
struct channel {
    consteval channel(const char* name) noexcept { }
};
consteval const char* make_channel_name(const char* name) { return name;}

channel rsx_log(make_channel_name("rsx_log"));
}
```
produced a nested immediate invocation whose subexpressions are attached
to different expression evaluation contexts. The constructor call
belongs to TU context and `make_channel_name` call to context of
variable initializer.

This patch removes this assumption and adds tracking of previously
failed immediate invocations, so it is possible when handling an
immediate invocation th check that its subexpressions from possibly another
evaluation context contains errors and not produce duplicate
diagnostics.

Fixes https://github.com/llvm/llvm-project/issues/58207

Reviewed By: aaron.ballman, shafik

Differential Revision: https://reviews.llvm.org/D146234
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx2a-consteval.cpp