This is an archive of the discontinued LLVM Phabricator instance.

[clang][AVR] Add avr-libc/include to clang system include paths
ClosedPublic

Authored by benshi001 on Mar 1 2021, 1:54 AM.

Diff Detail

Event Timeline

benshi001 created this revision.Mar 1 2021, 1:54 AM
benshi001 requested review of this revision.Mar 1 2021, 1:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2021, 1:54 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
benshi001 added a comment.EditedMar 1 2021, 1:57 AM

The wrong stdio.h (/usr/include/stdio.h) is included with a simple a.c like

#include <stdio.h>
...

However the expected one is avr-libc's stdio.h (/usr/lib/avr/include), and this patch add avr-libc's include/ to clang system include paths.

aykevl added a comment.Mar 1 2021, 4:46 PM

Looks reasonable to me. But again, I would like this to be reviewed also by someone familiar with the internals of Clang (I'm not).

benshi001 added a comment.EditedMar 1 2021, 5:47 PM

Looks reasonable to me. But again, I would like this to be reviewed also by someone familiar with the internals of Clang (I'm not).

Actually this patch is copied from msp430, with just a little change.

Although the bug can be avoided via "-I /usr/lib/avr/include" in clang's command line option, I expect clang to have the save behaviour as avr-gcc.

And for avr-gcc, avr-gcc a.c -mmcu=xxx will automatically include avr-libc's header files and link avr-libc's libxxxx.a .

Is stdio.h used by anything?

clang/lib/Driver/ToolChains/AVR.cpp
356

function name doesn't adhere to the coding style.

benshi001 marked an inline comment as done.Apr 1 2021, 8:43 PM
benshi001 added inline comments.
clang/lib/Driver/ToolChains/AVR.cpp
356

Not sure your concern ? Other platforms also use the same function name.

void RISCVToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
                                               ArgStringList &CC1Args) const {
void Linux::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
                                      ArgStringList &CC1Args) const {
void WebAssembly::AddClangSystemIncludeArgs(const ArgList &DriverArgs,
                                            ArgStringList &CC1Args) const {
benshi001 marked an inline comment as done.Apr 1 2021, 11:12 PM

Is stdio.h used by anything?

No. stdio.h is not used. But if I do #include <avr/interrupt.h>, then -I /usr/lib/avr/include must be specified in the command line option. While avr-gcc does not reqiures that.

I would like to keep clang & avr-gcc in the behaviour.

Anastasia added inline comments.Apr 6 2021, 11:04 AM
clang/lib/Driver/ToolChains/AVR.cpp
356

https://llvm.org/docs/CodingStandards.html#name-types-functions-variables-and-enumerators-properly

Function names should be verb phrases (as they represent actions), and command-like function should be imperative. The name should be camel case, and start with a lower case letter (e.g. openFile() or isFoo()).

You should adhere to the coding style in the new functionality.

benshi001 added inline comments.Apr 6 2021, 11:48 PM
clang/lib/Driver/ToolChains/AVR.cpp
356

I have created another patch for that, and would like to keep current patch simple without noise.

https://reviews.llvm.org/D100022

Anastasia added inline comments.Apr 7 2021, 3:21 AM
clang/lib/Driver/ToolChains/AVR.cpp
356

Sorry, my mistake - I haven't realized that you are overriding the method instead of adding a new one. Then I think it is best to keep the old style because we don't normally do purely formatting/renaming changes.

benshi001 marked 2 inline comments as done.Apr 7 2021, 3:44 AM
benshi001 added inline comments.
clang/lib/Driver/ToolChains/AVR.cpp
356

Thanks. You are appreciated to go on with this patch.

benshi001 marked an inline comment as done.Apr 7 2021, 3:44 AM

Is stdio.h used by anything?

No. stdio.h is not used. But if I do #include <avr/interrupt.h>, then -I /usr/lib/avr/include must be specified in the command line option. While avr-gcc does not reqiures that.

I would like to keep clang & avr-gcc in the behaviour.

Ok, do you plan to use it later? Then perhaps you should be adding it in the subsequent patches?

Is stdio.h used by anything?

No. stdio.h is not used. But if I do #include <avr/interrupt.h>, then -I /usr/lib/avr/include must be specified in the command line option. While avr-gcc does not reqiures that.

I would like to keep clang & avr-gcc in the behaviour.

Ok, do you plan to use it later? Then perhaps you should be adding it in the subsequent patches?

No. No future pathes are needed. The avr-libc includes standard libc (headers and libs) and avr specific headers and libs. This patch fixes all of these issues. Both standard libc and avr platform specific libs can be used without any explict command line option, just like avr-gcc does.

Is stdio.h used by anything?

No. stdio.h is not used. But if I do #include <avr/interrupt.h>, then -I /usr/lib/avr/include must be specified in the command line option. While avr-gcc does not reqiures that.

I would like to keep clang & avr-gcc in the behaviour.

Ok, do you plan to use it later? Then perhaps you should be adding it in the subsequent patches?

No. No future pathes are needed. The avr-libc includes standard libc (headers and libs) and avr specific headers and libs. This patch fixes all of these issues. Both standard libc and avr platform specific libs can be used without any explict command line option, just like avr-gcc does.

Ok, so your patch is adding the following file

clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/include/stdio.h

But it doesn't seem to be used at present? If you don't need it anywhere it should not be added.

Is stdio.h used by anything?

No. stdio.h is not used. But if I do #include <avr/interrupt.h>, then -I /usr/lib/avr/include must be specified in the command line option. While avr-gcc does not reqiures that.

I would like to keep clang & avr-gcc in the behaviour.

Ok, do you plan to use it later? Then perhaps you should be adding it in the subsequent patches?

No. No future pathes are needed. The avr-libc includes standard libc (headers and libs) and avr specific headers and libs. This patch fixes all of these issues. Both standard libc and avr platform specific libs can be used without any explict command line option, just like avr-gcc does.

Ok, so your patch is adding the following file

clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/include/stdio.h

But it doesn't seem to be used at present? If you don't need it anywhere it should not be added.

No. The stdio.h is still needed even it is not referred by any code in current patch. It works as a placeholder for the directory clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/include/, and this directory is needed in the test case clang/test/Driver/avr-toolchain.c of current patch, and this directory can not exist without stdio.h.

Anastasia resigned from this revision.Apr 14 2021, 6:17 AM

Is stdio.h used by anything?

No. stdio.h is not used. But if I do #include <avr/interrupt.h>, then -I /usr/lib/avr/include must be specified in the command line option. While avr-gcc does not reqiures that.

I would like to keep clang & avr-gcc in the behaviour.

Ok, do you plan to use it later? Then perhaps you should be adding it in the subsequent patches?

No. No future pathes are needed. The avr-libc includes standard libc (headers and libs) and avr specific headers and libs. This patch fixes all of these issues. Both standard libc and avr platform specific libs can be used without any explict command line option, just like avr-gcc does.

Ok, so your patch is adding the following file

clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/include/stdio.h

But it doesn't seem to be used at present? If you don't need it anywhere it should not be added.

No. The stdio.h is still needed even it is not referred by any code in current patch. It works as a placeholder for the directory clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/include/, and this directory is needed in the test case clang/test/Driver/avr-toolchain.c of current patch, and this directory can not exist without stdio.h.

Do you know why an empty directory is not sufficient?

Overall perhaps it makes more sense if someone with more experience on AVR reviews this change.

Anastasia added a subscriber: Anastasia.
benshi001 updated this revision to Diff 337591.Apr 14 2021, 5:57 PM

Is stdio.h used by anything?

No. stdio.h is not used. But if I do #include <avr/interrupt.h>, then -I /usr/lib/avr/include must be specified in the command line option. While avr-gcc does not reqiures that.

I would like to keep clang & avr-gcc in the behaviour.

Ok, do you plan to use it later? Then perhaps you should be adding it in the subsequent patches?

No. No future pathes are needed. The avr-libc includes standard libc (headers and libs) and avr specific headers and libs. This patch fixes all of these issues. Both standard libc and avr platform specific libs can be used without any explict command line option, just like avr-gcc does.

Ok, so your patch is adding the following file

clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/include/stdio.h

But it doesn't seem to be used at present? If you don't need it anywhere it should not be added.

No. The stdio.h is still needed even it is not referred by any code in current patch. It works as a placeholder for the directory clang/test/Driver/Inputs/basic_avr_tree/usr/lib/avr/include/, and this directory is needed in the test case clang/test/Driver/avr-toolchain.c of current patch, and this directory can not exist without stdio.h.

Do you know why an empty directory is not sufficient?

Overall perhaps it makes more sense if someone with more experience on AVR reviews this change.

I just learnt that llvm repo uses an empty .keep file to keep an empty directory, so I replaced the stdio.h with a .keep. Thanks for your comments.

benshi001 added a reviewer: efriedma.EditedMay 17 2021, 7:30 PM
benshi001 added a subscriber: efriedma.

@efriedma

Could you please help me review this patch? It relates to the one you have reviewed for me, and is also about wrong mangled function name in c++ on AVR.

The previous patch has correctly handled __UINT8/16/32/64_TYPE__, but current clang-avr still be wrong at int8/16/32/64_t, the underlying cause is the system's stdint.h is used first, which it should be avr-libc's stdint.h going first. (avr-g++ does so)

The patch fixes that issue, which add avr-libc to clang-avr toolchain's include path.

Thanks for your help!!

dylanmckay accepted this revision.May 30 2021, 2:50 AM

Looks good, nice and simple. Thanks @benshi001

This revision is now accepted and ready to land.May 30 2021, 2:50 AM
This revision was landed with ongoing or failed builds.May 30 2021, 7:39 AM
This revision was automatically updated to reflect the committed changes.