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

    <tr>
        <th>Summary</th>
        <td>
            clang-format: Macro operator spacing not working as expected
        </td>
    </tr>

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

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

    <tr>
      <th>Reporter</th>
      <td>
          HarryYin-code
      </td>
    </tr>
</table>

<pre>
    
Description:
When formatting macro definitions, clang-format doesn't add spaces around operators as expected, particularly in complex macro expressions.

Current Behavior:
Given the following macro definition:
```c
#define __RV_ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b))
```

After running clang-format, the output remains unchanged:
```c
#define __RV_ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b))
```

Expected Behavior:
The macro should be formatted with spaces around operators:
```c
#define __RV_ROUNDUP(a, b) ((((a) - 1) / (b) + 1) * (b))
```

Current clang-format configuration:
```yaml
SpaceBeforeParens: ControlStatements
SpaceBeforeBinaryOperators: All
SpaceBeforeAssignmentOperators: true
AlignOperands: true
AlignConsecutiveAssignments: true
```

Environment:
- OS: Ubuntu 20.04.6 LTS
- clang-format version: Ubuntu clang-format version 14.0.6
- Shell: /bin/bash

Minimal Reproduction:
1. Create a test file `test.h`:
```c
#ifndef TEST_H
#define TEST_H

#define TEST_MACRO(a, b) ((((a)-1) / (b) + 1) * (b))

#endif /* TEST_H */
```

2. Run clang-format:
```bash
clang-format -i test.h
```

3. The output remains unchanged, without spaces around operators.

Additional Notes:
- This issue affects all binary operators in macro definitions, not just subtraction
- The issue is particularly noticeable in complex macro expressions with multiple operators
- The current configuration works correctly for non-macro code
- This is a common use case in system programming and embedded development

Steps to Reproduce:
1. Create a new file with the test macro
2. Apply the provided .clang-format configuration
3. Run clang-format
4. Observe that the operators in the macro definition remain without spaces

Impact:
This issue affects code readability, especially in complex macro definitions commonly used in system programming and embedded development. The lack of consistent spacing around operators in macros makes the code harder to read and maintain.

Possible Workarounds:
1. Manual formatting of macro definitions
2. Using alternative formatting tools like astyle
3. Restructuring macros to use do-while(0) blocks

Would you like me to provide any additional information or clarification?
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVl1v2zoS_TXyy8CCLCtfD35w0ma7wKYp4mSLfQpG5MhiQ5ECOXTqf78gJSd27Ba4FwUuICQwORzOnDlzhui9WhuiRXZ2nZ19mmDg1rrFF3Ru-z9lpsJKmtRWbhdZsfxEXjjVs7Immy-zYvm9JQONdR0yK7OGDoWzIKlRRkUrn5U3IDSa9XSwAmnJm6y8YEApwfcoyAM6G4wE25NDts4DeqCfPQkmGT306FiJoNHpLSgDwna9pp_jdfSzd-R9vC7PihjWTXCODMM1tbhR1g3B_kttyAC3BI3V2r6eCniwzM6L4RPxRzlP-wTPzw__fX64f_r66elbVl5iDK3OyivIysu3D7PyajobVm_jzmhxDePicrcYv727htCXDZMDF4yJ4e1DF2-LwdvAfWBw1KEyHoIRLZo1yX889M9jxT7A_tjSCLNvbdASatpRhiS8Km5_RYM_kxFM4e_ntGPSAYeFNY1aB4cnGLPFTmfFchUzuqbGOvqGjkzMBW6sYWf1ipGpI8P-0PBaGXTb-73sYak_OFumdo2HD-zYBYrk0Wpt0oaRR-s31ngSgdVmz8u-1cdymo1yNlkNOU7hfhXNn-pgOEBZ5EWVn8N_Hldp8wCiDTk_gLMzP7UNsyov8vN0fNWS1tE-K29rZeJf9O0Qyp0yqkMND9Q7K4N4x32Ww40jZAIEJs_QKE2QnRfxR97GZE6SSDVGUgOPn1ePz18OePW-dLR6t7x5uP9z3ZP8k5GqiSfi_nB3NI0LRxUpc3gI5lAUDrMbITvAeqpgBOPI4TyHx98pSnmT-tMG_lWLjoK7lDLJJ2r4apn8jjCPrfKgvA8E2DQk2ANqDXVi-p7eK3N6dBjL8CN4Bh9qdjgUfnBMo1_lD8eDsawEYa3pt5NiEJ4uaFa9pj3N2XkXu87fb3Z4te7F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