[clang] Remove .. from clang resource path when specified with CLANG_RESOURCE_DIR (PR #216996)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 18 04:34:37 PDT 2026
https://github.com/rgal created https://github.com/llvm/llvm-project/pull/216996
As discussed here: https://discourse.llvm.org/t/removing-clang-version-number-from-resource-dir-in-a-distribution/90234
If a distributor wishes to have stable include paths across LLVM versions, then they can build with `CLANG_RESOURCE_DIR=../lib/clang`. This results in a slightly untidy include path (E.g.`C:\Program Files\LLVM\bin\..\lib\clang\include`). This removes the ".." to make it `C:\Program Files\LLVM\lib\clang\include` in this configuration.
Also added test. This uses "SIE" vendor. Since https://github.com/llvm/llvm-zorg/commit/eac6791821f5104eb4c2b32f39ef5d20cda535a9, PS4 and PS5 buildbots use this configuration and define the vendor so this should be tested on at least these buildbots.
>From e4ac50becb905acfa7bdd9e0f47954bdd239f7f4 Mon Sep 17 00:00:00 2001
From: Russell Gallop <russell.gallop at sony.com>
Date: Thu, 19 Mar 2026 12:13:09 +0000
Subject: [PATCH 1/4] Remove dots from clang resource path, if configured with
relative CLANG_RESOURCE_DIR
---
clang/lib/Options/OptionUtils.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/clang/lib/Options/OptionUtils.cpp b/clang/lib/Options/OptionUtils.cpp
index 77f89552e852a..4ea312639d9de 100644
--- a/clang/lib/Options/OptionUtils.cpp
+++ b/clang/lib/Options/OptionUtils.cpp
@@ -219,10 +219,12 @@ std::string clang::GetResourcesPath(StringRef BinaryPath) {
if (!ConfiguredResourceDir.empty()) {
// FIXME: We should fix the behavior of llvm::sys::path::append so we don't
// need to check for absolute paths here.
- if (llvm::sys::path::is_absolute(ConfiguredResourceDir))
+ if (llvm::sys::path::is_absolute(ConfiguredResourceDir)) {
P = ConfiguredResourceDir;
- else
+ } else {
llvm::sys::path::append(P, ConfiguredResourceDir);
+ llvm::sys::path::remove_dots(P, true);
+ }
} else {
// On Windows, libclang.dll is in bin/.
// On non-Windows, libclang.so/.dylib is in lib/.
>From 55604b937de352b909b4bb48f50cbc13dbf46c5d Mon Sep 17 00:00:00 2001
From: Russell Gallop <russell.gallop at sony.com>
Date: Fri, 24 Jul 2026 14:30:17 +0100
Subject: [PATCH 2/4] Add test for versionless clang resource path.
Specific to SIE vendor toolchains.
---
clang/test/Driver/sie-resource-path.cpp | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 clang/test/Driver/sie-resource-path.cpp
diff --git a/clang/test/Driver/sie-resource-path.cpp b/clang/test/Driver/sie-resource-path.cpp
new file mode 100644
index 0000000000000..ee2651c32c2d4
--- /dev/null
+++ b/clang/test/Driver/sie-resource-path.cpp
@@ -0,0 +1,12 @@
+// REQUIRES: clang-vendor=SIE
+
+// Test relative CLANG_RESOURCE_PATH configuration, as used on SIE toolchains.
+// --target shouldn't have an impact on this as it's a build config.
+
+// RUN: %clang -c -### %s 2>&1 | FileCheck %s
+// Expected resource path.
+// CHECK: "-resource-dir" "{{.*}}{{/|\\\\}}lib{{/|\\\\}}clang"
+// Check resource path doesn't have a version number at the end.
+// CHECK-NOT: "-resource-dir" "{{.*}}{{/|\\\\}}lib{{/|\\\\}}clang{{/|\\\\}}{{[0-9]}}"
+// Check resource path doesn't have .. before lib.
+// CHECK-NOT: "-resource-dir" "{{.*}}..{{/|\\\\}}lib{{/|\\\\}}clang"
>From 918e802d4124830ee6de6d8866e31a4892db3ee4 Mon Sep 17 00:00:00 2001
From: Russell Gallop <russell.gallop at sony.com>
Date: Fri, 24 Jul 2026 17:18:54 +0100
Subject: [PATCH 3/4] Improve test to be sensitive to dots before and version
numbers after.
Previously the check not tests weren't actually doing anything, as the
checked the strings after the CHECK succeeded.
Added a . check before, and the hard end of the " should catch a stray
version number.
---
clang/test/Driver/sie-resource-path.cpp | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)
diff --git a/clang/test/Driver/sie-resource-path.cpp b/clang/test/Driver/sie-resource-path.cpp
index ee2651c32c2d4..a54d229539fdd 100644
--- a/clang/test/Driver/sie-resource-path.cpp
+++ b/clang/test/Driver/sie-resource-path.cpp
@@ -1,12 +1,8 @@
// REQUIRES: clang-vendor=SIE
-// Test relative CLANG_RESOURCE_PATH configuration, as used on SIE toolchains.
+// Test relative CLANG_RESOURCE_PATH=../lib/clang configuration, as used on SIE toolchains.
// --target shouldn't have an impact on this as it's a build config.
// RUN: %clang -c -### %s 2>&1 | FileCheck %s
-// Expected resource path.
-// CHECK: "-resource-dir" "{{.*}}{{/|\\\\}}lib{{/|\\\\}}clang"
-// Check resource path doesn't have a version number at the end.
-// CHECK-NOT: "-resource-dir" "{{.*}}{{/|\\\\}}lib{{/|\\\\}}clang{{/|\\\\}}{{[0-9]}}"
-// Check resource path doesn't have .. before lib.
-// CHECK-NOT: "-resource-dir" "{{.*}}..{{/|\\\\}}lib{{/|\\\\}}clang"
+// Expected resource path doesn't have a . before, or a number after.
+// CHECK: "-resource-dir" "{{.*[^.]}}{{/|\\\\}}lib{{/|\\\\}}clang"
>From a69d1c204ae8f6f86ab001b80409311e76912400 Mon Sep 17 00:00:00 2001
From: Russell Gallop <russell.gallop at sony.com>
Date: Mon, 27 Jul 2026 10:33:56 +0100
Subject: [PATCH 4/4] Expand on commentary a bit.
---
clang/test/Driver/sie-resource-path.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/test/Driver/sie-resource-path.cpp b/clang/test/Driver/sie-resource-path.cpp
index a54d229539fdd..11e716ca17447 100644
--- a/clang/test/Driver/sie-resource-path.cpp
+++ b/clang/test/Driver/sie-resource-path.cpp
@@ -1,6 +1,7 @@
// REQUIRES: clang-vendor=SIE
-// Test relative CLANG_RESOURCE_PATH=../lib/clang configuration, as used on SIE toolchains.
+// Test relative CLANG_RESOURCE_PATH=../lib/clang configuration, as used on
+// SIE toolchains (PS4/PS5).
// --target shouldn't have an impact on this as it's a build config.
// RUN: %clang -c -### %s 2>&1 | FileCheck %s
More information about the cfe-commits
mailing list