cor3ntin updated this revision to Diff 518161.
cor3ntin added a comment.
I don't think this is actually testable, ultimately we may run out of stack
any way, the warning (when emitted) even say so.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142401/new/
https://reviews.llvm.org/D142401
Files:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/cxx11-default-member-initializers-recurse.cpp
Index: clang/test/SemaCXX/cxx11-default-member-initializers-recurse.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/cxx11-default-member-initializers-recurse.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -std=c++20 %s
+
+// Recursively constructing default member initializers
+// should not crash clang.
+namespace GH60082 {
+
+struct A;
+
+int f(const A&) { return 42; }
+
+struct A {
+ int x = f(A());
+ A() { }
+};
+
+void foo() { A(); }
+
+}
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -5926,7 +5926,9 @@
Param);
ExprEvalContexts.back().IsCurrentlyCheckingDefaultArgumentOrInitializer =
SkipImmediateInvocations;
- MarkDeclarationsReferencedInExpr(Init, /*SkipLocalVariables*/ true);
+ runWithSufficientStackSpace(CallLoc, [&] {
+ MarkDeclarationsReferencedInExpr(Init, /*SkipLocalVariables=*/true);
+ });
return false;
}
@@ -6036,8 +6038,11 @@
ExprEvalContexts.back().DelayedDefaultInitializationContext = {
CallLoc, Param, CurContext};
EnsureImmediateInvocationInDefaultArgs Immediate(*this);
- ExprResult Res = Immediate.TransformInitializer(Param->getInit(),
- /*NotCopy=*/false);
+ ExprResult Res;
+ runWithSufficientStackSpace(CallLoc, [&] {
+ Res = Immediate.TransformInitializer(Param->getInit(),
+ /*NotCopy=*/false);
+ });
if (Res.isInvalid())
return ExprError();
Res = ConvertParamDefaultArgument(Param, Res.get(),
@@ -6117,10 +6122,11 @@
NestedDefaultChecking;
EnsureImmediateInvocationInDefaultArgs Immediate(*this);
-
- ExprResult Res =
- Immediate.TransformInitializer(Field->getInClassInitializer(),
- /*CXXDirectInit=*/false);
+ ExprResult Res;
+ runWithSufficientStackSpace(Loc, [&] {
+ Res = Immediate.TransformInitializer(Field->getInClassInitializer(),
+ /*CXXDirectInit=*/false);
+ });
if (!Res.isInvalid())
Res = ConvertMemberDefaultInitExpression(Field, Res.get(), Loc);
if (Res.isInvalid()) {
@@ -6133,7 +6139,9 @@
if (Field->getInClassInitializer()) {
Expr *E = Init ? Init : Field->getInClassInitializer();
if (!NestedDefaultChecking)
- MarkDeclarationsReferencedInExpr(E, /*SkipLocalVariables=*/false);
+ runWithSufficientStackSpace(Loc, [&] {
+ MarkDeclarationsReferencedInExpr(E, /*SkipLocalVariables=*/false);
+ });
// C++11 [class.base.init]p7:
// The initialization of each base and member constitutes a
// full-expression.
@@ -18545,7 +18553,9 @@
if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(Func)) {
for (CXXCtorInitializer *Init : Constructor->inits()) {
if (Init->isInClassMemberInitializer())
- MarkDeclarationsReferencedInExpr(Init->getInit());
+ runWithSufficientStackSpace(Init->getSourceLocation(), [&]() {
+ MarkDeclarationsReferencedInExpr(Init->getInit());
+ });
}
}
Index: clang/docs/ReleaseNotes.rst
===================================================================
--- clang/docs/ReleaseNotes.rst
+++ clang/docs/ReleaseNotes.rst
@@ -313,8 +313,8 @@
not a type concept.
- Fix crash when a doc comment contains a line splicing.
(`#62054 <https://github.com/llvm/llvm-project/issues/62054>`_)
-- Work around with a clang coverage crash which happens when visiting
- expressions/statements with invalid source locations in non-assert builds.
+- Work around with a clang coverage crash which happens when visiting
+ expressions/statements with invalid source locations in non-assert builds.
Assert builds may still see assertions triggered from this.
- Fix a failed assertion due to an invalid source location when trying to form
a coverage report for an unresolved constructor expression.
@@ -338,6 +338,8 @@
- Fix crash when attempting to perform parenthesized initialization of an
aggregate with a base class with only non-public constructors.
(`#62296 <https://github.com/llvm/llvm-project/issues/62296>`_)
+- Fix a stack overflow issue when evaluating ``consteval`` default arguments.
+ (`#60082` <https://github.com/llvm/llvm-project/issues/60082>`_)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits