https://github.com/wenju-he updated 
https://github.com/llvm/llvm-project/pull/199164

>From 19a2287424d6be4b0030df95fc5d21b695e43333 Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Fri, 22 May 2026 07:04:24 +0200
Subject: [PATCH 1/4] [libclc] Diable .cl tests in standalone build

libclc standalone build puts libclc.bc in ${CMAKE_CURRENT_BINARY_DIR}/
${TARGET_TRIPLE} dir. check-libclc fails because .cl test is looking for
libclc in clang resource dir.

Disabling them is simple fix.
---
 libclc/test/lit.cfg.py         | 4 +++-
 libclc/test/lit.site.cfg.py.in | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/libclc/test/lit.cfg.py b/libclc/test/lit.cfg.py
index 22715411ea9d6..d6c9eb7428b29 100644
--- a/libclc/test/lit.cfg.py
+++ b/libclc/test/lit.cfg.py
@@ -17,7 +17,9 @@
 config.test_format = lit.formats.ShTest()
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = [".cl", ".test"]
+config.suffixes = [".test"]
+if not config.libclc_standalone_build:
+    config.suffixes.append(".cl")
 
 # Exclude certain directories and files from test discovery
 config.excludes = [
diff --git a/libclc/test/lit.site.cfg.py.in b/libclc/test/lit.site.cfg.py.in
index 3c9acfc0551f0..87a9626afbe53 100644
--- a/libclc/test/lit.site.cfg.py.in
+++ b/libclc/test/lit.site.cfg.py.in
@@ -9,6 +9,7 @@ config.libclc_obj_root = 
lit_config.substitute(path(r"@CMAKE_CURRENT_BINARY_DIR@
 config.libclc_target = "@LIBCLC_TARGET@"
 config.libclc_target_arch = "@LIBCLC_TARGET_ARCH@"
 config.libclc_target_cpu = "@LIBCLC_TARGET_CPU@"
+config.libclc_standalone_build = "@LIBCLC_STANDALONE_BUILD@" == "TRUE"
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)

>From 71bc1368610716f49fabae024de113562fb62bb8 Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Fri, 22 May 2026 12:22:47 +0200
Subject: [PATCH 2/4] Revert "[libclc] Diable .cl tests in standalone build"

This reverts commit 19a2287424d6be4b0030df95fc5d21b695e43333.
---
 libclc/test/lit.cfg.py         | 4 +---
 libclc/test/lit.site.cfg.py.in | 1 -
 2 files changed, 1 insertion(+), 4 deletions(-)

diff --git a/libclc/test/lit.cfg.py b/libclc/test/lit.cfg.py
index d6c9eb7428b29..22715411ea9d6 100644
--- a/libclc/test/lit.cfg.py
+++ b/libclc/test/lit.cfg.py
@@ -17,9 +17,7 @@
 config.test_format = lit.formats.ShTest()
 
 # suffixes: A list of file extensions to treat as test files.
-config.suffixes = [".test"]
-if not config.libclc_standalone_build:
-    config.suffixes.append(".cl")
+config.suffixes = [".cl", ".test"]
 
 # Exclude certain directories and files from test discovery
 config.excludes = [
diff --git a/libclc/test/lit.site.cfg.py.in b/libclc/test/lit.site.cfg.py.in
index 87a9626afbe53..3c9acfc0551f0 100644
--- a/libclc/test/lit.site.cfg.py.in
+++ b/libclc/test/lit.site.cfg.py.in
@@ -9,7 +9,6 @@ config.libclc_obj_root = 
lit_config.substitute(path(r"@CMAKE_CURRENT_BINARY_DIR@
 config.libclc_target = "@LIBCLC_TARGET@"
 config.libclc_target_arch = "@LIBCLC_TARGET_ARCH@"
 config.libclc_target_cpu = "@LIBCLC_TARGET_CPU@"
-config.libclc_standalone_build = "@LIBCLC_STANDALONE_BUILD@" == "TRUE"
 
 import lit.llvm
 lit.llvm.initialize(lit_config, config)

>From 9e003de0f30663b51f93d06127b9b0ae46681e5c Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Fri, 22 May 2026 12:34:28 +0200
Subject: [PATCH 3/4] add --libclc-lib= to .cl tests in standalone build

---
 libclc/test/conversion/convert.cl     |  2 +-
 libclc/test/geometric/cross.cl        |  2 +-
 libclc/test/integer/add_sat.cl        |  2 +-
 libclc/test/integer/sub_sat.cl        |  2 +-
 libclc/test/lit.cfg.py                |  5 +++++
 libclc/test/lit.site.cfg.py.in        |  1 +
 libclc/test/math/cos.cl               |  2 +-
 libclc/test/math/fabs.cl              |  2 +-
 libclc/test/math/rsqrt.cl             | 18 +++++++++---------
 libclc/test/misc/as_type.cl           |  2 +-
 libclc/test/update_libclc_tests.py    | 25 +++++++++++++++++++++++--
 libclc/test/work-item/get_group_id.cl |  2 +-
 12 files changed, 46 insertions(+), 19 deletions(-)

diff --git a/libclc/test/conversion/convert.cl 
b/libclc/test/conversion/convert.cl
index 2e2a79e4ebb1e..0c0a1a3c88561 100644
--- a/libclc/test/conversion/convert.cl
+++ b/libclc/test/conversion/convert.cl
@@ -1,7 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang --target=%target -mcpu=%cpu -cl-std=CL3.0 -O2 -emit-llvm -S -o 
- %s | FileCheck %s --check-prefix=%check_prefix
+// RUN: %clang --target=%target -mcpu=%cpu %libclc_lib -cl-std=CL3.0 -O2 
-emit-llvm -S -o - %s | FileCheck %s --check-prefix=%check_prefix
 
 // AMDGCN-LABEL: define hidden <4 x i32> @float4_to_int4(
 // AMDGCN-SAME: <4 x float> noundef [[X:%.*]]) local_unnamed_addr 
#[[ATTR0:[0-9]+]] {
diff --git a/libclc/test/geometric/cross.cl b/libclc/test/geometric/cross.cl
index 41be4176f76cf..cbf4f28c35b8e 100644
--- a/libclc/test/geometric/cross.cl
+++ b/libclc/test/geometric/cross.cl
@@ -1,7 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang --target=%target -mcpu=%cpu -cl-std=CL3.0 -O2 -emit-llvm -S -o 
- %s | FileCheck %s --check-prefix=%check_prefix
+// RUN: %clang --target=%target -mcpu=%cpu %libclc_lib -cl-std=CL3.0 -O2 
-emit-llvm -S -o - %s | FileCheck %s --check-prefix=%check_prefix
 
 // AMDGCN-LABEL: define hidden <4 x float> @test_float4(
 // AMDGCN-SAME: <4 x float> noundef [[X:%.*]], <4 x float> noundef [[Y:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
diff --git a/libclc/test/integer/add_sat.cl b/libclc/test/integer/add_sat.cl
index 21d17423e3f68..acfadcb2a201b 100644
--- a/libclc/test/integer/add_sat.cl
+++ b/libclc/test/integer/add_sat.cl
@@ -1,7 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang --target=%target -mcpu=%cpu -cl-std=CL3.0 -O2 -emit-llvm -S -o 
- %s | FileCheck %s --check-prefix=%check_prefix
+// RUN: %clang --target=%target -mcpu=%cpu %libclc_lib -cl-std=CL3.0 -O2 
-emit-llvm -S -o - %s | FileCheck %s --check-prefix=%check_prefix
 
 // AMDGCN-LABEL: define hidden noundef signext i8 @test_char(
 // AMDGCN-SAME: i8 noundef signext [[X:%.*]], i8 noundef signext [[Y:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
diff --git a/libclc/test/integer/sub_sat.cl b/libclc/test/integer/sub_sat.cl
index 15096d57d66d7..13fcd35ebb557 100644
--- a/libclc/test/integer/sub_sat.cl
+++ b/libclc/test/integer/sub_sat.cl
@@ -1,7 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang --target=%target -mcpu=%cpu -cl-std=CL3.0 -O2 -emit-llvm -S -o 
- %s | FileCheck %s --check-prefix=%check_prefix
+// RUN: %clang --target=%target -mcpu=%cpu %libclc_lib -cl-std=CL3.0 -O2 
-emit-llvm -S -o - %s | FileCheck %s --check-prefix=%check_prefix
 
 // AMDGCN-LABEL: define hidden noundef signext i8 @test_char(
 // AMDGCN-SAME: i8 noundef signext [[X:%.*]], i8 noundef signext [[Y:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
diff --git a/libclc/test/lit.cfg.py b/libclc/test/lit.cfg.py
index 22715411ea9d6..be5cad7f7494e 100644
--- a/libclc/test/lit.cfg.py
+++ b/libclc/test/lit.cfg.py
@@ -59,11 +59,16 @@ def calculate_arch_features(arch_string):
 
 llvm_config.add_tool_substitutions(["llvm-nm"], config.llvm_tools_dir)
 
+is_standalone = config.libclc_standalone_build.lower() == "true"
+path = os.path.join(config.libclc_library_dir, config.libclc_target, 
"libclc.bc")
+libclc_lib = f"--libclc-lib=:{path}" if is_standalone else ""
+
 config.substitutions.extend(
     [
         ("%library_dir", config.libclc_library_dir),
         ("%target", config.libclc_target),
         ("%cpu", config.libclc_target_cpu),
+        ("%libclc_lib", libclc_lib),
         ("%check_prefix", config.libclc_target_arch.upper()),
     ]
 )
diff --git a/libclc/test/lit.site.cfg.py.in b/libclc/test/lit.site.cfg.py.in
index 3c9acfc0551f0..6b8b5456b2174 100644
--- a/libclc/test/lit.site.cfg.py.in
+++ b/libclc/test/lit.site.cfg.py.in
@@ -6,6 +6,7 @@ config.host_triple = "@LLVM_HOST_TRIPLE@"
 config.llvm_tools_dir = lit_config.substitute(path(r"@LLVM_TOOLS_DIR@"))
 config.libclc_library_dir = 
lit_config.substitute(path(r"@LIBCLC_OUTPUT_LIBRARY_DIR@"))
 config.libclc_obj_root = 
lit_config.substitute(path(r"@CMAKE_CURRENT_BINARY_DIR@"))
+config.libclc_standalone_build = "@LIBCLC_STANDALONE_BUILD@"
 config.libclc_target = "@LIBCLC_TARGET@"
 config.libclc_target_arch = "@LIBCLC_TARGET_ARCH@"
 config.libclc_target_cpu = "@LIBCLC_TARGET_CPU@"
diff --git a/libclc/test/math/cos.cl b/libclc/test/math/cos.cl
index 99d3acc2d714d..d22048d2932f2 100644
--- a/libclc/test/math/cos.cl
+++ b/libclc/test/math/cos.cl
@@ -1,7 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang --target=%target -mcpu=%cpu -cl-std=CL3.0 -O2 -emit-llvm -S -o 
- %s | FileCheck %s --check-prefix=%check_prefix
+// RUN: %clang --target=%target -mcpu=%cpu %libclc_lib -cl-std=CL3.0 -O2 
-emit-llvm -S -o - %s | FileCheck %s --check-prefix=%check_prefix
 
 // AMDGCN-LABEL: define hidden float @test_float(
 // AMDGCN-SAME: float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
diff --git a/libclc/test/math/fabs.cl b/libclc/test/math/fabs.cl
index e512abd80468b..d44750e58ed01 100644
--- a/libclc/test/math/fabs.cl
+++ b/libclc/test/math/fabs.cl
@@ -1,7 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang --target=%target -mcpu=%cpu -cl-std=CL3.0 -O2 -emit-llvm -S -o 
- %s | FileCheck %s --check-prefix=%check_prefix
+// RUN: %clang --target=%target -mcpu=%cpu %libclc_lib -cl-std=CL3.0 -O2 
-emit-llvm -S -o - %s | FileCheck %s --check-prefix=%check_prefix
 
 // AMDGCN-LABEL: define hidden noundef float @test_float(
 // AMDGCN-SAME: float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
diff --git a/libclc/test/math/rsqrt.cl b/libclc/test/math/rsqrt.cl
index 339c93ea67cf1..c9975047e0a0e 100644
--- a/libclc/test/math/rsqrt.cl
+++ b/libclc/test/math/rsqrt.cl
@@ -1,15 +1,15 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang --target=%target -mcpu=%cpu -x cl -cl-std=CL3.0 -O2 -emit-llvm 
-S -o - %s | FileCheck %s --check-prefix=%check_prefix
+// RUN: %clang --target=%target -mcpu=%cpu %libclc_lib -x cl -cl-std=CL3.0 -O2 
-emit-llvm -S -o - %s | FileCheck %s --check-prefix=%check_prefix
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
 // AMDGCN-LABEL: define hidden noundef half @test_half(
 // AMDGCN-SAME: half noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
 // AMDGCN-NEXT:  [[ENTRY:.*:]]
-// AMDGCN-NEXT:    [[TMP0:%.*]] = tail call contract half @llvm.sqrt.f16(half 
[[X]]), !fpmath [[META12:![0-9]+]]
-// AMDGCN-NEXT:    [[TMP1:%.*]] = fdiv contract half 1.000000e+00, [[TMP0]], 
!fpmath [[META13:![0-9]+]]
+// AMDGCN-NEXT:    [[TMP0:%.*]] = tail call contract half @llvm.sqrt.f16(half 
[[X]]), !fpmath [[META13:![0-9]+]]
+// AMDGCN-NEXT:    [[TMP1:%.*]] = fdiv contract half 1.000000e+00, [[TMP0]], 
!fpmath [[META14:![0-9]+]]
 // AMDGCN-NEXT:    ret half [[TMP1]]
 //
 half test_half(half x) {
@@ -19,8 +19,8 @@ half test_half(half x) {
 // AMDGCN-LABEL: define hidden noundef float @test_float(
 // AMDGCN-SAME: float noundef [[X:%.*]]) local_unnamed_addr #[[ATTR0]] {
 // AMDGCN-NEXT:  [[ENTRY:.*:]]
-// AMDGCN-NEXT:    [[TMP0:%.*]] = tail call contract float 
@llvm.sqrt.f32(float [[X]]), !fpmath [[META14:![0-9]+]]
-// AMDGCN-NEXT:    [[TMP1:%.*]] = fdiv contract float 1.000000e+00, [[TMP0]], 
!fpmath [[META15:![0-9]+]]
+// AMDGCN-NEXT:    [[TMP0:%.*]] = tail call contract float 
@llvm.sqrt.f32(float [[X]]), !fpmath [[META15:![0-9]+]]
+// AMDGCN-NEXT:    [[TMP1:%.*]] = fdiv contract float 1.000000e+00, [[TMP0]], 
!fpmath [[META16:![0-9]+]]
 // AMDGCN-NEXT:    ret float [[TMP1]]
 //
 float test_float(float x) {
@@ -38,8 +38,8 @@ double test_double(double x) {
   return rsqrt(x);
 }
 //.
-// AMDGCN: [[META12]] = !{float 1.500000e+00}
-// AMDGCN: [[META13]] = !{float 1.000000e+00}
-// AMDGCN: [[META14]] = !{float 3.000000e+00}
-// AMDGCN: [[META15]] = !{float 2.500000e+00}
+// AMDGCN: [[META13]] = !{float 1.500000e+00}
+// AMDGCN: [[META14]] = !{float 1.000000e+00}
+// AMDGCN: [[META15]] = !{float 3.000000e+00}
+// AMDGCN: [[META16]] = !{float 2.500000e+00}
 //.
diff --git a/libclc/test/misc/as_type.cl b/libclc/test/misc/as_type.cl
index 25f9df2e11137..5f98df07d2a67 100644
--- a/libclc/test/misc/as_type.cl
+++ b/libclc/test/misc/as_type.cl
@@ -1,7 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang --target=%target -mcpu=%cpu -cl-std=CL3.0 -O2 -emit-llvm -S -o 
- %s | FileCheck %s --check-prefix=%check_prefix
+// RUN: %clang --target=%target -mcpu=%cpu %libclc_lib -cl-std=CL3.0 -O2 
-emit-llvm -S -o - %s | FileCheck %s --check-prefix=%check_prefix
 
 // AMDGCN-LABEL: define hidden noundef <4 x i32> @test_float4_as_int4(
 // AMDGCN-SAME: <4 x float> noundef [[X:%.*]]) local_unnamed_addr 
#[[ATTR0:[0-9]+]] {
diff --git a/libclc/test/update_libclc_tests.py 
b/libclc/test/update_libclc_tests.py
index c0519088dd782..d5e43b420b816 100755
--- a/libclc/test/update_libclc_tests.py
+++ b/libclc/test/update_libclc_tests.py
@@ -64,10 +64,11 @@ def replace_in_file(path: Path, triple: str, cpu: str, 
check_prefix: str):
     if cpu:
         content = content.replace(b"%cpu", cpu.encode())
     content = content.replace(b"%check_prefix", check_prefix.encode())
+    content = content.replace(b"%libclc_lib", b"")
     path.write_bytes(content)
 
 
-def revert_in_file(path: Path, triple: str, cpu: str, check_prefix: str):
+def revert_in_file(path: Path, triple: str, cpu: str, check_prefix: str, 
original: bytes):
     # Only revert in the RUN line context, not in generated CHECK lines.
     content = path.read_bytes()
     content = content.replace(f"--target={triple}".encode(), 
b"--target=%target")
@@ -76,6 +77,8 @@ def revert_in_file(path: Path, triple: str, cpu: str, 
check_prefix: str):
     content = content.replace(
         f"--check-prefix={check_prefix}".encode(), 
b"--check-prefix=%check_prefix"
     )
+    if b"%libclc_lib" in original:
+        content = _restore_libclc_lib(content, original)
     path.write_bytes(content)
 
 
@@ -94,7 +97,25 @@ def file_requires_feature(path: Path, feature: str) -> bool:
     return False
 
 
+def _restore_libclc_lib(content: bytes, original: bytes) -> bytes:
+    RUN_MARKERS = (b"// RUN:", b"; RUN:")
+    orig_run_lines = [
+        l for l in original.splitlines(keepends=True)
+        if any(l.lstrip().startswith(m) for m in RUN_MARKERS)
+    ]
+    curr_lines = content.splitlines(keepends=True)
+    curr_run_indices = [
+        i for i, l in enumerate(curr_lines)
+        if any(l.lstrip().startswith(m) for m in RUN_MARKERS)
+    ]
+    result = list(curr_lines)
+    for idx, orig_line in zip(curr_run_indices, orig_run_lines):
+        result[idx] = orig_line
+    return b"".join(result)
+
+
 def process_file(cl_file: Path, triple: str, cpu: str, check_prefix: str) -> 
bool:
+    original = cl_file.read_bytes()
     replace_in_file(cl_file, triple, cpu, check_prefix)
     cmd = [
         sys.executable,
@@ -108,7 +129,7 @@ def process_file(cl_file: Path, triple: str, cpu: str, 
check_prefix: str) -> boo
     ok = result.returncode == 0
     if not ok:
         print(f"  FAILED: {result.stderr.strip()}", file=sys.stderr)
-    revert_in_file(cl_file, triple, cpu, check_prefix)
+    revert_in_file(cl_file, triple, cpu, check_prefix, original)
     return ok
 
 
diff --git a/libclc/test/work-item/get_group_id.cl 
b/libclc/test/work-item/get_group_id.cl
index 1818662c60be1..6afaa3a4a3368 100644
--- a/libclc/test/work-item/get_group_id.cl
+++ b/libclc/test/work-item/get_group_id.cl
@@ -1,7 +1,7 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 6
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang --target=%target -mcpu=%cpu -cl-std=CL3.0 -O2 -emit-llvm -S -o 
- %s | FileCheck %s --check-prefix=%check_prefix
+// RUN: %clang --target=%target -mcpu=%cpu %libclc_lib -cl-std=CL3.0 -O2 
-emit-llvm -S -o - %s | FileCheck %s --check-prefix=%check_prefix
 
 // AMDGCN-LABEL: define hidden range(i64 0, 4294967296) i64 @test(
 // AMDGCN-SAME: ) local_unnamed_addr #[[ATTR0:[0-9]+]] {

>From 69b5ac9c265c06ec872184faa751523dee7b189f Mon Sep 17 00:00:00 2001
From: Wenju He <[email protected]>
Date: Fri, 22 May 2026 12:42:27 +0200
Subject: [PATCH 4/4] update_libclc_tests.py: save RUN line before replace

---
 libclc/test/update_libclc_tests.py | 44 ++++++++++--------------------
 1 file changed, 14 insertions(+), 30 deletions(-)

diff --git a/libclc/test/update_libclc_tests.py 
b/libclc/test/update_libclc_tests.py
index d5e43b420b816..5ad78eed549ff 100755
--- a/libclc/test/update_libclc_tests.py
+++ b/libclc/test/update_libclc_tests.py
@@ -68,18 +68,13 @@ def replace_in_file(path: Path, triple: str, cpu: str, 
check_prefix: str):
     path.write_bytes(content)
 
 
-def revert_in_file(path: Path, triple: str, cpu: str, check_prefix: str, 
original: bytes):
-    # Only revert in the RUN line context, not in generated CHECK lines.
-    content = path.read_bytes()
-    content = content.replace(f"--target={triple}".encode(), 
b"--target=%target")
-    if cpu:
-        content = content.replace(f"-mcpu={cpu}".encode(), b"-mcpu=%cpu")
-    content = content.replace(
-        f"--check-prefix={check_prefix}".encode(), 
b"--check-prefix=%check_prefix"
-    )
-    if b"%libclc_lib" in original:
-        content = _restore_libclc_lib(content, original)
-    path.write_bytes(content)
+def _run_line_indices(content: bytes) -> list:
+    RUN_MARKERS = (b"// RUN:", b"; RUN:")
+    return [
+        i
+        for i, l in enumerate(content.splitlines(keepends=True))
+        if any(l.lstrip().startswith(m) for m in RUN_MARKERS)
+    ]
 
 
 def file_requires_feature(path: Path, feature: str) -> bool:
@@ -97,25 +92,10 @@ def file_requires_feature(path: Path, feature: str) -> bool:
     return False
 
 
-def _restore_libclc_lib(content: bytes, original: bytes) -> bytes:
-    RUN_MARKERS = (b"// RUN:", b"; RUN:")
-    orig_run_lines = [
-        l for l in original.splitlines(keepends=True)
-        if any(l.lstrip().startswith(m) for m in RUN_MARKERS)
-    ]
-    curr_lines = content.splitlines(keepends=True)
-    curr_run_indices = [
-        i for i, l in enumerate(curr_lines)
-        if any(l.lstrip().startswith(m) for m in RUN_MARKERS)
-    ]
-    result = list(curr_lines)
-    for idx, orig_line in zip(curr_run_indices, orig_run_lines):
-        result[idx] = orig_line
-    return b"".join(result)
-
-
 def process_file(cl_file: Path, triple: str, cpu: str, check_prefix: str) -> 
bool:
     original = cl_file.read_bytes()
+    orig_lines = original.splitlines(keepends=True)
+    saved_run = {i: orig_lines[i] for i in _run_line_indices(original)}
     replace_in_file(cl_file, triple, cpu, check_prefix)
     cmd = [
         sys.executable,
@@ -129,7 +109,11 @@ def process_file(cl_file: Path, triple: str, cpu: str, 
check_prefix: str) -> boo
     ok = result.returncode == 0
     if not ok:
         print(f"  FAILED: {result.stderr.strip()}", file=sys.stderr)
-    revert_in_file(cl_file, triple, cpu, check_prefix, original)
+    updated = cl_file.read_bytes()
+    updated_lines = updated.splitlines(keepends=True)
+    for i, line in saved_run.items():
+        updated_lines[i] = line
+    cl_file.write_bytes(b"".join(updated_lines))
     return ok
 
 

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to