[libclc] [libclc] Give a helpful error when an unknown target is requested (PR #111528)

David Spickett via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 8 05:44:55 PDT 2024


https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/111528

I just tried using LLVM backend names here e.g. NVPTX but libclc want's targets more like triples. This change adds a mesasge to tell you that.

Before you got:
```
 libclc target 'AMDGCN' is enabled
 CMake Error at CMakeLists.txt:253 (list):
   list index: 1 out of range (-1, 0)

 CMake Error at CMakeLists.txt:254 (list):
   list index: 2 out of range (-1, 0)

 Configuring incomplete, errors occurred!
```
Now you get:

```
 CMake Error at CMakeLists.txt:145 (message):
   Unknown target in LIBCLC_TARGETS_TO_BUILD: "AMDGCN"

   Valid targets are:
   amdgcn--;amdgcn--amdhsa;clspv--;clspv64--;r600--;nvptx--;nvptx64--;nvptx--nvidiacl;nvptx64--nvidiacl;amdgcn-mesa-mesa3d
```
Some of the targets are dynamic based on what is installed, so spirv isn't here for me because I don't have llvm-spirv installed yet.

So this is not perfect but it's an improvement on the current behaviour.

>From 686a0404c968d3bcec56bca232599465a9549312 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Tue, 8 Oct 2024 12:40:40 +0000
Subject: [PATCH] [libclc] Give a helpful error when an unknown target is
 requested

I just tried using LLVM backend names here e.g. NVPTX but libclc
want's targets more like triples. This change adds a mesasge to
tell you that.

Before you got:
```
 libclc target 'AMDGCN' is enabled
 CMake Error at CMakeLists.txt:253 (list):
   list index: 1 out of range (-1, 0)

 CMake Error at CMakeLists.txt:254 (list):
   list index: 2 out of range (-1, 0)

 Configuring incomplete, errors occurred!
```
Now you get:

```
 CMake Error at CMakeLists.txt:145 (message):
   Unknown target in LIBCLC_TARGETS_TO_BUILD: "AMDGCN"

   Valid targets are:
   amdgcn--;amdgcn--amdhsa;clspv--;clspv64--;r600--;nvptx--;nvptx64--;nvptx--nvidiacl;nvptx64--nvidiacl;amdgcn-mesa-mesa3d
```
Some of the targets are dynamic based on what is installed,
so spirv isn't here for me because I don't have llvm-spirv
installed yet.

So this is not perfect but it's an improvement on the current
behaviour.
---
 libclc/CMakeLists.txt | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 260e4d433a1d49..0135b2c64e3ea6 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -139,6 +139,13 @@ endif()
 
 if( LIBCLC_TARGETS_TO_BUILD STREQUAL "all" )
   set( LIBCLC_TARGETS_TO_BUILD ${LIBCLC_TARGETS_ALL} )
+else()
+  foreach(TARGET_TO_BUILD ${LIBCLC_TARGETS_TO_BUILD})
+    if (NOT ${TARGET_TO_BUILD} IN_LIST LIBCLC_TARGETS_ALL)
+      message ( FATAL_ERROR "Unknown target in LIBCLC_TARGETS_TO_BUILD: \"${TARGET_TO_BUILD}\"\n"
+                            "Valid targets are: ${LIBCLC_TARGETS_ALL}")
+    endif()
+  endforeach()
 endif()
 
 list( SORT LIBCLC_TARGETS_TO_BUILD )



More information about the cfe-commits mailing list