<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/79112>79112</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang-format] Inconsistent indentation when mixing preprocessor directives and code
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-format
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Grzzlwmpf
      </td>
    </tr>
</table>

<pre>
    When using `IndentPPDirectives` with anything other than `None`, `clang-format` produces inconsistent output. As an example, the snippet
```c
int foo()
{
  #ifdef foo1
    #ifdef foo2
      #ifdef foo 3
 bar1();
      #endif
      bar2();
    #endif
    bar3();
 #else
    bar4();
  #endif
}
```
is formatted as 
```c
int foo()
{
#ifdef foo1
  #ifdef foo2
    #ifdef foo 3
  bar1(); //line was outdented
    #endif
  bar2(); //line was outdented
  #endif
  bar3();
#else
 bar4();
#endif
}
```
when using `IndentPPDirectives: BeforeHash` (the output of `AfterHash` is analogous).

It seems that the indentation of PP directives is computed completely independently from other code, which somewhat defeats the purpose of indenting them in the first place.
I'd expect using PP indentation would either "sync" the indent levels of PP directives and code (so control statemenmts in PP directives would indent the follwing code block and vice versa) or at least not "unformat" manual indentation.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVU1v4zYQ_TX0ZRCDovx50CGpkTaXwreeKWpksaVIgTOy4_31BWmlGzlebBcwbIl8783MI2esiezJI1Zi_SLWh4UeuQux-j1---Yu_dAu6tBcq7869DCS9ScQG_nmG_R8PB5sRMP2jCQ2Ei6WO9D-yl2CBe4wAnfaJ8afwaPYSKF-S2_GaX96akPsNSfmEEMzGiSw3gRPlhg9Qxh5GHkJzwTaA77rfnCYFLhDIG-HAVnIg5DPSTl_zO3deoY2BKF2Qu0nyPbl9gAgVGnbBtsEKT4W58vq-_J8A8ppp9axmPTLlzs0-sa2n9dqHdUD8FdorWN5D0woRzgDrb6ozbXE9nDnzGQMwc11xgY0wa_b99C8H1j30Li5cyDUq1CvznqEi6Z05ulqYfNjl2Zm_pT_gH3v8NzgB-7-P28vP2uR8hlesA0R_9DUpWsv1C5d5ds9h9Am3nPLGD8ANt187cIpjCTUfjnFzd9vDITYU2oxzi1hc0jNNvgkdjxC81_wJGVCP4zp4NODQ0Z3zZwBM9FdoY2hnxrXhCb32qWzpgMKPV5SnAZb1Ew53jDGIRCmWLfQqXTusAfrM6C1kRgGpw1Oqb8JtW0A3wc0PHl1PM4Sv4TRNYA2JyGUoqs3QqlPBYLDMzr6WqL2TU47-UoBTPAcgwNizdij7znNlzvOLdwknHMOzl1SXlmpdsH8k4XP1iCcMZIWag8hgk6JaGLwgVOio5_mmVLQaz9q97mu5aKpymZf7vUCq2IrN1Kuip1cdJXGssB6tym3Zm_2Ba7XrdRabneojFmvi4WtlFQrWaiykLKUclnXu1Wrtdbb1R6x3oiVxF5bt3Tu3C9DPC0s0YjVdl8UauF0jY7ydFdqNniVSvM-Von2VI8nEivpLDF9F2LLLv8zzIjrA7x9HtSz80td0Nv3ZOEQcYjBIFGIjw5qMUZXdcxD6o1bI58sd2O9NKFPXe3OHz9PQwx_o2GhXnNxJNRrru_fAAAA__-t4hO8">