[llvm] [llvm-lit] Fix `TypeError` string argument expected in lit's internal shell (PR #105925)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 23 22:46:30 PDT 2024


https://github.com/Harini0924 created https://github.com/llvm/llvm-project/pull/105925

This patch addresses an issue encountered when running the BOLT test suite with the lit internal shell using the command: 
```
LIT_USE_INTERNAL_SHELL=1 ninja check-bolt
```
During execution, the following error was observed:
```
File "/usr/local/google/home/harinidonthula/llvm-project/llvm/utils/lit/lit/TestRunner.py", line 416, in executeBuiltinEcho
    stdout.write(encode(maybeUnescape(args[-1])))
TypeError: string argument expected, got 'GlobItem'
```
This error occurs because the `executeBuiltinEcho` function in the lit testing framework expects a string to be passed to `stdout.write`, but it received a `GlobItem` object instead. The `GlobItem` represents an unexpanded glob pattern that needs to be converted to a string before being processed.

This patch adds `str()` to the arguments passed to `stdout.write` in the `executeBuiltinEcho` function. By converting the arguments to strings, including any `GlobItem` objects, we ensure compatibility and prevent the `TypeError` during test execution.

This change is relevant for [[RFC] Enabling the Lit Internal Shell by Default](https://discourse.llvm.org/t/rfc-enabling-the-lit-internal-shell-by-default/80179/3)  
fixes: #102693

>From f5e4c4668005c4e66ba442355bcf4bcc7e161dbb Mon Sep 17 00:00:00 2001
From: Harini <harinidonthula at google.com>
Date: Sat, 24 Aug 2024 05:36:25 +0000
Subject: [PATCH] Fix TypeError in BOLT test

Ensured that arguments passed to `stdout.write` in the `executeBuiltinEcho`
function are properly converted to strings.
---
 llvm/utils/lit/lit/TestRunner.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py
index 2d9af9fbbb3634..625ce009515d5f 100644
--- a/llvm/utils/lit/lit/TestRunner.py
+++ b/llvm/utils/lit/lit/TestRunner.py
@@ -413,7 +413,7 @@ def maybeUnescape(arg):
         for arg in args[:-1]:
             stdout.write(encode(maybeUnescape(arg)))
             stdout.write(encode(" "))
-        stdout.write(encode(maybeUnescape(args[-1])))
+        stdout.write(encode(maybeUnescape(str(args[-1]))))
     if write_newline:
         stdout.write(encode("\n"))
 



More information about the llvm-commits mailing list