-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Add compile tests for each public header #122527
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
Changes from all commits
cc2061a
91da76c
56d789a
76b24bb
1370e51
cfa89f6
36c1dc3
ca8e8cd
57ee7ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -422,7 +422,7 @@ add_libc_test( | |
-Werror | ||
DEPENDS | ||
libc.include.llvm-libc-macros.math_function_macros | ||
) | ||
) | ||
|
||
add_libc_test( | ||
isfinite_c_test | ||
|
@@ -483,3 +483,70 @@ add_libc_test( | |
DEPENDS | ||
libc.include.llvm-libc-macros.math_function_macros | ||
) | ||
|
||
# Test `#include <...>` of each header in each available language mode. | ||
# This is gated on -DLLVM_LIBC_BUILD_HEADER_TESTS=ON until all the bugs | ||
# in headers are fixed so the tests all compile. | ||
set(TEST_STDC_VERSIONS 89;99;11;17;23) | ||
set(TEST_STDCXX_VERSIONS 03;11;14;17;20;23;26) | ||
|
||
function(add_header_test target_name source_file deps std_mode) | ||
if(LLVM_LIBC_BUILD_HEADER_TESTS) | ||
add_libc_test( | ||
${target_name} | ||
C_TEST | ||
HERMETIC_TEST_ONLY | ||
SUITE | ||
libc_include_tests | ||
SRCS | ||
${source_file} | ||
COMPILE_OPTIONS | ||
-Werror | ||
-Wsystem-headers | ||
-Wall | ||
-Wextra | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you need to be setting There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to, but it shouldn't hurt. I'll try it. These will only be considered "system headers" by the compiler if they're found in a directory that's put on the path with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wrong! I'm not sure yet how we're plumbing things, but we are getting the system header exception for the libc headers. And boy howdy do we need it! To start with, every file uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I can recall, the use of |
||
-std=${std_mode} | ||
DEPENDS | ||
${deps} | ||
) | ||
endif() | ||
endfunction() | ||
|
||
foreach(target ${TARGET_PUBLIC_HEADERS}) | ||
string(REPLACE "libc.include." "" header ${target}) | ||
get_target_property(HEADER_NAME ${target} HEADER_NAME) | ||
|
||
set(test_stdc_file "${CMAKE_CURRENT_BINARY_DIR}/${header}_test.c") | ||
configure_file(header-test-template.c ${test_stdc_file} @ONLY) | ||
foreach(stdc_version ${TEST_STDC_VERSIONS}) | ||
add_header_test( | ||
"${header}_c${stdc_version}_test" | ||
${test_stdc_file} | ||
${target} | ||
"c${stdc_version}" | ||
) | ||
add_header_test( | ||
"${header}_gnu${stdc_version}_test" | ||
${test_stdc_file} | ||
${target} | ||
"gnu${stdc_version}" | ||
) | ||
endforeach() | ||
|
||
set(test_stdcxx_file "${CMAKE_CURRENT_BINARY_DIR}/${header}_test.cpp") | ||
configure_file(header-test-template.c ${test_stdcxx_file} @ONLY) | ||
foreach(stdcxx_version ${TEST_STDCXX_VERSIONS}) | ||
add_header_test( | ||
"${header}_cpp${stdcxx_version}_test" | ||
${test_stdcxx_file} | ||
${target} | ||
"c++${stdcxx_version}" | ||
) | ||
add_header_test( | ||
"${header}_gnucpp${stdcxx_version}_test" | ||
${test_stdcxx_file} | ||
${target} | ||
"gnu++${stdcxx_version}" | ||
) | ||
endforeach() | ||
endforeach() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/*===-- Test for <@HEADER_NAME@> ----------------------------------------=== | ||
* | ||
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
* See https://llvm.org/LICENSE.txt for license information. | ||
* SPDXList-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
overmighty marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
|
||
#include <@HEADER_NAME@> | ||
|
||
int main(int argc, char **argv) { | ||
(void)argc; | ||
(void)argv; | ||
return 0; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.