llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[AVR] missing built-in defines

Open maribu opened this issue 2 years ago • 2 comments

avr-gcc provides a number of built-in defines 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:

#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.

maribu avatar Jun 22 '22 08:06 maribu

@llvm/issue-subscribers-clang-driver

llvmbot avatar Jun 22 '22 15:06 llvmbot

Currently we use hand writting arrays to record features for different devices.

https://github.com/llvm/llvm-project/blob/main/clang/lib/Basic/Targets/AVR.cpp#L32 https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/AVR.cpp#L38

We should change to a unique TD file, generate an .inc file, and include it in the above two .cpp files.

benshi001 avatar Aug 15 '22 09:08 benshi001