Skip to content

Instantly share code, notes, and snippets.

@tenpercent
Created July 30, 2026 00:15
Show Gist options
  • Select an option

  • Save tenpercent/7075fbecc7e9c2cfa2b2c55c1a1ec7ee to your computer and use it in GitHub Desktop.

Select an option

Save tenpercent/7075fbecc7e9c2cfa2b2c55c1a1ec7ee to your computer and use it in GitHub Desktop.
PR #9583: Windows -Wunused-function break — cause, repro, patch
--- a/dnn-providers/hip-kernel-provider/rocke/platform/cpp/core/lower_llvm/core.cpp
+++ b/dnn-providers/hip-kernel-provider/rocke/platform/cpp/core/lower_llvm/core.cpp
@@ -277,6 +277,7 @@
return found;
}
+#ifndef _WIN32 /* POSIX-only: used solely by the dirent scans below */
/* Python runtime_coexistence._version_key, as a comparison: compare the runs of
* digits in each name as an integer sequence so "rocm-7.10" sorts NEWER than
* "rocm-7.2" (a plain strcmp gets this backwards, because '1' < '2'). Returns
@@ -310,6 +311,7 @@
return (va > vb) ? 1 : -1;
}
}
+#endif /* !_WIN32 */
/* Does <libdir>/libamd_comgr.so[.3] exist? Python's _candidate_lib_paths gives
* each discovered libdir the bare .so plus the SONAME-suffixed variants; we
#!/bin/bash
# Minimal reproduction of the HipDNN Windows Superbuild failure:
# a static helper defined outside a _WIN32 guard, used only inside one.
# Needs any C compiler; no ROCm or LLVM required.
d=$(mktemp -d); cd "$d"
cat > broken.c <<'X'
#include <stdlib.h>
static int helper(const char* a, const char* b) { return a && b ? 1 : 0; }
#ifndef _WIN32
int scan(const char* x, const char* y) { return helper(x, y); }
#else
int scan(const char* x, const char* y) { (void)x; (void)y; return 0; }
#endif
X
sed '2d; 3a static int helper(const char* a, const char* b) { return a \&\& b ? 1 : 0; }' broken.c > fixed.c
echo "current structure, compiled as Windows:"
gcc -D_WIN32 -Wunused-function -Werror -c broken.c -o /dev/null 2>&1 | head -3
echo "definition moved inside the guard, as Windows:"
gcc -D_WIN32 -Wunused-function -Werror -c fixed.c -o /dev/null && echo " compiles clean"
echo "same, on POSIX:"
gcc -Wunused-function -Werror -c fixed.c -o /dev/null && echo " compiles clean"
#!/usr/bin/env python3
"""Find any static function defined outside a _WIN32 guard whose every call
site is inside one — i.e. the next -Wunused-function break waiting to happen.
Usage: 15_scan_for_more.py <path-to-core.cpp>
"""
import re, sys
src = open(sys.argv[1]).read().splitlines()
state, depth = [], 0
for line in src:
s = line.strip()
if s.startswith("#ifndef _WIN32") or s.startswith("#ifdef _WIN32"):
depth += 1
elif s.startswith("#endif") and depth:
depth -= 1
state.append(depth > 0)
bad = 0
for i, line in enumerate(src):
m = re.match(r"^static\s+[\w:\*\s]+?\b(\w+)\s*\(", line)
if not m or state[i]:
continue
name = m.group(1)
uses = [(j + 1, state[j]) for j, x in enumerate(src)
if re.search(rf"\b{name}\s*\(", x) and j != i]
if uses and all(guarded for _, guarded in uses):
print(f"{name}: defined :{i+1}, all uses guarded {[u for u, _ in uses]}")
bad += 1
print(f"{bad} issue(s)")

Windows build break in PR #9583 @ 6efd67eb

HipDNN Windows Superbuild fails with:

core.cpp:284:12: error: unused function 'll_rocm_name_newer' [-Werror,-Wunused-function]

Cause. ll_rocm_name_newer is defined at core.cpp:284 outside any guard, but both call sites (:367, :405) are inside #ifndef _WIN32 blocks, alongside the <dirent.h>/opendir code they serve. On Windows the callers compile out and the definition is left unused.

script purpose
13_fix_windows_unused_function.patch the fix — wraps the definition in its own #ifndef _WIN32; applies cleanly with git apply -p1
14_repro_unused_function.sh 7-line reproduction, no ROCm/LLVM needed
15_scan_for_more.py scans core.cpp for the same pattern elsewhere — reports 0 after the patch

Introduced in 6efd67eb; absent from 56006f38, f19a5b09, 5bb9126a.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment