<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/56157>56157</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[AVR] missing built-in defines
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
maribu
</td>
</tr>
</table>
<pre>
avr-gcc [provides a number of built-in defines](https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/AVR-Options.html) that is useful to implement context switching code for AVR, most notably `__AVR_3_BYTE_PC__`, `__AVR_2_BYTE_PC__`, `__AVR_HAVE_RAMPD__`, `__AVR_HAVE_RAMPX__`, `__AVR_HAVE_RAMPY__`, `__AVR_HAVE_RAMPZ__`. There are also other built-in defines that are useful to provide optimized inline assembly, such as `__AVR_HAVE_MOVW__`, `__AVR_HAVE_MUL__`, etc.
These are currently not provided with clang:
``` C
#if __AVR_3_BYTE_PC__
#warning "3 byte program counter"
#endif
#if __AVR_2_BYTE_PC__
#warning "2 byte program counter"
#endif
#if __AVR_HAVE_RAMPX__
#warning "Has RAMPX register"
#endif
#if __AVR_HAVE_RAMPY__
#warning "Has RAMPY register"
#endif
#if __AVR_HAVE_RAMPZ__
#warning "Has RAMPZ register"
#endif
#if __AVR_HAVE_RAMPD__
#warning "Has RAMPD register"
#endif
typedef int dont_be_pedantdic;
```
```
$ avr-gcc -mmcu=atmega328p -c test.c
test.c:6:2: warning: #warning "2 byte program counter" [-Wcpp]
6 | #warning "2 byte program counter"
| ^~~~~~~
$ clang --target=avr -mmcu=atmega328p -c test.c
$ avr-gcc -mmcu=atmega2560 -c test.c
test.c:2:2: warning: #warning "3 byte program counter" [-Wcpp]
2 | #warning "3 byte program counter"
| ^~~~~~~
test.c:18:2: warning: #warning "Has RAMPZ register" [-Wcpp]
18 | #warning "Has RAMPZ register"
| ^~~~~~~
$ clang --target=avr -mmcu=atmega2560 -c test.c
$ avr-gcc -mmcu=atxmega128a1 -c test.c
test.c:2:2: warning: #warning "3 byte program counter" [-Wcpp]
2 | #warning "3 byte program counter"
| ^~~~~~~
test.c:10:2: warning: #warning "Has RAMPX register" [-Wcpp]
10 | #warning "Has RAMPX register"
| ^~~~~~~
test.c:14:2: warning: #warning "Has RAMPY register" [-Wcpp]
14 | #warning "Has RAMPY register"
| ^~~~~~~
test.c:18:2: warning: #warning "Has RAMPZ register" [-Wcpp]
18 | #warning "Has RAMPZ register"
| ^~~~~~~
test.c:22:2: warning: #warning "Has RAMPD register" [-Wcpp]
22 | #warning "Has RAMPD register"
| ^~~~~~~
$ clang --target=avr -mmcu=atxmega128a1 -c test.c
```
It would be extremely convenient if those would also be provided by clang.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzdV1GPmzgQ_jXkZQQCEwh5yEN2s1VPulWrqrdt9gUZY8AnwJFtss39-huTTdLuEpJ2-9QICPaYz5-_mcFDJvPdgm6VWzIGTnSzUXIrcq6BQts1GVcgC8g6URtXtJDzQrRcO9HKIUllzEY74dIh7_DA572y7TypSmzJtsaBuWR6b3ID3yOev2_gdfnwyf2wMUK22qtMUztkDqaiBoSGTvOiq8FIEM2m5g1vDTDZGv7NgH4ShlWiLbEn51BIBQjlkFtopDbQSkOzegdO7KcpGtIwvVl_vks_3qYp9tlxRxM5b3q_fLhLPy3vP65GbF9HbOsR22Nv8-BzxRUHas9aS5AG26-U3otiB51UeXYRSNSvEf_xHESvNlCteYPLt_PqjlXY8WL--w8PX85Qu__n76OFG-Y5_srxl_srUtV7qqxTCv2BEqPUByY5oFcqYDVtSxsP3z1pAfsDbp87SCgKeO2cg_GJqta61yEkhGxnuJ2kVLRBh3cYAwoNx8G8zUXxw3TfoZNxdPI29B_CYAD-PWrfm0HxUuhfgl6PQ6_fAP04Dv34BujVOPTqOmiz23DMAQxtAzkmf5rxFHtoa3LBnPDmRXgNxtwBfQqHF5zbNKxzwhU1DS9pSJINuAwM18Zjz_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