6.7.7.50 Trivial-auto-var-init Option

The -ftrivial-auto-var-init=choice option instructs the compiler to initialize automatic variables that have not been explicitly initialized in the source code with either a pattern or with zeroes. Doing so can increase the security and predictability of a program by preventing uninitialized memory disclosure and use. Even with this feature in effect, automatic variables that do not have an explicit initializer are treated as uninitialized. The -Wuninitialized and -Wanalyzer-use-of-uninitialized-value options will still report warning messages against such automatic variables and the compiler will perform optimization as if the variable were uninitialized. This feature also initializes padding of automatic structure or union objects to zero. However, automatic variables that are declared between the controlling expression and the first case of a switch statement are not initialized. Use the -Wtrivial-auto-var-init option to report all such cases.

The three values of choice are:
uninitialized
Do not initialize any automatic variables. This choice results in the fastest execution of the program.
pattern
Initialize automatic variables with the value 0xFE. This value is chosen so that logic bugs in the program will more likely result in obvious program crashes, it is easily recognized in crash dumps, and is not a value that programmers rely on for useful program semantics. Note, however, that the value or values used for pattern initialization might changed in future implementations.
zero
Initialize automatic variables with zeroes.

If this option is not specified, the default action is to not initialize automatic variables, as if the uninitialized choice had been selected.

You can control this behavior for a specific variable by using the uninitialized variable attribute (see Specifying Attributes of Variables).