[clang] 133b6d7 - [clang][C++20] Fix clang/clangd assert/crash after compilation errors
Dmitry Polukhin via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 17 07:54:10 PDT 2022
Author: Dmitry Polukhin
Date: 2022-09-17T07:37:19-07:00
New Revision: 133b6d7db90d9b52b01e8e09e1aa8fb8d2da0f9d
URL: https://github.com/llvm/llvm-project/commit/133b6d7db90d9b52b01e8e09e1aa8fb8d2da0f9d
DIFF: https://github.com/llvm/llvm-project/commit/133b6d7db90d9b52b01e8e09e1aa8fb8d2da0f9d.diff
LOG: [clang][C++20] Fix clang/clangd assert/crash after compilation errors
After compilation errors, expression a transformation result may not be usable.
It triggers an assert in RemoveNestedImmediateInvocation and SIGSEGV in case of
builds without asserts. This issue significantly affects clangd because source
may not be valid during typing. Tests cases that I attached was reduce from huge
C++ translation unit.
Test Plan: check-clang
Differential Revision: https://reviews.llvm.org/D133948
Added:
clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp
Modified:
clang/lib/Sema/SemaExpr.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index e53c88b283b8..b49b7ce45cf4 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17624,9 +17624,13 @@ static void RemoveNestedImmediateInvocation(
Transformer.AllowSkippingFirstCXXConstructExpr = false;
ExprResult Res = Transformer.TransformExpr(It->getPointer()->getSubExpr());
- assert(Res.isUsable());
- Res = SemaRef.MaybeCreateExprWithCleanups(Res);
- It->getPointer()->setSubExpr(Res.get());
+ // The result may not be usable in case of previous compilation errors.
+ // In this case evaluation of the expression may result in crash so just
+ // don't do anything further with the result.
+ if (Res.isUsable()) {
+ Res = SemaRef.MaybeCreateExprWithCleanups(Res);
+ It->getPointer()->setSubExpr(Res.get());
+ }
}
static void
diff --git a/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp b/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp
new file mode 100644
index 000000000000..26faf2bc1c06
--- /dev/null
+++ b/clang/test/SemaCXX/remove-nested-immediate-invocation-crash.cpp
@@ -0,0 +1,11 @@
+// RUN: not %clang_cc1 -fsyntax-only -verify -std=gnu++20 -ferror-limit 19 %s
+// Creduced test case for the crash in RemoveNestedImmediateInvocation after compliation errros.
+
+a, class b { template < typename c> consteval b(c
+} template <typename...> using d = b;
+auto e(d<>) -> int:;
+}
+f
+}
+g() {
+ auto h = "":(::i(e(h))
More information about the cfe-commits
mailing list