Rate This Document
Findability
Accuracy
Completeness
Readability

Stack Exhaustion Caused by Compiling Complex Expressions

In the following example, 10,000 variables are continuously added in the expression:

Sum += g0 + g1 + g2 + ... + g9998 + g9999 //Adding 10,000 variables continuously

When the default stack size of the host system is limited, a segmentation fault error may occur. This is because the stack size used by the Clang process exceeds the system limit during compilation of this complex expression.

At a high optimization level, some loops are expanded, resulting in complex expressions.

Workaround

Run the ulimit -s command to set the stack space size to a larger value. For example, run the ulimit -s 20000 command to set the upper limit of the stack size to 20000 KB, or run the ulimit -s unlimited command to set the stack size to unlimited.

You can run the ulimit -a command to view the default stack size limit of the system.

Figure 1 System information