[llvm] [ci] Add ids workflow for checking llvm apis have been annotated with LLVM_ABI (PR #172673)
Fabrice de Gans via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 12 07:28:58 PST 2026
https://github.com/Steelskin updated https://github.com/llvm/llvm-project/pull/172673
>From 39e6d40a9b8da3ee633bad704f8b192133098570 Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <fabrice at thebrowser.company>
Date: Wed, 17 Dec 2025 15:46:52 +0100
Subject: [PATCH 1/7] [ci] Add ids workflow for checking llvm apis have been
annotated with LLVM_ABI
This PR adds a workflow which checks that llvm apis have been annotated with LLVM_ABI.
---
.github/workflows/ids-check.yml | 113 ++++++++++++++++++++++++++++++++
llvm/include/llvm/ADT/APSInt.h | 4 +-
2 files changed, 115 insertions(+), 2 deletions(-)
create mode 100644 .github/workflows/ids-check.yml
diff --git a/.github/workflows/ids-check.yml b/.github/workflows/ids-check.yml
new file mode 100644
index 0000000000000..dac076d0a9e7c
--- /dev/null
+++ b/.github/workflows/ids-check.yml
@@ -0,0 +1,113 @@
+name: ids-check
+on:
+ pull_request:
+ types:
+ - opened
+ - synchronize
+ - reopened
+ - closed
+ push:
+ branches:
+ - 'main'
+ - 'release/**'
+
+permissions:
+ contents: read
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+
+jobs:
+ build:
+ if: github.repository_owner == 'llvm'
+ name: ids-check
+ runs-on: ubuntu-24.04
+
+ steps:
+ - uses: actions/checkout at 11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
+ with:
+ repository: compnerd/ids
+ path: ${{ github.workspace }}/ids
+ fetch-depth: 0
+
+ - uses: actions/checkout at 11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
+ with:
+ path: ${{ github.workspace }}/llvm-project
+ fetch-depth: 2
+
+ - name: Compute base ref
+ id: base_ref
+ run: |
+ if [ "${{ github.event_name }}" == "pull_request" ]; then
+ git -C ${{ github.workspace }}/llvm-project fetch origin ${{ github.base_ref }}
+ echo "base_ref=origin/${{ github.base_ref }}" >> $GITHUB_OUTPUT
+ else
+ echo "base_ref=HEAD~1" >> $GITHUB_OUTPUT
+ fi
+
+ - name: Install dependencies
+ run: |
+ sudo apt install -y clang-19 ninja-build libclang-19-dev
+ pip install lit
+
+ - name: Configure and build minimal LLVM for use by ids
+ run: |
+ cmake -B ${{ github.workspace }}/llvm-project/build/ \
+ -S ${{ github.workspace }}/llvm-project/llvm/ \
+ -D CMAKE_BUILD_TYPE=Release \
+ -D CMAKE_C_COMPILER=clang \
+ -D CMAKE_CXX_COMPILER=clang++ \
+ -D LLVM_ENABLE_PROJECTS=clang \
+ -D LLVM_TARGETS_TO_BUILD="host" \
+ -D CMAKE_EXPORT_COMPILE_COMMANDS=ON \
+ -G Ninja
+ cd ${{ github.workspace }}/llvm-project/build/
+ ninja -t targets all | grep "CommonTableGen: phony$" | grep -v "/" | sed 's/:.*//'
+
+ - name: Configure ids
+ run: |
+ cmake -B ${{ github.workspace }}/ids/build/ \
+ -S ${{ github.workspace }}/ids/ \
+ -D CMAKE_BUILD_TYPE=Release \
+ -D CMAKE_C_COMPILER=clang \
+ -D CMAKE_CXX_COMPILER=clang++ \
+ -D CMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld \
+ -D LLVM_DIR=/usr/lib/llvm-19/lib/cmake/llvm/ \
+ -D Clang_DIR=/usr/lib/llvm-19/lib/cmake/clang/ \
+ -D FILECHECK_EXECUTABLE=$(which FileCheck-19) \
+ -D LIT_EXECUTABLE=$(which lit)
+
+ - name: Build ids
+ run: |
+ cmake --build ${{ github.workspace }}/ids/build \
+ --config Release \
+ --parallel $(nproc --all)
+
+ - name: Run ids over compilation database
+ run: |
+ cd ${{ github.workspace }}/llvm-project
+ export H_OR_CPP_FILES_CHANGED_LAST_COMMIT=$(git diff --name-only ${{ steps.base_ref.outputs.base_ref }} HEAD -- 'llvm/include/llvm/**/*.h' ':!llvm/include/llvm/Debuginfod/' ':!llvm/include/llvm/Demangle/' )
+ if [ ! -z "${H_OR_CPP_FILES_CHANGED_LAST_COMMIT}" ]; then
+ for file in $H_OR_CPP_FILES_CHANGED_LAST_COMMIT; do
+ ${{ github.workspace }}/ids/build/bin/idt -p ${{ github.workspace }}/llvm-project/build/compile_commands.json --apply-fixits --inplace --export-macro=LLVM_ABI --include-header="llvm/include/llvm/Support/Compiler.h" --extra-arg="-DLLVM_ABI=__attribute__((visibility(\"default\")))" --extra-arg="-Wno-macro-redefined" $file
+ done
+ fi
+ export H_OR_CPP_FILES_CHANGED_LAST_COMMIT=$(git diff --name-only ${{ steps.base_ref.outputs.base_ref }} HEAD -- 'llvm/include/llvm-c/**/*.h' )
+ if [ ! -z "${H_OR_CPP_FILES_CHANGED_LAST_COMMIT}" ]; then
+ for file in $H_OR_CPP_FILES_CHANGED_LAST_COMMIT; do
+ ${{ github.workspace }}/ids/build/bin/idt -p ${{ github.workspace }}/llvm-project/build/compile_commands.json --apply-fixits --inplace --export-macro=LLVM_C_ABI --include-header="llvm/include/llvm-c/Visibility.h" --extra-arg="-DLLVM_C_ABI=__attribute__((visibility(\"default\")))" --extra-arg="-Wno-macro-redefined" $file
+ done
+ fi
+ export H_OR_CPP_FILES_CHANGED_LAST_COMMIT=$(git diff --name-only ${{ steps.base_ref.outputs.base_ref }} HEAD -- 'llvm/include/llvm/Demangle/**/*.h' )
+ if [ ! -z "${H_OR_CPP_FILES_CHANGED_LAST_COMMIT}" ]; then
+ for file in $H_OR_CPP_FILES_CHANGED_LAST_COMMIT; do
+ ${{ github.workspace }}/ids/build/bin/idt -p ${{ github.workspace }}/llvm-project/build/compile_commands.json --apply-fixits --inplace --export-macro=DEMANGLE_ABI --include-header="llvm/Demangle/Visibility.h" --extra-arg="-DEMANGLE_ABI=__attribute__((visibility(\"default\")))" --extra-arg="-Wno-macro-redefined" $file
+ done
+ fi
+ git diff --quiet
+ if [ $? -ne 0 ]; then
+ echo "Apply the following diff to fix the LLVM_ABI annotations"
+ git diff
+ exit 1
+ fi
diff --git a/llvm/include/llvm/ADT/APSInt.h b/llvm/include/llvm/ADT/APSInt.h
index 88a7a6e71c817..a7201cdcb7088 100644
--- a/llvm/include/llvm/ADT/APSInt.h
+++ b/llvm/include/llvm/ADT/APSInt.h
@@ -42,7 +42,7 @@ class [[nodiscard]] APSInt : public APInt {
/// constructed APSInt is determined automatically.
///
/// \param Str the string to be interpreted.
- LLVM_ABI explicit APSInt(StringRef Str);
+ explicit APSInt(StringRef Str);
/// Determine sign of this APSInt.
///
@@ -352,7 +352,7 @@ class [[nodiscard]] APSInt : public APInt {
/// Used to insert APSInt objects, or objects that contain APSInt objects,
/// into FoldingSets.
- LLVM_ABI void Profile(FoldingSetNodeID &ID) const;
+ void Profile(FoldingSetNodeID &ID) const;
};
inline bool operator==(int64_t V1, const APSInt &V2) { return V2 == V1; }
>From 5313f7c4283f517449c662aaf60566b0d25bf2d0 Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <fabrice at thebrowser.company>
Date: Thu, 18 Dec 2025 18:38:10 +0100
Subject: [PATCH 2/7] Use specific SHA for the ids repo
---
.github/workflows/ids-check.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/.github/workflows/ids-check.yml b/.github/workflows/ids-check.yml
index dac076d0a9e7c..94f832a46b607 100644
--- a/.github/workflows/ids-check.yml
+++ b/.github/workflows/ids-check.yml
@@ -29,6 +29,7 @@ jobs:
with:
repository: compnerd/ids
path: ${{ github.workspace }}/ids
+ ref: b3bf35dd13d7ff244a6a6d106fe58d0eedb5743e # main
fetch-depth: 0
- uses: actions/checkout at 11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
>From 07e3519bd3cdac5620218e415a3b9e1aace2b811 Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <fabrice at thebrowser.company>
Date: Fri, 19 Dec 2025 11:06:38 +0100
Subject: [PATCH 3/7] Revert test header changes
---
llvm/include/llvm/ADT/APSInt.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/include/llvm/ADT/APSInt.h b/llvm/include/llvm/ADT/APSInt.h
index a7201cdcb7088..88a7a6e71c817 100644
--- a/llvm/include/llvm/ADT/APSInt.h
+++ b/llvm/include/llvm/ADT/APSInt.h
@@ -42,7 +42,7 @@ class [[nodiscard]] APSInt : public APInt {
/// constructed APSInt is determined automatically.
///
/// \param Str the string to be interpreted.
- explicit APSInt(StringRef Str);
+ LLVM_ABI explicit APSInt(StringRef Str);
/// Determine sign of this APSInt.
///
@@ -352,7 +352,7 @@ class [[nodiscard]] APSInt : public APInt {
/// Used to insert APSInt objects, or objects that contain APSInt objects,
/// into FoldingSets.
- void Profile(FoldingSetNodeID &ID) const;
+ LLVM_ABI void Profile(FoldingSetNodeID &ID) const;
};
inline bool operator==(int64_t V1, const APSInt &V2) { return V2 == V1; }
>From 4e0503436cfc9c160b0936fed88e168fc04f9a6d Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <fabrice at thebrowser.company>
Date: Tue, 23 Dec 2025 11:08:39 +0100
Subject: [PATCH 4/7] Switch to a reusable python script
---
.github/workflows/ids-check.yml | 170 ++++++------
llvm/utils/git/ids-check-helper.py | 414 +++++++++++++++++++++++++++++
2 files changed, 497 insertions(+), 87 deletions(-)
create mode 100755 llvm/utils/git/ids-check-helper.py
diff --git a/.github/workflows/ids-check.yml b/.github/workflows/ids-check.yml
index 94f832a46b607..ada90c6863551 100644
--- a/.github/workflows/ids-check.yml
+++ b/.github/workflows/ids-check.yml
@@ -1,11 +1,9 @@
-name: ids-check
+name: "Check LLVM ABI annotations"
on:
pull_request:
- types:
- - opened
- - synchronize
- - reopened
- - closed
+ branches:
+ - main
+ - 'users/**'
push:
branches:
- 'main'
@@ -21,94 +19,92 @@ concurrency:
jobs:
build:
if: github.repository_owner == 'llvm'
- name: ids-check
+ name: Check LLVM_ABI annotations with ids
runs-on: ubuntu-24.04
+ timeout-minutes: 10
steps:
- - uses: actions/checkout at 11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- with:
- repository: compnerd/ids
- path: ${{ github.workspace }}/ids
- ref: b3bf35dd13d7ff244a6a6d106fe58d0eedb5743e # main
- fetch-depth: 0
+ # TODO: Use an image with a prebuilt idt.
+ - uses: actions/checkout at 8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4.2.2
+ with:
+ repository: compnerd/ids
+ path: ${{ github.workspace }}/ids
+ ref: b3bf35dd13d7ff244a6a6d106fe58d0eedb5743e # main
+
+ - uses: actions/checkout at 8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4.2.2
+ with:
+ path: ${{ github.workspace }}/llvm-project
+ fetch-depth: 2
- - uses: actions/checkout at 11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- with:
- path: ${{ github.workspace }}/llvm-project
- fetch-depth: 2
+ - name: Get changed files
+ id: changed-files
+ uses: tj-actions/changed-files at 24d32ffd492484c1d75e0c0b894501ddb9d30d62 # v47.0.0
+ with:
+ separator: ","
+ skip_initial_fetch: true
+ base_sha: 'HEAD~1'
+ sha: 'HEAD'
- - name: Compute base ref
- id: base_ref
- run: |
- if [ "${{ github.event_name }}" == "pull_request" ]; then
- git -C ${{ github.workspace }}/llvm-project fetch origin ${{ github.base_ref }}
- echo "base_ref=origin/${{ github.base_ref }}" >> $GITHUB_OUTPUT
- else
- echo "base_ref=HEAD~1" >> $GITHUB_OUTPUT
- fi
+ # TODO: Use an image with a prebuilt idt.
+ - name: Install dependencies
+ run: |
+ sudo apt install -y clang-19 ninja-build libclang-19-dev
+ pip install lit PyGithub
- - name: Install dependencies
- run: |
- sudo apt install -y clang-19 ninja-build libclang-19-dev
- pip install lit
+ - name: Configure and build minimal LLVM for use by ids
+ run: |
+ cmake -B ${{ github.workspace }}/llvm-project/build/ \
+ -S ${{ github.workspace }}/llvm-project/llvm/ \
+ -D CMAKE_BUILD_TYPE=Release \
+ -D CMAKE_C_COMPILER=clang \
+ -D CMAKE_CXX_COMPILER=clang++ \
+ -D LLVM_ENABLE_PROJECTS=clang \
+ -D LLVM_TARGETS_TO_BUILD="host" \
+ -D CMAKE_EXPORT_COMPILE_COMMANDS=ON \
+ -G Ninja
+ cd ${{ github.workspace }}/llvm-project/build/
+ ninja -t targets all | grep "CommonTableGen: phony$" | grep -v "/" | sed 's/:.*//'
- - name: Configure and build minimal LLVM for use by ids
- run: |
- cmake -B ${{ github.workspace }}/llvm-project/build/ \
- -S ${{ github.workspace }}/llvm-project/llvm/ \
- -D CMAKE_BUILD_TYPE=Release \
- -D CMAKE_C_COMPILER=clang \
- -D CMAKE_CXX_COMPILER=clang++ \
- -D LLVM_ENABLE_PROJECTS=clang \
- -D LLVM_TARGETS_TO_BUILD="host" \
- -D CMAKE_EXPORT_COMPILE_COMMANDS=ON \
- -G Ninja
- cd ${{ github.workspace }}/llvm-project/build/
- ninja -t targets all | grep "CommonTableGen: phony$" | grep -v "/" | sed 's/:.*//'
+ # TODO: Use an image with a prebuilt idt.
+ - name: Configure ids
+ run: |
+ cmake -B ${{ github.workspace }}/ids/build/ \
+ -S ${{ github.workspace }}/ids/ \
+ -D CMAKE_BUILD_TYPE=Release \
+ -D CMAKE_C_COMPILER=clang \
+ -D CMAKE_CXX_COMPILER=clang++ \
+ -D CMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld \
+ -D LLVM_DIR=/usr/lib/llvm-19/lib/cmake/llvm/ \
+ -D Clang_DIR=/usr/lib/llvm-19/lib/cmake/clang/ \
+ -D FILECHECK_EXECUTABLE=$(which FileCheck-19) \
+ -D LIT_EXECUTABLE=$(which lit) \
+ -G Ninja
- - name: Configure ids
- run: |
- cmake -B ${{ github.workspace }}/ids/build/ \
- -S ${{ github.workspace }}/ids/ \
- -D CMAKE_BUILD_TYPE=Release \
- -D CMAKE_C_COMPILER=clang \
- -D CMAKE_CXX_COMPILER=clang++ \
- -D CMAKE_EXE_LINKER_FLAGS=-fuse-ld=lld \
- -D LLVM_DIR=/usr/lib/llvm-19/lib/cmake/llvm/ \
- -D Clang_DIR=/usr/lib/llvm-19/lib/cmake/clang/ \
- -D FILECHECK_EXECUTABLE=$(which FileCheck-19) \
- -D LIT_EXECUTABLE=$(which lit)
+ # TODO: Use an image with a prebuilt idt.
+ - name: Build ids
+ run: |
+ ninja -C ${{ github.workspace }}/ids/build/ all
- - name: Build ids
- run: |
- cmake --build ${{ github.workspace }}/ids/build \
- --config Release \
- --parallel $(nproc --all)
+ - name: Run ids check
+ env:
+ GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
+ CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
+ working-directory: ${{ github.workspace }}/llvm-project
+ run: |
+ echo "[]" > comments &&
+ python llvm/utils/git/ids-check-helper.py \
+ --token ${{ secrets.GITHUB_TOKEN }} \
+ --issue-number $GITHUB_PR_NUMBER \
+ --idt-path ${{ github.workspace }}/ids/build/bin/idt \
+ --compile-commands ${{ github.workspace }}/llvm-project/build/compile_commands.json \
+ --start-rev HEAD~1 \
+ --end-rev HEAD \
+ --changed-files "$CHANGED_FILES"
- - name: Run ids over compilation database
- run: |
- cd ${{ github.workspace }}/llvm-project
- export H_OR_CPP_FILES_CHANGED_LAST_COMMIT=$(git diff --name-only ${{ steps.base_ref.outputs.base_ref }} HEAD -- 'llvm/include/llvm/**/*.h' ':!llvm/include/llvm/Debuginfod/' ':!llvm/include/llvm/Demangle/' )
- if [ ! -z "${H_OR_CPP_FILES_CHANGED_LAST_COMMIT}" ]; then
- for file in $H_OR_CPP_FILES_CHANGED_LAST_COMMIT; do
- ${{ github.workspace }}/ids/build/bin/idt -p ${{ github.workspace }}/llvm-project/build/compile_commands.json --apply-fixits --inplace --export-macro=LLVM_ABI --include-header="llvm/include/llvm/Support/Compiler.h" --extra-arg="-DLLVM_ABI=__attribute__((visibility(\"default\")))" --extra-arg="-Wno-macro-redefined" $file
- done
- fi
- export H_OR_CPP_FILES_CHANGED_LAST_COMMIT=$(git diff --name-only ${{ steps.base_ref.outputs.base_ref }} HEAD -- 'llvm/include/llvm-c/**/*.h' )
- if [ ! -z "${H_OR_CPP_FILES_CHANGED_LAST_COMMIT}" ]; then
- for file in $H_OR_CPP_FILES_CHANGED_LAST_COMMIT; do
- ${{ github.workspace }}/ids/build/bin/idt -p ${{ github.workspace }}/llvm-project/build/compile_commands.json --apply-fixits --inplace --export-macro=LLVM_C_ABI --include-header="llvm/include/llvm-c/Visibility.h" --extra-arg="-DLLVM_C_ABI=__attribute__((visibility(\"default\")))" --extra-arg="-Wno-macro-redefined" $file
- done
- fi
- export H_OR_CPP_FILES_CHANGED_LAST_COMMIT=$(git diff --name-only ${{ steps.base_ref.outputs.base_ref }} HEAD -- 'llvm/include/llvm/Demangle/**/*.h' )
- if [ ! -z "${H_OR_CPP_FILES_CHANGED_LAST_COMMIT}" ]; then
- for file in $H_OR_CPP_FILES_CHANGED_LAST_COMMIT; do
- ${{ github.workspace }}/ids/build/bin/idt -p ${{ github.workspace }}/llvm-project/build/compile_commands.json --apply-fixits --inplace --export-macro=DEMANGLE_ABI --include-header="llvm/Demangle/Visibility.h" --extra-arg="-DEMANGLE_ABI=__attribute__((visibility(\"default\")))" --extra-arg="-Wno-macro-redefined" $file
- done
- fi
- git diff --quiet
- if [ $? -ne 0 ]; then
- echo "Apply the following diff to fix the LLVM_ABI annotations"
- git diff
- exit 1
- fi
+ - name: Upload results
+ uses: actions/upload-artifact at 330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
+ if: always()
+ with:
+ name: workflow-args
+ path: |
+ llvm-project/comments
diff --git a/llvm/utils/git/ids-check-helper.py b/llvm/utils/git/ids-check-helper.py
new file mode 100755
index 0000000000000..3b731733d2811
--- /dev/null
+++ b/llvm/utils/git/ids-check-helper.py
@@ -0,0 +1,414 @@
+#!/usr/bin/env python3
+#
+# ====- ids-check-helper, runs ids-check from the ci or in a hook --*- python -*--==#
+#
+# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+# See https://llvm.org/LICENSE.txt for license information.
+# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+#
+# ==--------------------------------------------------------------------------------------==#
+
+import argparse
+import os
+import subprocess
+import sys
+from typing import List, Optional
+
+"""
+This script is run by GitHub actions to ensure that the code in PRs properly
+labels LLVM APIs with `LLVM_ABI` so as not to break the LLVM DLL build. It can
+also be installed as a pre-commit git hook to check ABI annotations before
+submitting. The canonical source of this script is in the LLVM source tree
+under llvm/utils/git.
+
+This script uses the idt (Interface Diff Tool) to check for missing LLVM_ABI,
+LLVM_C_ABI, and DEMANGLE_ABI annotations in header files.
+
+You can install this script as a git hook by symlinking it to the .git/hooks
+directory:
+
+ln -s $(pwd)/llvm/utils/git/ids-check-helper.py .git/hooks/pre-commit
+
+You can control the exact path to idt and compile_commands.json with the
+following environment variables: $IDT_PATH and $COMPILE_COMMANDS_PATH.
+"""
+
+
+class IdsCheckArgs:
+ start_rev: str = ""
+ end_rev: str = ""
+ changed_files: List[str] = []
+ idt_path: str = ""
+ compile_commands: str = ""
+ repo: str = ""
+ token: str = ""
+ issue_number: int = 0
+ verbose: bool = True
+
+ def __init__(self, args: argparse.Namespace) -> None:
+ self.start_rev = args.start_rev
+ self.end_rev = args.end_rev
+ self.changed_files = args.changed_files
+ self.idt_path = args.idt_path
+ self.compile_commands = args.compile_commands
+ self.repo = getattr(args, "repo", "")
+ self.token = getattr(args, "token", "")
+ self.issue_number = getattr(args, "issue_number", 0)
+ self.verbose = getattr(args, "verbose", True)
+
+
+class IdsChecker:
+ """
+ Checker for LLVM ABI annotations using the idt tool.
+ """
+
+ COMMENT_TAG = "<!--LLVM IDS CHECK COMMENT-->"
+ name = "ids-check"
+ friendly_name = "LLVM ABI annotation checker"
+ comment: dict = {}
+
+ # Macro definition used for all export macros
+ MACRO_DEFINITION = '__attribute__((visibility("default")))'
+
+ @property
+ def comment_tag(self) -> str:
+ return self.COMMENT_TAG
+
+ @property
+ def instructions(self) -> str:
+ # Provide basic usage instructions
+ return f"""git diff origin/main HEAD -- 'llvm/include/llvm/**/*.h' 'llvm/include/llvm-c/**/*.h' 'llvm/include/llvm/Demangle/**/*.h'
+Then run idt on the changed files with appropriate --export-macro and --include-header flags."""
+
+ def pr_comment_text_for_diff(self, diff: str) -> str:
+ return f"""
+:warning: {self.friendly_name}, {self.name} found issues in your code. :warning:
+
+<details>
+<summary>
+You can test this locally with the following command:
+</summary>
+
+``````````bash
+{self.instructions}
+``````````
+
+:warning:
+The reproduction instructions above might return results for more than one PR
+in a stack if you are using a stacked PR workflow. You can limit the results by
+changing `origin/main` to the base branch/commit you want to compare against.
+:warning:
+
+</details>
+
+<details>
+<summary>
+View the diff from {self.name} here.
+</summary>
+
+``````````diff
+{diff}
+``````````
+
+</details>
+"""
+
+ def update_pr(
+ self, comment_text: str, args: IdsCheckArgs, create_new: bool
+ ) -> None:
+ import github
+
+ repo = github.Github(auth=github.Auth.Token(args.token)).get_repo(args.repo)
+ pr = repo.get_issue(args.issue_number).as_pull_request()
+
+ comment_text = self.comment_tag + "\n\n" + comment_text
+
+ existing_comment = None
+ for comment in pr.as_issue().get_comments():
+ if self.comment_tag in comment.body:
+ existing_comment = comment
+ break
+
+ if existing_comment:
+ self.comment = {"body": comment_text, "id": existing_comment.id}
+ elif create_new:
+ self.comment = {"body": comment_text}
+
+ # Define the file categories and their corresponding configurations
+ FILE_CATEGORIES = [
+ {
+ "name": "LLVM headers",
+ "patterns": ["llvm/include/llvm/**/*.h"],
+ "excludes": [
+ "llvm/include/llvm/Debuginfod/",
+ "llvm/include/llvm/Demangle/",
+ ],
+ "export_macro": "LLVM_ABI",
+ "include_header": "llvm/include/llvm/Support/Compiler.h",
+ },
+ {
+ "name": "LLVM-C headers",
+ "patterns": ["llvm/include/llvm-c/**/*.h"],
+ "excludes": [],
+ "export_macro": "LLVM_C_ABI",
+ "include_header": "llvm/include/llvm-c/Visibility.h",
+ },
+ {
+ "name": "LLVM Demangle headers",
+ "patterns": ["llvm/include/llvm/Demangle/**/*.h"],
+ "excludes": [],
+ "export_macro": "DEMANGLE_ABI",
+ "include_header": "llvm/Demangle/Visibility.h",
+ },
+ ]
+
+ def filter_files_for_category(
+ self, changed_files: List[str], category: dict
+ ) -> List[str]:
+ """Filter changed files based on category patterns and excludes."""
+ filtered = []
+ for path in changed_files:
+ # Check if file matches any pattern
+ matches_pattern = False
+ for pattern in category["patterns"]:
+ # Simple pattern matching for /**/*.h style patterns
+ pattern_prefix = pattern.replace("/**/*.h", "")
+ if path.startswith(pattern_prefix) and path.endswith(".h"):
+ matches_pattern = True
+ break
+
+ if not matches_pattern:
+ continue
+
+ # Check if file should be excluded
+ excluded = False
+ for exclude in category["excludes"]:
+ if path.startswith(exclude):
+ excluded = True
+ break
+
+ if not excluded:
+ filtered.append(path)
+
+ return filtered
+
+ def run_idt_on_files(
+ self,
+ files: List[str],
+ category: dict,
+ args: IdsCheckArgs,
+ idt_path: str,
+ compile_commands: str,
+ ) -> bool:
+ """Run idt tool on the given files with category-specific configuration."""
+ if not files:
+ return True
+
+ if args.verbose:
+ print(
+ f"Running idt on {len(files)} {category['name']} file(s)...",
+ file=sys.stderr,
+ )
+
+ for file in files:
+ cmd = [
+ idt_path,
+ "-p",
+ compile_commands,
+ "--apply-fixits",
+ "--inplace",
+ f"--export-macro={category['export_macro']}",
+ f"--include-header={category['include_header']}",
+ f"--extra-arg=-D{category['export_macro']}={self.MACRO_DEFINITION}",
+ "--extra-arg=-Wno-macro-redefined",
+ file,
+ ]
+
+ if args.verbose:
+ print(f"Running: {' '.join(cmd)}", file=sys.stderr)
+
+ subprocess.run(cmd)
+
+ return True
+
+ def get_changed_files(self, args: IdsCheckArgs) -> List[str]:
+ """Get list of changed files between revisions."""
+ if args.changed_files:
+ return args.changed_files
+
+ cmd = ["git", "diff", "--name-only", args.start_rev, args.end_rev]
+ if args.verbose:
+ print(f"Running: {' '.join(cmd)}", file=sys.stderr)
+
+ proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ if proc.returncode != 0:
+ print("Error: Failed to get changed files", file=sys.stderr)
+ sys.stderr.write(proc.stderr.decode("utf-8"))
+ return []
+
+ files = proc.stdout.decode("utf-8").strip().split("\n")
+ return [f for f in files if f]
+
+ def check_for_diff(self) -> Optional[str]:
+ """Check if there are any uncommitted changes after running idt."""
+ cmd = ["git", "diff"]
+ proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+ diff = proc.stdout.decode("utf-8")
+ if diff:
+ return diff
+ return None
+
+ def run(self, args: IdsCheckArgs) -> int:
+ """Main entry point for running ids check."""
+ # Resolve idt path: prefer command line arg, then env var
+ idt_path = args.idt_path or os.environ.get("IDT_PATH")
+ if not idt_path:
+ print(
+ "Error: idt path not specified. Use --idt-path argument or set IDT_PATH environment variable",
+ file=sys.stderr,
+ )
+ return 1
+
+ if not os.path.exists(idt_path):
+ print(f"Error: idt tool not found at {idt_path}", file=sys.stderr)
+ return 1
+
+ # Resolve compile_commands path: prefer command line arg, then env var
+ compile_commands = args.compile_commands or os.environ.get(
+ "COMPILE_COMMANDS_PATH"
+ )
+ if not compile_commands:
+ print(
+ "Error: compile_commands.json path not specified. Use --compile-commands argument or set COMPILE_COMMANDS_PATH environment variable",
+ file=sys.stderr,
+ )
+ return 1
+
+ if not os.path.exists(compile_commands):
+ print(
+ f"Error: compile_commands.json not found at {compile_commands}",
+ file=sys.stderr,
+ )
+ return 1
+
+ # Get changed files
+ changed_files = self.get_changed_files(args)
+ if not changed_files:
+ if args.verbose:
+ print("No files changed, skipping ids check", file=sys.stderr)
+ return 0
+
+ # Process each category
+ any_processed = False
+ for category in self.FILE_CATEGORIES:
+ filtered_files = self.filter_files_for_category(changed_files, category)
+ if filtered_files:
+ any_processed = True
+ if not self.run_idt_on_files(
+ filtered_files, category, args, idt_path, compile_commands
+ ):
+ return 1
+
+ if not any_processed:
+ if args.verbose:
+ print(
+ "No relevant header files changed, skipping ids check",
+ file=sys.stderr,
+ )
+ return 0
+
+ # Check for differences
+ diff = self.check_for_diff()
+ should_update_gh = args.token is not None and args.repo is not None
+
+ if diff:
+ if should_update_gh:
+ comment_text = self.pr_comment_text_for_diff(diff)
+ self.update_pr(comment_text, args, create_new=True)
+ else:
+ print(
+ "\nError: idt found missing LLVM_ABI annotations", file=sys.stderr
+ )
+ print(
+ "Apply the following diff to fix the LLVM_ABI annotations:\n",
+ file=sys.stderr,
+ )
+ print(diff)
+ return 1
+ else:
+ if should_update_gh:
+ comment_text = (
+ ":white_check_mark: With the latest revision "
+ f"this PR passed the {self.friendly_name}."
+ )
+ self.update_pr(comment_text, args, create_new=False)
+ if args.verbose:
+ print("All files pass ids check", file=sys.stderr)
+ return 0
+
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(
+ description="Check LLVM ABI annotations in header files"
+ )
+ parser.add_argument("--token", type=str, help="GitHub authentication token")
+ parser.add_argument(
+ "--repo",
+ type=str,
+ default=os.getenv("GITHUB_REPOSITORY", "llvm/llvm-project"),
+ help="The GitHub repository that we are working with in the form of <owner>/<repo> (e.g. llvm/llvm-project)",
+ )
+ parser.add_argument("--issue-number", type=int, help="GitHub issue/PR number")
+ parser.add_argument(
+ "--start-rev",
+ type=str,
+ required=True,
+ help="Compute changes from this revision",
+ )
+ parser.add_argument(
+ "--end-rev",
+ type=str,
+ required=True,
+ help="Compute changes to this revision",
+ )
+ parser.add_argument(
+ "--changed-files",
+ type=str,
+ help="Comma separated list of files that have been changed",
+ )
+ parser.add_argument(
+ "--idt-path",
+ type=str,
+ help="Path to the idt executable (can also be set via IDT_PATH environment variable)",
+ )
+ parser.add_argument(
+ "--compile-commands",
+ type=str,
+ help="Path to compile_commands.json (can also be set via COMPILE_COMMANDS_PATH environment variable)",
+ )
+ parser.add_argument(
+ "--verbose", action="store_true", default=True, help="Enable verbose output"
+ )
+
+ parsed_args = parser.parse_args()
+
+ # Parse changed files if provided
+ if parsed_args.changed_files:
+ parsed_args.changed_files = [
+ f.strip() for f in parsed_args.changed_files.split(",") if f.strip()
+ ]
+ else:
+ parsed_args.changed_files = []
+
+ args = IdsCheckArgs(parsed_args)
+ checker = IdsChecker()
+ exit_code = checker.run(args)
+
+ if checker.comment:
+ with open("comments", "w") as f:
+ import json
+
+ json.dump([checker.comment], f)
+
+ sys.exit(exit_code)
>From cbec12448cb6aa803fafd0ef1716bc436b1a3c25 Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <fabrice at thebrowser.company>
Date: Mon, 12 Jan 2026 15:56:09 +0100
Subject: [PATCH 5/7] Switch to using `requirements.txt`
---
.github/workflows/ids-check.yml | 8 +-------
llvm/utils/git/requirements.txt | 6 +++++-
llvm/utils/git/requirements.txt.in | 1 +
3 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/.github/workflows/ids-check.yml b/.github/workflows/ids-check.yml
index ada90c6863551..c04e3b96d3a65 100644
--- a/.github/workflows/ids-check.yml
+++ b/.github/workflows/ids-check.yml
@@ -1,9 +1,6 @@
name: "Check LLVM ABI annotations"
on:
pull_request:
- branches:
- - main
- - 'users/**'
push:
branches:
- 'main'
@@ -24,7 +21,6 @@ jobs:
timeout-minutes: 10
steps:
- # TODO: Use an image with a prebuilt idt.
- uses: actions/checkout at 8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4.2.2
with:
repository: compnerd/ids
@@ -45,11 +41,10 @@ jobs:
base_sha: 'HEAD~1'
sha: 'HEAD'
- # TODO: Use an image with a prebuilt idt.
- name: Install dependencies
run: |
sudo apt install -y clang-19 ninja-build libclang-19-dev
- pip install lit PyGithub
+ pip install --require-hashes -r ./llvm/utils/git/requirements.txt
- name: Configure and build minimal LLVM for use by ids
run: |
@@ -65,7 +60,6 @@ jobs:
cd ${{ github.workspace }}/llvm-project/build/
ninja -t targets all | grep "CommonTableGen: phony$" | grep -v "/" | sed 's/:.*//'
- # TODO: Use an image with a prebuilt idt.
- name: Configure ids
run: |
cmake -B ${{ github.workspace }}/ids/build/ \
diff --git a/llvm/utils/git/requirements.txt b/llvm/utils/git/requirements.txt
index bbb9059b6b260..51c489ad7abfa 100644
--- a/llvm/utils/git/requirements.txt
+++ b/llvm/utils/git/requirements.txt
@@ -1,5 +1,5 @@
#
-# This file is autogenerated by pip-compile with Python 3.11
+# This file is autogenerated by pip-compile with Python 3.14
# by the following command:
#
# pip-compile --generate-hashes --output-file=requirements.txt requirements.txt.in
@@ -218,6 +218,10 @@ idna==3.8 \
--hash=sha256:050b4e5baadcd44d760cedbd2b8e639f2ff89bbc7a5730fcc662954303377aac \
--hash=sha256:d838c2c0ed6fced7693d5e8ab8e734d5f8fda53a039c0164afb0b82e771e3603
# via requests
+lit==18.1.8 \
+ --hash=sha256:47c174a186941ae830f04ded76a3444600be67d5e5fb8282c3783fba671c4edb \
+ --hash=sha256:a873ff7acd76e746368da32eb7355625e2e55a2baaab884c9cc130f2ee0300f7
+ # via -r requirements.txt.in
pycparser==2.22 \
--hash=sha256:491c8be9c040f5390f5bf44a5b07752bd07f56edf992381b05c701439eec10f6 \
--hash=sha256:c3702b6d3dd8c7abc1afa565d7e63d53a1d0bd86cdc24edd75470f4de499cfcc
diff --git a/llvm/utils/git/requirements.txt.in b/llvm/utils/git/requirements.txt.in
index e880e94e1de80..dfd6d0637a545 100644
--- a/llvm/utils/git/requirements.txt.in
+++ b/llvm/utils/git/requirements.txt.in
@@ -9,3 +9,4 @@ PyGithub==2.4.0 # >=1.59.1 For WorkflowRun.name
# >= Fix for https://github.com/PyGithub/PyGithub/issues/3001
# (variables in graphql query).
GitPython>=3.1.32 # https://security.snyk.io/vuln/SNYK-PYTHON-GITPYTHON-5840584
+lit>=18.1.8 # No entry on snyk as of 2026-12-01
>From 047fbad794e8e36ac538f929f264792a757f968b Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <fabrice at thebrowser.company>
Date: Mon, 12 Jan 2026 16:04:59 +0100
Subject: [PATCH 6/7] Use the right path for `requirements.txt`
---
.github/workflows/ids-check.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.github/workflows/ids-check.yml b/.github/workflows/ids-check.yml
index c04e3b96d3a65..a98cfa8d44dc6 100644
--- a/.github/workflows/ids-check.yml
+++ b/.github/workflows/ids-check.yml
@@ -44,7 +44,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt install -y clang-19 ninja-build libclang-19-dev
- pip install --require-hashes -r ./llvm/utils/git/requirements.txt
+ pip install --require-hashes -r ${{ github.workspace }}/llvm-project/llvm/utils/git/requirements.txt
- name: Configure and build minimal LLVM for use by ids
run: |
>From 707b1e02ba73f5d40b3d6a89e9ba13d484f2b0be Mon Sep 17 00:00:00 2001
From: Fabrice de Gans <fabrice at thebrowser.company>
Date: Mon, 12 Jan 2026 16:28:00 +0100
Subject: [PATCH 7/7] Address review comments
---
.github/workflows/ids-check.yml | 4 ++--
llvm/utils/git/ids-check-helper.py | 4 ----
2 files changed, 2 insertions(+), 6 deletions(-)
diff --git a/.github/workflows/ids-check.yml b/.github/workflows/ids-check.yml
index a98cfa8d44dc6..4a9b61006a99e 100644
--- a/.github/workflows/ids-check.yml
+++ b/.github/workflows/ids-check.yml
@@ -21,13 +21,13 @@ jobs:
timeout-minutes: 10
steps:
- - uses: actions/checkout at 8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4.2.2
+ uses: actions/checkout at 8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
repository: compnerd/ids
path: ${{ github.workspace }}/ids
ref: b3bf35dd13d7ff244a6a6d106fe58d0eedb5743e # main
- - uses: actions/checkout at 8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4.2.2
+ uses: actions/checkout at 8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
path: ${{ github.workspace }}/llvm-project
fetch-depth: 2
diff --git a/llvm/utils/git/ids-check-helper.py b/llvm/utils/git/ids-check-helper.py
index 3b731733d2811..62a498dd0a71f 100755
--- a/llvm/utils/git/ids-check-helper.py
+++ b/llvm/utils/git/ids-check-helper.py
@@ -1,12 +1,8 @@
#!/usr/bin/env python3
#
-# ====- ids-check-helper, runs ids-check from the ci or in a hook --*- python -*--==#
-#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-#
-# ==--------------------------------------------------------------------------------------==#
import argparse
import os
More information about the llvm-commits
mailing list