[compiler-rt] 6f4f0af - [Compiler-rt] Fix bug when considering CMake path returned by llvm-config.

Dan Liew via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 20 11:57:46 PDT 2021


Author: Dan Liew
Date: 2021-04-20T11:57:20-07:00
New Revision: 6f4f0afaa8ae54e44e94b9358bb5336a35cb8614

URL: https://github.com/llvm/llvm-project/commit/6f4f0afaa8ae54e44e94b9358bb5336a35cb8614
DIFF: https://github.com/llvm/llvm-project/commit/6f4f0afaa8ae54e44e94b9358bb5336a35cb8614.diff

LOG: [Compiler-rt] Fix bug when considering CMake path returned by llvm-config.

The previous check was wrong because it only checks that the LLVM CMake
directory exists. However, it's possible that the directory exists but
the `LLVMConfig.cmake` file does not. When this happens we would
incorectly try to include the non-existant file.

To fix this we make the check stricter by checking that the file
we want to include actually exists.

This is a follow up to fd28517d878e1d3d14f492ab659aabdf729fd331.

rdar://76870467

Added: 
    

Modified: 
    compiler-rt/cmake/Modules/CompilerRTUtils.cmake

Removed: 
    


################################################################################
diff  --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index 5f209e6d1d83..e8e0ec20af29 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -373,15 +373,17 @@ macro(load_llvm_config)
       set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR_CMAKE_STYLE}/lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm")
     endif()
 
-    if (EXISTS "${LLVM_CMAKE_PATH}")
+    set(LLVM_CMAKE_INCLUDE_FILE "${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
+    if (EXISTS "${LLVM_CMAKE_INCLUDE_FILE}")
       list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
       # Get some LLVM variables from LLVMConfig.
-      include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
+      include("${LLVM_CMAKE_INCLUDE_FILE}")
       set(FOUND_LLVM_CMAKE_PATH TRUE)
     else()
       set(FOUND_LLVM_CMAKE_PATH FALSE)
-      message(WARNING "LLVM CMake path (${LLVM_CMAKE_PATH}) reported by llvm-config does not exist")
+      message(WARNING "LLVM CMake path (${LLVM_CMAKE_INCLUDE_FILE}) reported by llvm-config does not exist")
     endif()
+    unset(LLVM_CMAKE_INCLUDE_FILE)
 
     set(LLVM_LIBRARY_OUTPUT_INTDIR
       ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})


        


More information about the llvm-commits mailing list