Page MenuHomePhabricator

[clang][AVR] Redefine some types to be compatible with avr-gcc
ClosedPublic

Authored by benshi001 on Apr 17 2021, 4:16 AM.

Diff Detail

Event Timeline

benshi001 created this revision.Apr 17 2021, 4:16 AM
benshi001 requested review of this revision.Apr 17 2021, 4:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 17 2021, 4:16 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
benshi001 added a comment.EditedApr 17 2021, 5:01 AM

Some key points,

  1. This patch fixes the bug https://bugs.llvm.org/show_bug.cgi?id=31530 .
  1. The test builtins.cpp failed on AVR and is disabled, due to uint16_t is defined to unsigned short. The underlying reason is that the system's libc/stdint.h is used instead of avr-libc's stdint.h.

In avr-libc's stdint, the correct definition is

typedef signed int int8_t attribute((mode(QI)));
typedef unsigned int uint8_t attribute((mode(QI)));
typedef signed int int16_t attribute ((mode (HI)));
typedef unsigned int uint16_t attribute ((mode (HI)));
typedef signed int int32_t attribute ((mode (SI)));
typedef unsigned int uint32_t attribute ((mode (SI)));

typedef signed int int64_t attribute((mode(DI)));
typedef unsigned int uint64_t attribute((mode(DI)));

Though the disabled test builtins.cpp can pass after my another patch https://reviews.llvm.org/D97669, it will still fail on llvm build machines, since there are no avr-libc installed on them.

dylanmckay accepted this revision.May 12 2021, 4:56 AM
This revision is now accepted and ready to land.May 12 2021, 4:56 AM
efriedma added inline comments.
clang/lib/Basic/Targets/AVR.cpp
313

Redefining __INT16_TYPE__ like this is unusual. The macro is normally defined in InitPreprocessor.cpp; if the logic there is wrong, I'd prefer to fix it there.

For specific types int16_t and uint16_t, I'm not sure if anything inside the compiler actually uses them at the moment, but I'd prefer to encode the type in the TargetInfo, along the lines of getInt64Type(), in case we need these types elsewhere in the future.

benshi001 added inline comments.May 13 2021, 7:14 PM
clang/lib/Basic/Targets/AVR.cpp
313

Making changes to InitPreprocessor.cpp will affect all targets, and I not familar with other targets. Actually AVR is so special that it defines __INT16_TYPE__ to int.

efriedma added inline comments.May 14 2021, 11:07 AM
clang/lib/Basic/Targets/AVR.cpp
313

Making changes to InitPreprocessor.cpp will affect all targets, and I not familar with other targets.

That shouldn't be a problem as long as you have an appropriate reviewer; I volunteer. :)

You should be able to use getInt64Type() as a model for the necessary changes.

benshi001 marked an inline comment as done.May 14 2021, 11:29 PM
benshi001 added inline comments.
clang/lib/Basic/Targets/AVR.cpp
313

Thanks for your suggestion. I have submitted a patch,

https://reviews.llvm.org/D102547, and you are appreciated to review it. ^_^