[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-06-03 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov closed https://github.com/llvm/llvm-project/pull/79875 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-06-03 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov updated https://github.com/llvm/llvm-project/pull/79875 >From db8b091568c924a9550052ea643f718ac11d3e73 Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Mon, 29 Jan 2024 18:55:53 +0100 Subject: [PATCH 1/4] [Serialization] Check for stack exhaustion when

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-06-03 Thread Ilya Biryukov via cfe-commits
ilya-biryukov wrote: I have tried `ulimit` and found that Clang relies on a very intricate balance between the stack size, the desired stack size (the cutoff at which we create a new thread with a larger stack) and the points in code where we call `runWithSufficientStackSpace`. If the stack

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-06-03 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov updated https://github.com/llvm/llvm-project/pull/79875 >From 6e474e393e63fd1cb5f3b0bea3c971b96591c57f Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Mon, 29 Jan 2024 18:55:53 +0100 Subject: [PATCH 1/4] [Serialization] Check for stack exhaustion when

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-06-03 Thread Ilya Biryukov via cfe-commits
@@ -9403,6 +9404,20 @@ DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) const { return Diags.Report(Loc, DiagID); } +void ASTReader::warnStackExhausted(SourceLocation Loc) { + // When Sema is available, avoid duplicate errors. This should be rare.

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-29 Thread Chuanqi Xu via cfe-commits
https://github.com/ChuanqiXu9 edited https://github.com/llvm/llvm-project/pull/79875 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-29 Thread Chuanqi Xu via cfe-commits
https://github.com/ChuanqiXu9 approved this pull request. If we don't insist on testing this in this commit, them LGTM. https://github.com/llvm/llvm-project/pull/79875 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-29 Thread Chuanqi Xu via cfe-commits
@@ -9403,6 +9404,20 @@ DiagnosticBuilder ASTReader::Diag(SourceLocation Loc, unsigned DiagID) const { return Diags.Report(Loc, DiagID); } +void ASTReader::warnStackExhausted(SourceLocation Loc) { + // When Sema is available, avoid duplicate errors. This should be rare.

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-29 Thread Ilya Biryukov via cfe-commits
ilya-biryukov wrote: > there's a couple of tests that use `ulimit` > (`clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp` and > `clang/test/PCH/leakfiles.test`) - so that technique could be used to test > this in a way that's fast enough to check in? oh, I didn't realize I can

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-29 Thread David Blaikie via cfe-commits
dwblaikie wrote: (a bunch of compiler-rt tests also use ulimit, but doesn't look like any llvm core tests do... ) https://github.com/llvm/llvm-project/pull/79875 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-29 Thread David Blaikie via cfe-commits
dwblaikie wrote: there's a couple of tests that use `ulimit` (`clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp` and `clang/test/PCH/leakfiles.test`) - so that technique could be used to test this in a way that's fast enough to check in?

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-29 Thread Ilya Biryukov via cfe-commits
ilya-biryukov wrote: > Yeah, I was hoping to have it in the text of the discussion here without > having to do it myself since you've already got the repro locally, > presumably... so we can all see/discuss it. But perhaps it's not sufficiently > helpful/constructive to worry about - not

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-29 Thread Ilya Biryukov via cfe-commits
@@ -4099,7 +4099,9 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { // calls to Decl::getASTContext() by Decl's methods will find the // TranslationUnitDecl without crashing. D->setDeclContext(Context.getTranslationUnitDecl()); - Reader.Visit(D); + + // Reading some

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-29 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov updated https://github.com/llvm/llvm-project/pull/79875 >From 6e474e393e63fd1cb5f3b0bea3c971b96591c57f Mon Sep 17 00:00:00 2001 From: Ilya Biryukov Date: Mon, 29 Jan 2024 18:55:53 +0100 Subject: [PATCH 1/3] [Serialization] Check for stack exhaustion when

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-28 Thread via cfe-commits
cor3ntin wrote: @ilya-biryukov ping! https://github.com/llvm/llvm-project/pull/79875 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-08 Thread Aaron Ballman via cfe-commits
AaronBallman wrote: > I think we should apply @ChuanqiXu9 suggestion and merge that without tests. > At worse it's harmless, at best it solves an actual issue for users. We have > precedent for not being able to test resource exhaustion fixes. I would not be opposed to landing with a test,

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-08 Thread Ilya Biryukov via cfe-commits
ilya-biryukov wrote: Sorry for loosing track of this change. I will go through the comments and try to land this some time next week. https://github.com/llvm/llvm-project/pull/79875 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-05-03 Thread via cfe-commits
cor3ntin wrote: I think we should apply @ChuanqiXu9 suggestion and merge that without tests. At worse it's harmless, at best it solves an actual issue for users. We have precedent for not being able to test resource exhaustion fixes. https://github.com/llvm/llvm-project/pull/79875

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-30 Thread David Blaikie via cfe-commits
dwblaikie wrote: > > Could you show the stack (omitting/annotating the repeated part) that leads > > to failure? and/or the AST shape that leads to failure? > > See the test I added. All you need is ~10k overloads of a method in a class > and a `using Base::func` in the derived class. The AST

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-30 Thread Chuanqi Xu via cfe-commits
ChuanqiXu9 wrote: > with stack exhaustion warning, the compiler can continue (albeit being slow > or unstable). The depth limit here will be a hard restriction and so there > will be no workaround if the code reaches it. It is a surprise to me that this is only a warning instead of a hard

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-30 Thread Chuanqi Xu via cfe-commits
ChuanqiXu9 wrote: > I am not saying it's a bad idea to add this for testing purposes, but given > how fragile this approach is, I think we should not provide configuration > knobs to users there. At least everyone sees crashes at roughly the same > points right now (although variation is

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-30 Thread Chuanqi Xu via cfe-commits
@@ -4099,7 +4099,9 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { // calls to Decl::getASTContext() by Decl's methods will find the // TranslationUnitDecl without crashing. D->setDeclContext(Context.getTranslationUnitDecl()); - Reader.Visit(D); + + // Reading some

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-30 Thread Ilya Biryukov via cfe-commits
ilya-biryukov wrote: > To make this testable, maybe we can refactor > `clang::runWithSufficientStackSpace` a little bit to make `DesiredStackSize` > and `isStackNearlyExhausted::SufficientStack` configurable. Maybe... As long as we only use this in tests. However, for this particular case, we

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-30 Thread Ilya Biryukov via cfe-commits
@@ -4099,7 +4099,9 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { // calls to Decl::getASTContext() by Decl's methods will find the // TranslationUnitDecl without crashing. D->setDeclContext(Context.getTranslationUnitDecl()); - Reader.Visit(D); + + // Reading some

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-30 Thread Ilya Biryukov via cfe-commits
ilya-biryukov wrote: > Could you show the stack (omitting/annotating the repeated part) that leads > to failure? and/or the AST shape that leads to failure? See the test I added. All you need is ~10k overloads of a method in a class and a `using Base::func` in the derived class.\ The AST

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-30 Thread Ilya Biryukov via cfe-commits
@@ -0,0 +1,43 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/usings.cppm -o %t/usings.pcm +// RUN: %clang_cc1 -std=c++20 -fmodule-file=usings=%t/usings.pcm %t/use.cpp -verify -fsyntax-only

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread Chuanqi Xu via cfe-commits
ChuanqiXu9 wrote: Another idea is to limit (or check) the threshold for `ASTReader::NumCurrentElementsDeserializing`. Then we still can print the stack trace by some utils in LLVM also we can get better performance than this. https://github.com/llvm/llvm-project/pull/79875

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread Chuanqi Xu via cfe-commits
@@ -0,0 +1,43 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/usings.cppm -o %t/usings.pcm +// RUN: %clang_cc1 -std=c++20 -fmodule-file=usings=%t/usings.pcm %t/use.cpp -verify -fsyntax-only

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread Chuanqi Xu via cfe-commits
https://github.com/ChuanqiXu9 commented: To make this testable, maybe we can refactor `clang::runWithSufficientStackSpace` a little bit to make `DesiredStackSize` and `isStackNearlyExhausted::SufficientStack` configurable. https://github.com/llvm/llvm-project/pull/79875

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread Chuanqi Xu via cfe-commits
@@ -4099,7 +4099,9 @@ Decl *ASTReader::ReadDeclRecord(DeclID ID) { // calls to Decl::getASTContext() by Decl's methods will find the // TranslationUnitDecl without crashing. D->setDeclContext(Context.getTranslationUnitDecl()); - Reader.Visit(D); + + // Reading some

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread Chuanqi Xu via cfe-commits
https://github.com/ChuanqiXu9 edited https://github.com/llvm/llvm-project/pull/79875 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread David Blaikie via cfe-commits
dwblaikie wrote: Could you show the stack (omitting/annotating the repeated part) that leads to failure? and/or the AST shape that leads to failure? https://github.com/llvm/llvm-project/pull/79875 ___ cfe-commits mailing list

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread via cfe-commits
https://github.com/cor3ntin approved this pull request. I think it makes sense to make this change without tests https://github.com/llvm/llvm-project/pull/79875 ___ cfe-commits mailing list cfe-commits@lists.llvm.org

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread Ilya Biryukov via cfe-commits
@@ -0,0 +1,43 @@ +// RUN: rm -rf %t +// RUN: mkdir -p %t +// RUN: split-file %s %t + +// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/usings.cppm -o %t/usings.pcm +// RUN: %clang_cc1 -std=c++20 -fmodule-file=usings=%t/usings.pcm %t/use.cpp -verify -fsyntax-only

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov commented: I think the alternative we could try to chase is turning the chain of using-shadow-decls into an array somehow, so we can process it in a loop instead of recursion. I am not sure if there is an an approach that does **not** involve structural

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov edited https://github.com/llvm/llvm-project/pull/79875 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread via cfe-commits
llvmbot wrote: @llvm/pr-subscribers-clang-modules @llvm/pr-subscribers-clang Author: Ilya Biryukov (ilya-biryukov) Changes Particular example that lead to this is a very long chain of `UsingShadowDecl`s that we hit in our codebase in generated code. To avoid that, check for stack

[clang] [Serialization] Check for stack exhaustion when reading declarations (PR #79875)

2024-01-29 Thread Ilya Biryukov via cfe-commits
https://github.com/ilya-biryukov created https://github.com/llvm/llvm-project/pull/79875 Particular example that lead to this is a very long chain of `UsingShadowDecl`s that we hit in our codebase in generated code. To avoid that, check for stack exhaustion when deserializing the declaration.