[llvm] e0f8898 - Avoid a race condition in opt-viewer/optrecord (#131214)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 2 02:52:45 PDT 2025
Author: Miro HronĨok
Date: 2025-04-02T11:52:41+02:00
New Revision: e0f8898e1d432ab4fdcaf353bf87a1d3cf36491a
URL: https://github.com/llvm/llvm-project/commit/e0f8898e1d432ab4fdcaf353bf87a1d3cf36491a
DIFF: https://github.com/llvm/llvm-project/commit/e0f8898e1d432ab4fdcaf353bf87a1d3cf36491a.diff
LOG: Avoid a race condition in opt-viewer/optrecord (#131214)
See https://bugzilla.redhat.com/2336915
See https://reviews.llvm.org/D41784?id=
See
https://github.com/androm3da/optviewer-demo/issues/4#issuecomment-718787822
Fixes https://github.com/llvm/llvm-project/issues/62403.
The race condition happened when the demangler_proc was being set. The
locking mechanism itself happened too late.
This way, the lock always exists (to avoid a race when creating it) and
is always used when *creating* demangler_proc.
Added:
Modified:
llvm/tools/opt-viewer/optrecord.py
Removed:
################################################################################
diff --git a/llvm/tools/opt-viewer/optrecord.py b/llvm/tools/opt-viewer/optrecord.py
index 9e2fc7cb553b5..8014204a64f45 100644
--- a/llvm/tools/opt-viewer/optrecord.py
+++ b/llvm/tools/opt-viewer/optrecord.py
@@ -64,17 +64,19 @@ class Remark(yaml.YAMLObject):
default_demangler = "c++filt -n"
demangler_proc = None
+ demangler_lock = Lock()
@classmethod
def set_demangler(cls, demangler):
cls.demangler_proc = subprocess.Popen(
demangler.split(), stdin=subprocess.PIPE, stdout=subprocess.PIPE
)
- cls.demangler_lock = Lock()
@classmethod
def demangle(cls, name):
with cls.demangler_lock:
+ if not cls.demangler_proc:
+ cls.set_demangler(cls.default_demangler)
cls.demangler_proc.stdin.write((name + "\n").encode("utf-8"))
cls.demangler_proc.stdin.flush()
return cls.demangler_proc.stdout.readline().rstrip().decode("utf-8")
@@ -323,8 +325,6 @@ def get_remarks(input_file, filter_=None):
def gather_results(filenames, num_jobs, should_print_progress, filter_=None):
if should_print_progress:
print("Reading YAML files...")
- if not Remark.demangler_proc:
- Remark.set_demangler(Remark.default_demangler)
remarks = optpmap.pmap(
get_remarks, filenames, num_jobs, should_print_progress, filter_
)
More information about the llvm-commits
mailing list