[PATCH] D148364: Check default target triple during config

Nathan Sidwell via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 14 12:13:59 PDT 2023


urnathan created this revision.
Herald added subscribers: fedor.sergeev, kristof.beyls.
Herald added a project: All.
urnathan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

I wasted some time setting a default target triple to 'arm-eabi', thinking it would be canonicalized.  The build succeeded but testing blew up because utils/lit/lit/llvm/config.py has:

  def make_itanium_abi_triple(self, triple):
       m = re.match(r'(\w+)-(\w+)-(\w+)', triple)
      ...

and that regex expects at least two '-'.  Notice that regex isn't anchored and some triplets have '.' (solaris2.10 is the example I recall, dunno if anyone cares enough now though).  Anyway, this inserts a regex check in set_llvm_target_triplet to look for something at least reasonable at cmake config time -- somewhat earlier.


https://reviews.llvm.org/D148364

Files:
  llvm/cmake/modules/SetTargetTriple.cmake


Index: llvm/cmake/modules/SetTargetTriple.cmake
===================================================================
--- llvm/cmake/modules/SetTargetTriple.cmake
+++ llvm/cmake/modules/SetTargetTriple.cmake
@@ -1,9 +1,16 @@
 macro(set_llvm_target_triple)
-  set(LLVM_DEFAULT_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE_default}" CACHE STRING
-  "Default target for which LLVM will generate code." )
+  set(LLVM_DEFAULT_TARGET_TRIPLE
+    "${LLVM_DEFAULT_TARGET_TRIPLE_default}" CACHE STRING
+    "Default target for which LLVM will generate code." )
+  if (NOT LLVM_DEFAULT_TARGET_TRIPLE
+      MATCHES "^[0-9A-Za-z_]+-[0-9A-Za-z_]+-[0-9A-Za-z_.]+(-[0-9A-Za-z_]+)?\$")
+    message(FATAL_ERROR
+      "LLVM_DEFAULT_TARGET_TRIPLE '${LLVM_DEFAULT_TARGET_TRIPLE}' is malformed")
+  endif ()
   if (TARGET_TRIPLE)
-    message(WARNING "TARGET_TRIPLE is deprecated and will be removed in a future release. "
-    "Please use LLVM_DEFAULT_TARGET_TRIPLE instead.")
+    message(WARNING
+      "TARGET_TRIPLE is deprecated and will be removed in a future release. "
+      "Please use LLVM_DEFAULT_TARGET_TRIPLE instead.")
     set(LLVM_TARGET_TRIPLE "${TARGET_TRIPLE}")
   else()
     set(LLVM_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148364.513707.patch
Type: text/x-patch
Size: 1233 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230414/ad292c34/attachment.bin>


More information about the llvm-commits mailing list