Skip to content

Conversation

etcwilde
Copy link
Contributor

@etcwilde etcwilde commented Apr 1, 2025

The try-compile mechanism requires that CMAKE_REQUIRED_FLAGS is a space-separated string instead of a list of flags. The original code expanded BUILTIN_FLAGS into CMAKE_REQUIRED_FLAGS as a space-separated string and then would overwrite CMAKE_REQUIRED_FLAGS with TARGET_${arch}_CFLAGS prepended to the unexpanded
BUILTIN_CFLAGS_${arch}. This resulted in the first two arguments being passed into the try-compile invocation, but dropping the other arguments listed in BUILTIN_CFLAGS_${arch}.

This patch appends ${TARGET_${arch}_CFLAGS} to the list, and then joins the elements with spaces, resulting in all arguments passed via CMAKE_REQUIRED_FLAGS being space-separated and being used in the try-compile when detecting Float16.

Copy link
Member

@arichardson arichardson left a comment

Choose a reason for hiding this comment

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

Unrelated to this change but I see string(REPLACE ";" " " _TARGET_${arch}_CFLAGS "${TARGET_${arch}_CFLAGS}") below, which I think could just be dropped and we use CMAKE_REQUIRED_FLASG instead?

etcwilde added 2 commits April 2, 2025 16:19
The try-compile mechanism requires that `CMAKE_REQUIRED_FLAGS` is a
space-separated string instead of a list of flags. The original code
expanded BUILTIN_FLAGS into CMAKE_REQUIRED_FLAGS as a space-separated
string and then would overwrite CMAKE_REQUIRED_FLAGS with
TARGET_${arch}_CFLAGS prepended to the unexpanded
BUILTIN_CFLAGS_${arch}. This resulted in the first two arguments being
passed into the try-compile invocation, but dropping the other arguments
listed in BUILTIN_CFLAGS_${arch}.

This patch takes the contents of both TARGET_${arch}_CLFAGS and
BUILTIN_FLAGS_${arch}, combines them into a single list, and then
joins that list as a space-separated string in `CMAKE_REQUIRED_FLAGS`.
`TARGET_${arch}_CFLAGS` is expanded into `CMAKE_REQUIRED_FLAGS`, which
is implicitly added to the flags by `check_compile_definition`. We don't
need to re-expand the `TARGET_${arch}_CFLAGS` variable again.
@etcwilde
Copy link
Contributor Author

etcwilde commented Apr 2, 2025

Unrelated to this change but I see string(REPLACE ";" " " TARGET${arch}CFLAGS "${TARGET${arch}_CFLAGS}") below, which I think could just be dropped and we use CMAKE_REQUIRED_FLASG instead?

Even better, it looks like check_compile_definition implicitly adds CMAKE_REQUIRED_FLAGS:

function(check_compile_definition def argstring out_var)
if("${def}" STREQUAL "")
set(${out_var} TRUE PARENT_SCOPE)
return()
endif()
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${argstring}")
check_symbol_exists(${def} "" ${out_var})
cmake_pop_check_state()
endfunction()

I've dropped adding those arguments entirely and it's only adding CMAKE_C_FLAGS.

Comment on lines 860 to 861
set(CMAKE_REQUIRED_FLAGS ${BUILTIN_CFLAGS_${arch}} ${TARGET_${arch}_CFLAGS})
list(JOIN CMAKE_REQUIRED_FLAGS " " CMAKE_REQUIRED_FLAGS)
Copy link
Member

Choose a reason for hiding this comment

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

This is going to overwrite CMAKE_REQUIRED_FLAGS set by parent directories. Instead, we should be concatenating the flags.

Suggested change
set(CMAKE_REQUIRED_FLAGS ${BUILTIN_CFLAGS_${arch}} ${TARGET_${arch}_CFLAGS})
list(JOIN CMAKE_REQUIRED_FLAGS " " CMAKE_REQUIRED_FLAGS)
set(BUILTIN_CFLAGS ${BUILTIN_CFLAGS_${arch}} ${TARGET_${arch}_CFLAGS})
list(JOIN BUILTIN_CFLAGS " " BUILTIN_CFLAGS)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${BUILTIN_CFLAGS}")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original behavior also did not include existing CMAKE_REQUIRED_FLAGS. Fixed.

The original behavior also omitted any existing required flags. Patch
this to include them in the _Float16 support check.
@etcwilde etcwilde requested a review from petrhosek April 3, 2025 17:05
@etcwilde etcwilde merged commit 0d3f5ec into llvm:main Apr 4, 2025
10 checks passed
@etcwilde etcwilde deleted the ewilde/compiler-rt-all-the-flags branch April 4, 2025 16:02
etcwilde added a commit to etcwilde/llvm-project that referenced this pull request Apr 4, 2025
)

The try-compile mechanism requires that `CMAKE_REQUIRED_FLAGS` is a
space-separated string instead of a list of flags. The original code
expanded `BUILTIN_FLAGS` into `CMAKE_REQUIRED_FLAGS` as a
space-separated string and then would overwrite `CMAKE_REQUIRED_FLAGS`
with `TARGET_${arch}_CFLAGS` prepended to the unexpanded
`BUILTIN_CFLAGS_${arch}`. This resulted in the first two arguments being
passed into the try-compile invocation, but dropping the other arguments
listed in `BUILTIN_CFLAGS_${arch}`.

This patch appends `TARGET_${arch}_CFLAGS` and `BUILTIN_CFLAGS_${arch}` to
`CMAKE_REQUIRED_FLAGS` before expanding CMAKE_REQUIRED_FLAGS as a
space-separated string. This passes any pre-set required flags, in addition to
all of the builtin and target flags to the Float16 detection.

