[libclc][Test] Don't hard code `clang` path in update_libclc_tests.py (#201806)

In #201773, build folder is `redhat-linux-build` rather than `build`.
Detect clang from PATH. Also add --clang-binary option to specify clang path.

GitOrigin-RevId: 985e49989fa6ac24a1318969f6865bb5407574c6
diff --git a/test/update_libclc_tests.py b/test/update_libclc_tests.py
index 5ad78ee..4eb77cf 100755
--- a/test/update_libclc_tests.py
+++ b/test/update_libclc_tests.py
@@ -19,6 +19,7 @@
 import argparse
 import os
 import re
+import shutil
 import subprocess
 import sys
 from concurrent.futures import ProcessPoolExecutor, as_completed
@@ -51,7 +52,6 @@
 SCRIPT_DIR = Path(__file__).parent
 REPO_ROOT = SCRIPT_DIR.parent.parent
 UPDATE_SCRIPT = REPO_ROOT / "llvm" / "utils" / "update_cc_test_checks.py"
-CLANG = REPO_ROOT / "build" / "bin" / "clang"
 
 
 def find_cl_files(test_dir: Path):
@@ -92,7 +92,9 @@
     return False
 
 
-def process_file(cl_file: Path, triple: str, cpu: str, check_prefix: str) -> bool:
+def process_file(
+    cl_file: Path, triple: str, cpu: str, check_prefix: str, clang: Path
+) -> 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)}
@@ -101,7 +103,7 @@
         sys.executable,
         str(UPDATE_SCRIPT),
         "--clang",
-        str(CLANG),
+        str(clang),
         str(cl_file),
     ]
     print(f"  update: {cl_file.relative_to(REPO_ROOT)}")
@@ -126,8 +128,28 @@
         choices=list(ARCH_TO_TRIPLE.keys()),
         help="Target arch: amdgpu, amdgcn, nvptx64, spirv, spirv64",
     )
+    parser.add_argument(
+        "--clang-binary",
+        default=None,
+        help="The clang binary used to generate the test case (default: clang from PATH)",
+    )
     args = parser.parse_args()
 
+    if args.clang_binary:
+        clang = Path(args.clang_binary)
+        if not clang.is_file():
+            print(f"Error: clang binary not found: {clang}", file=sys.stderr)
+            sys.exit(1)
+    else:
+        clang_in_path = shutil.which("clang")
+        if not clang_in_path:
+            print(
+                "Error: clang not found in PATH; use --clang-binary to specify.",
+                file=sys.stderr,
+            )
+            sys.exit(1)
+        clang = Path(clang_in_path)
+
     arch = args.arch.lower()
     triple = ARCH_TO_TRIPLE[arch]
     cpu = ARCH_TO_CPU[arch]
@@ -147,7 +169,7 @@
         return
 
     print(
-        f"arch={arch}  triple={triple}  cpu={cpu}  check_prefix={check_prefix}  requires={requires_feature}"
+        f"arch={arch}  triple={triple}  cpu={cpu}  check_prefix={check_prefix}  requires={requires_feature}  clang={clang}"
     )
     print(f"Processing {len(target_files)} file(s)...")
 
@@ -155,7 +177,7 @@
     num_workers = max(1, os.cpu_count() // 2)
     with ProcessPoolExecutor(max_workers=num_workers) as executor:
         futures = {
-            executor.submit(process_file, f, triple, cpu, check_prefix): f
+            executor.submit(process_file, f, triple, cpu, check_prefix, clang): f
             for f in target_files
         }
         for future in as_completed(futures):