This is an archive of the discontinued LLVM Phabricator instance.

[AVR] Fix __AVR_xxx macro definitions
ClosedPublic

Authored by Lekensteyn on Feb 10 2017, 2:26 AM.

Details

Summary

The -mmcu option for GCC sets macros like AVR_ATmega328P (with the trailing
underscores), be sure to include these underscores for Clangs -mcpu option.

See "AVR Built-in Macros" in https://gcc.gnu.org/onlinedocs/gcc/AVR-Options.html

Diff Detail

Event Timeline

Lekensteyn created this revision.Feb 10 2017, 2:26 AM

Without this patch, compilation of a program using avr/io.h fails. Tested with:

clang --target=avr -Xclang -target-cpu -Xclang atmega328p -I/usr/avr/include -Os led.c -c -o /dev/null

Btw, it seems that avr-libc 2.0.0 also uses __AVR_ARCH__, __AVR_XMEGA__ and __AVR_3_BYTE_PC__ in some places, but these are not defined in Clang.

Lekensteyn retitled this revision from [AVR} Fix __AVR_xxx macro definitions to [AVR] Fix __AVR_xxx macro definitions.Feb 10 2017, 2:36 AM
dylanmckay edited edge metadata.Feb 10 2017, 4:47 AM

Nice catch, unsure why I didn't catch this earlier.

Do we also need to modify the other tests inside target-cpu-defines?

Lekensteyn updated this revision to Diff 87986.Feb 10 2017, 5:07 AM

Oops, missed the avrtiny patch. After updating that, it now actually passes the clang-test tests.

This revision is now accepted and ready to land.Feb 10 2017, 8:33 AM
efriedma added inline comments.
lib/Basic/Targets.cpp
8464–8702

Four underscores?

Lekensteyn marked an inline comment as done.

Good catch! I just checked again and confirmed that there is only one line that had this issue (there are no other occurrences of ___").

dylanmckay accepted this revision.Feb 10 2017, 1:57 PM

Do you have commit access @Lekensteyn?

Do you have commit access @Lekensteyn?

No I do not, please push it for me :-)

This revision was automatically updated to reflect the committed changes.

Done, thanks for the patch @Lekensteyn!

If you plan on submitting more patches, feel free to ask for commit access.