Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[libc][cmake] Tidy compiler includes #66783

Merged
merged 3 commits into from
Sep 19, 2023
Merged

Conversation

gchatelet
Copy link
Contributor

@gchatelet gchatelet commented Sep 19, 2023

We want to activate llvm-header-guard (#66477) but the current CMake configuration includes paths that should be isystem. This PR restricts the number of -I passed to the clang command line and correctly marks the llvm libc include path as isystem.

There are still two paths that should be removed but I couldn't find where they are set.

@jhuber6 can I ask you to try this patch for the GPU ? I can't test it on my side.

@gchatelet
Copy link
Contributor Author

gchatelet commented Sep 19, 2023

Before this patch for libc/src/fenv/feclearexcept.cpp

  • -I/home/gchatelet/build/libc_x86/projects/libc/src/fenv
  • -I/home/gchatelet/git/llvm-project/libc/src/fenv
  • -I/home/gchatelet/build/libc_x86/include
  • -I/home/gchatelet/git/llvm-project/llvm/include
  • -I/home/gchatelet/git/llvm-project/libc
  • -I/home/gchatelet/build/libc_x86/projects/libc/include

After this patch

  • -I/home/gchatelet/build/libc_x86/projects/libc/src/fenv <-- This one should also go away
  • -I/home/gchatelet/git/llvm-project/libc/src/fenv <-- This one should also go away
  • -I/home/gchatelet/git/llvm-project/libc
  • -isystem /home/gchatelet/build/libc_x86/projects/libc/include

@jhuber6
Copy link
Contributor

jhuber6 commented Sep 19, 2023

Works fine on the GPU build

# `llvm-project/llvm/CMakeLists.txt` adds the following directive
# `include_directories( ${LLVM_INCLUDE_DIR} ${LLVM_MAIN_INCLUDE_DIR})`
# We undo it to be able to precisely control what is getting included.
set_property(DIRECTORY . PROPERTY INCLUDE_DIRECTORIES "")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@gchatelet
Copy link
Contributor Author

I've used grep, and cmake --trace and --trace-expand but I couldn't find where the first two include are coming from.
Anyways, it should be good enough for #66477

@sivachandra
Copy link
Collaborator

Feel free to land this change. We can cleanup as required.

@gchatelet gchatelet merged commit a35a3b7 into llvm:main Sep 19, 2023
2 checks passed
@gchatelet gchatelet deleted the fix_includes branch September 19, 2023 21:08
gchatelet added a commit to gchatelet/llvm-project that referenced this pull request Sep 19, 2023
This reverts commit a35a3b7.
This broke libc benchmarks.
gchatelet added a commit that referenced this pull request Sep 19, 2023
This reverts commit a35a3b7. This broke
libc benchmarks.
gchatelet added a commit to gchatelet/llvm-project that referenced this pull request Sep 20, 2023
We want to activate `llvm-header-guard` (llvm#66477) but the current CMake
configuration includes paths that should be `isystem`. This PR restricts
the number of `-I` passed to the clang command line and correctly marks
the llvm libc include path as `isystem`.

This is a reland of llvm#66783 a35a3b7 fixing the benchmark breakage.
gchatelet added a commit that referenced this pull request Sep 20, 2023
This is a reland of #66783 a35a3b7
fixing the benchmark breakage.
@@ -189,13 +188,10 @@ function(_build_gpu_objects fq_target_name internal_target_name)
)

target_compile_options(${gpu_target_name} PRIVATE ${compile_options})
target_include_directories(${gpu_target_name} PRIVATE ${include_dirs})
target_include_directories(${gpu_target_name} SYSTEM PRIVATE ${LIBC_INCLUDE_DIR})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking include directory as "system" will hide warnings from the headers located in this directory.
It might be worth adding -Wsystem-headers to compilation flags to mitigate the issue.

Copy link
Contributor Author

@gchatelet gchatelet Sep 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx for chiming in here :)

Marking include directory as "system" will hide warnings from the headers located in this directory.

Yes this is on purpose. At least for clang-tidy we don't want the libc generated headers to participate in the clang-tidy checks (see #66477 (comment))

-Wsystem-headers is indeed a good way to catch errors in generated headers but it will potentially also catch warnings in the headers we don't own (clang provided headers or linux headers). WDYT @sivachandra ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. For some reason I thought that libc is fully isolated from the OS, but it may indeed pull OS headers, and those probably aren't clean (I can imagine warnings about unsupported attributes, pragmas, etc.).
On the other hand, -isystem suppresses warnings coming from libc's headers when building libc itself. This is probably lesser evil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants