Skip to content

Commit 7aeacae

Browse files
author
Your GitHub Username
committed
fix(ci): parse clang-tidy analyzer warning suffix
Signed-off-by: Your GitHub Username <your_email@example.com>
1 parent 96c3f41 commit 7aeacae

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

‎scripts/lint-mem-gate.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,15 @@
4747
MIN_WHY = 120
4848
MIN_TRIED = 40
4949

50-
FINDING_RE = re.compile(r"^(?P<file>[^:]+):(?P<line>\d+):\d+:\s+(?:error|warning):\s+(?P<msg>.*?)\s*\[(?P<check>[\w.-]+)\]\s*$")
50+
# With WarningsAsErrors enabled, clang-tidy appends the escalation reason to
51+
# analyzer checks, for example:
52+
# [clang-analyzer-core.NullDereference,-warnings-as-errors]
53+
# Keep the check name separate from that suffix so the gate still matches the
54+
# same whitelist key instead of silently dropping the finding.
55+
FINDING_RE = re.compile(
56+
r"^(?P<file>[^:]+):(?P<line>\d+):\d+:\s+(?:error|warning):\s+"
57+
r"(?P<msg>.*?)\s*\[(?P<check>[\w.-]+)(?:,-warnings-as-errors)?\]\s*$"
58+
)
5159

5260

5361
def strip_noise(text):

‎tests/test_lint_mem_gate.sh‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
# Regression contract for clang-tidy's `,-warnings-as-errors` diagnostic suffix.
3+
set -euo pipefail
4+
5+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
6+
FIX="$(mktemp -d "${TMPDIR:-/tmp}/lint-mem-gate.XXXXXX")"
7+
trap 'rm -rf "$FIX"' EXIT
8+
9+
cat > "$FIX/sample.c" <<'EOF'
10+
int sample(int *value) {
11+
return *value;
12+
}
13+
EOF
14+
15+
cat > "$FIX/whitelist.txt" <<EOF
16+
## $FIX/sample.c :: sample :: clang-analyzer-core.NullDereference
17+
segment-sha256: PLACEHOLDER
18+
why: |
19+
The test deliberately models a diagnostic that is suppressed by the fixture whitelist.
20+
This text is long enough to exercise the gate's normal argument validation path.
21+
tried: |
22+
The fixture is intentionally minimal and only verifies diagnostic parsing.
23+
EOF
24+
25+
HASH="$(LINT_MEM_WHITELIST="$FIX/whitelist.txt" python3 "$ROOT/scripts/lint-mem-gate.py" --hash "$FIX/sample.c" sample | awk '/^segment-sha256:/ {print $2}')"
26+
python3 - "$FIX/whitelist.txt" "$HASH" <<'PY'
27+
from pathlib import Path
28+
import sys
29+
30+
path = Path(sys.argv[1])
31+
text = path.read_text(encoding="utf-8").replace("PLACEHOLDER", sys.argv[2])
32+
path.write_text(text, encoding="utf-8")
33+
PY
34+
35+
printf '%s\n' "$FIX/sample.c:2:12: warning: possible null dereference [clang-analyzer-core.NullDereference,-warnings-as-errors]" \
36+
| LINT_MEM_WHITELIST="$FIX/whitelist.txt" python3 "$ROOT/scripts/lint-mem-gate.py" 2> "$FIX/stderr"
37+
38+
grep -q 'memory gate clean (1 argued false positive' "$FIX/stderr"
39+
echo 'lint-mem-gate warning suffix contract passed'

0 commit comments

Comments
 (0)