[clang] [clang] Fix segmentation fault caused by stack overflow on deeply nested expressions (PR #111701)
Ilya Biryukov via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 10 07:18:12 PDT 2024
================
@@ -0,0 +1,1013 @@
+// RUN: %clang_cc1 %s -emit-llvm -o - -Wstack-exhausted -verify
+
+class AClass {
+public:
+ AClass() {}
+ AClass &foo() { return *this; }
+};
+
+void test_bar() {
+ AClass a;
+ // expected-warning@* {{stack nearly exhausted; compilation time may suffer, and crashes due to stack overflow are likely}}
+ a.foo().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo().foo()
----------------
ilya-biryukov wrote:
Could we use preprocessor to reduce the size of the file?
The typical trick I use is:
```cpp
#define CALLS1 .foo().foo().foo().foo().foo().foo().foo().foo().foo().foo()
#define CALLS2 CALLS1().CALLS1().CALLS1().CALLS1(). ...
...
#define CALLS${N} CALLS${N-1}....
a.CALLS();
```
https://github.com/llvm/llvm-project/pull/111701
More information about the cfe-commits
mailing list