(cherry picked from commit 0d3f5ec)
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 4, 2025

LLVM Buildbot has detected a new failure on builder clang-aarch64-sve-vla running on linaro-g3-04 while building compiler-rt at step 7 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/17/builds/7033

Here is the relevant piece of the build log for the reference
Step 7 (ninja check 1) failure: stage 1 checked (failure)
...
PASS: Flang :: Driver/fveclib-codegen.f90 (25210 of 97650)
PASS: Flang :: Driver/predefined-macros-compiler-version.F90 (25211 of 97650)
PASS: Flang :: Driver/print-effective-triple.f90 (25212 of 97650)
PASS: Flang :: Driver/print-resource-dir.F90 (25213 of 97650)
PASS: Flang :: Driver/config-file.f90 (25214 of 97650)
PASS: Flang :: Driver/include-header.f90 (25215 of 97650)
PASS: Flang :: Driver/parse-fir-error.ll (25216 of 97650)
PASS: Clangd Unit Tests :: ./ClangdTests/35/81 (25217 of 97650)
PASS: Flang :: Driver/missing-arg.f90 (25218 of 97650)
UNRESOLVED: Flang :: Driver/slp-vectorize.ll (25219 of 97650)
******************** TEST 'Flang :: Driver/slp-vectorize.ll' FAILED ********************
Test has no 'RUN:' line
********************
PASS: Flang :: Driver/mlink-builtin-bc.f90 (25220 of 97650)
PASS: Flang :: Driver/parse-error.ll (25221 of 97650)
PASS: Flang :: Driver/print-pipeline-passes.f90 (25222 of 97650)
PASS: Clangd Unit Tests :: ./ClangdTests/36/81 (25223 of 97650)
PASS: Flang :: Driver/pthread.f90 (25224 of 97650)
PASS: Flang :: Driver/override-triple.ll (25225 of 97650)
PASS: Flang :: Driver/bbc-openmp-version-macro.f90 (25226 of 97650)
PASS: Flang :: Driver/phases.f90 (25227 of 97650)
PASS: Flang :: Driver/parse-ir-error.f95 (25228 of 97650)
PASS: Flang :: Driver/scanning-error.f95 (25229 of 97650)
PASS: Flang :: Driver/mlir-pass-pipeline.f90 (25230 of 97650)
PASS: Flang :: Driver/supported-suffices/f08-suffix.f08 (25231 of 97650)
PASS: Flang :: Driver/std2018-wrong.f90 (25232 of 97650)
PASS: Flang :: Driver/linker-flags.f90 (25233 of 97650)
PASS: Flang :: Driver/pp-fixed-form.f90 (25234 of 97650)
PASS: Clangd Unit Tests :: ./ClangdTests/79/81 (25235 of 97650)
PASS: Flang :: Driver/print-target-triple.f90 (25236 of 97650)
PASS: Flang :: Driver/target-gpu-features.f90 (25237 of 97650)
PASS: Flang :: Driver/target.f90 (25238 of 97650)
PASS: Flang :: Driver/supported-suffices/f03-suffix.f03 (25239 of 97650)
PASS: Flang :: Driver/macro-def-undef.F90 (25240 of 97650)
PASS: Flang :: Driver/tco-code-gen-llvm.fir (25241 of 97650)
PASS: Flang :: Driver/lto-bc.f90 (25242 of 97650)
PASS: Flang :: Driver/multiple-input-files.f90 (25243 of 97650)
PASS: Flang :: Driver/pass-plugin-not-found.f90 (25244 of 97650)
PASS: Flang :: Driver/q-unused-arguments.f90 (25245 of 97650)
PASS: Flang :: Driver/unsupported-vscale-max-min.f90 (25246 of 97650)
PASS: Flang :: Driver/lto-flags.f90 (25247 of 97650)
PASS: Flang :: Driver/unparse-with-modules.f90 (25248 of 97650)
PASS: Flang :: Driver/prescanner-diag.f90 (25249 of 97650)
PASS: Flang :: Driver/mllvm.f90 (25250 of 97650)
PASS: Flang :: Driver/target-machine-error.f90 (25251 of 97650)
PASS: Flang :: Driver/save-temps.f90 (25252 of 97650)
PASS: Flang :: Driver/optimization-remark-invalid.f90 (25253 of 97650)
PASS: Flang :: Driver/fixed-line-length.f90 (25254 of 97650)
PASS: Flang :: Driver/std2018.f90 (25255 of 97650)

devincoughlin pushed a commit to swiftlang/llvm-project that referenced this pull request Apr 21, 2025
)

The try-compile mechanism requires that `CMAKE_REQUIRED_FLAGS` is a
space-separated string instead of a list of flags. The original code
expanded `BUILTIN_FLAGS` into `CMAKE_REQUIRED_FLAGS` as a
space-separated string and then would overwrite `CMAKE_REQUIRED_FLAGS`
with `TARGET_${arch}_CFLAGS` prepended to the unexpanded
`BUILTIN_CFLAGS_${arch}`. This resulted in the first two arguments being
passed into the try-compile invocation, but dropping the other arguments
listed in `BUILTIN_CFLAGS_${arch}`.

This patch appends `TARGET_${arch}_CFLAGS` and `BUILTIN_CFLAGS_${arch}` to
`CMAKE_REQUIRED_FLAGS` before expanding CMAKE_REQUIRED_FLAGS as a
space-separated string. This passes any pre-set required flags, in addition to
all of the builtin and target flags to the Float16 detection.

(cherry picked from commit 0d3f5ec)
(cherry picked from commit e958952)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants