[llvm] [DebugCounter] Add support for non-continous ranges. (PR #89470)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 19 15:53:35 PDT 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {darker}-->


:warning: Python code formatter, darker found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
darker --check --diff -r adc11b34b1d7f99b3931f945073a652f0dec5aaf...03e83fbaea12acbe3b26a4ad66a97fbcff8b6412 llvm/utils/bisector/bisector.py
``````````

</details>

<details>
<summary>
View the diff from darker here.
</summary>

``````````diff
--- bisector.py	2024-04-19 22:50:04.000000 +0000
+++ bisector.py	2024-04-19 22:53:13.954649 +0000
@@ -2,109 +2,116 @@
 
 import subprocess
 import sys
 import os
 
-LINKER=os.environ["BISECTOR_LINKER"]
+LINKER = os.environ["BISECTOR_LINKER"]
 
 # The bisector finds guilty translation units so we ignore link steps
 if not "-c" in sys.argv:
-  res = subprocess.run(LINKER.split() + sys.argv[1:])
-  exit(res.returncode)
+    res = subprocess.run(LINKER.split() + sys.argv[1:])
+    exit(res.returncode)
 
-SAFE_COMPILER=os.environ["BISECTOR_SAFE_COMPILER"]
-UNSAFE_COMPILER=os.environ["BISECTOR_UNSAFE_COMPILER"]
+SAFE_COMPILER = os.environ["BISECTOR_SAFE_COMPILER"]
+UNSAFE_COMPILER = os.environ["BISECTOR_UNSAFE_COMPILER"]
 
 # List of bisector commands that will be run
-CMD_LIST=os.environ["BISECTOR_CMD_LIST"]
+CMD_LIST = os.environ["BISECTOR_CMD_LIST"]
 if not os.path.exists(CMD_LIST):
-  os.mknod(CMD_LIST)
+    os.mknod(CMD_LIST)
 
 # List of chunks that should use the unsafe tool
 CHUNKS = os.environ["BISECTOR_CHUNKS"]
 
-verbose=0
+verbose = 0
 if os.environ["BISECTOR_VERBOSE"]:
-  verbose=int(os.environ["BISECTOR_VERBOSE"])
+    verbose = int(os.environ["BISECTOR_VERBOSE"])
+
 
 def log(level=1, *args, **kwargs):
-  if verbose >= level:
-    print(*args, **kwargs)
+    if verbose >= level:
+        print(*args, **kwargs)
+
 
 # The signature is the working directory + the arguments passed to the bisector
-cmd_signature = f"cd {os.getcwd()} && \"" + "\" \"".join(sys.argv) + "\""
+cmd_signature = f'cd {os.getcwd()} && "' + '" "'.join(sys.argv) + '"'
 
 if "BISECTOR_DUMP_CMD" in os.environ:
-  with open(os.environ["BISECTOR_DUMP_CMD"], 'a') as f:
-    f.write(cmd_signature)
+    with open(os.environ["BISECTOR_DUMP_CMD"], "a") as f:
+        f.write(cmd_signature)
+
 
 # Start of the Chunks list parser
 def consume_int():
-  global CHUNKS
-  idx = 0
-  int_str = ''
-  while len(CHUNKS) != 0 and ord(CHUNKS[0]) >= ord('0') and ord(CHUNKS[0]) <= ord('9'):
-    idx += 1
-    int_str += CHUNKS[0]
-    CHUNKS = CHUNKS[1:]
-  return int(int_str)
+    global CHUNKS
+    idx = 0
+    int_str = ""
+    while (
+        len(CHUNKS) != 0 and ord(CHUNKS[0]) >= ord("0") and ord(CHUNKS[0]) <= ord("9")
+    ):
+        idx += 1
+        int_str += CHUNKS[0]
+        CHUNKS = CHUNKS[1:]
+    return int(int_str)
+
 
 def consume_char(C):
-  global CHUNKS
-  if len(CHUNKS) != 0 and CHUNKS[0] == C:
-    CHUNKS = CHUNKS[1:]
-    return True
-  return False
+    global CHUNKS
+    if len(CHUNKS) != 0 and CHUNKS[0] == C:
+        CHUNKS = CHUNKS[1:]
+        return True
+    return False
+
 
 INT_SET = set()
 
-while (1):
-  Start = consume_int()
-  if (consume_char('-')):
-    End = consume_int()
-    INT_SET |= set([I for I in range(Start, End + 1)])
-  else:
-    INT_SET |= {Start}
-  
-  if consume_char(':'):
-    continue
+while 1:
+    Start = consume_int()
+    if consume_char("-"):
+        End = consume_int()
+        INT_SET |= set([I for I in range(Start, End + 1)])
+    else:
+        INT_SET |= {Start}
 
-  if len(CHUNKS) == 0:
-    break
+    if consume_char(":"):
+        continue
+
+    if len(CHUNKS) == 0:
+        break
 # End of the Chunks list parser
 # The result of the chunk list is in INT_SET
 
 args = sys.argv[1:]
 found_signature = False
 should_use_unsafe = False
 
 # Traverse the CMD_LIST to look for the signature
 idx = 0
 with open(CMD_LIST) as file:
-  for line in file:
-    line = line[:-1]
-    if cmd_signature == line:
-      found_signature = True
-      if idx in INT_SET:
-        should_use_unsafe = True
+    for line in file:
+        line = line[:-1]
+        if cmd_signature == line:
+            found_signature = True
+            if idx in INT_SET:
+                should_use_unsafe = True
 
-      # Once we found the command we have nothing else to do
-      break
-    idx += 1
+            # Once we found the command we have nothing else to do
+            break
+        idx += 1
 
 # If we didn't find the signature in the CMD_LIST file we add it to the CMD_LIST
 if not found_signature:
-  if idx in INT_SET:
-    should_use_unsafe = True
-  log(1, f"failed to find \"{cmd_signature}\" inside {CMD_LIST}")
-  with open(CMD_LIST, "a") as file:
-    file.write(cmd_signature)
-    file.write("\n")
+    if idx in INT_SET:
+        should_use_unsafe = True
+    log(1, f'failed to find "{cmd_signature}" inside {CMD_LIST}')
+    with open(CMD_LIST, "a") as file:
+        file.write(cmd_signature)
+        file.write("\n")
 
 if should_use_unsafe:
-  log(1, f"using unsafe for: {cmd_signature}")
-  res = subprocess.run(UNSAFE_COMPILER.split() + args)
-  exit(res.returncode)
+    log(1, f"using unsafe for: {cmd_signature}")
+    res = subprocess.run(UNSAFE_COMPILER.split() + args)
+    exit(res.returncode)
 else:
-  log(1, f"using safe: {cmd_signature}")
-  res = subprocess.run(SAFE_COMPILER.split() + args)
-  exit(res.returncode)
+    log(1, f"using safe: {cmd_signature}")
+    res = subprocess.run(SAFE_COMPILER.split() + args)
+    exit(res.returncode)

``````````

</details>


https://github.com/llvm/llvm-project/pull/89470


More information about the llvm-commits mailing list