Page MenuHomePhabricator

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

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

Diff Detail

Unit TestsFailed

TimeTest
120 msx64 debian > LLVM.tools/llvm-objdump::section-filter.test
Script: -- : 'RUN: at line 4'; /mnt/disks/ssd0/agent/llvm-project/build/bin/yaml2obj /mnt/disks/ssd0/agent/llvm-project/llvm/test/tools/llvm-objdump/section-filter.test --docnum=1 -o /mnt/disks/ssd0/agent/llvm-project/build/test/tools/llvm-objdump/Output/section-filter.test.tmp.h.elf
540 msx64 windows > LLVM.tools/llvm-objdump::section-filter.test
Script: -- : 'RUN: at line 4'; c:\ws\w16n2-1\llvm-project\premerge-checks\build\bin\yaml2obj.exe C:\ws\w16n2-1\llvm-project\premerge-checks\llvm\test\tools\llvm-objdump\section-filter.test --docnum=1 -o C:\ws\w16n2-1\llvm-project\premerge-checks\build\test\tools\llvm-objdump\Output\section-filter.test.tmp.h.elf

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.Tue, Apr 6, 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.Tue, Apr 6, 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.Wed, Apr 7, 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.Wed, Apr 7, 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.Wed, Apr 7, 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.Wed, Apr 14, 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.Wed, Apr 14, 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.