Skip to content

Commit e49a609

Browse files
committed
fix clang-format for recent PRs and new rules
Note that LLVM does not support proper version matching, since the attempt to use it from cmake apparently failed: https://reviews.llvm.org/D99451.
1 parent 8c31246 commit e49a609

File tree

4 files changed

+146
-142
lines changed

4 files changed

+146
-142
lines changed

.github/workflows/main.yml

+129-129
Original file line numberDiff line numberDiff line change
@@ -1,129 +1,129 @@
1-
name: Build and Test
2-
3-
on:
4-
workflow_dispatch:
5-
pull_request:
6-
push:
7-
branches:
8-
- "master"
9-
10-
permissions:
11-
contents: read
12-
13-
# This allows a subsequently queued workflow run to interrupt previous runs
14-
concurrency:
15-
group: '${{ github.workflow }} @ ${{ github.ref_protected && github.run_id || github.event.pull_request.number || github.ref }}'
16-
cancel-in-progress: true
17-
18-
jobs:
19-
build:
20-
strategy:
21-
matrix:
22-
include:
23-
- os: ubuntu-latest
24-
- os: macos-latest
25-
runs-on: ${{ matrix.os }}
26-
steps:
27-
- name: Checkout
28-
uses: actions/checkout@v3
29-
30-
- name: Setup LLVM (Linux)
31-
if: ${{ runner.os == 'Linux' }}
32-
run: |
33-
wget https://apt.llvm.org/llvm.sh
34-
chmod +x llvm.sh
35-
sudo ./llvm.sh 19 all
36-
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 160
37-
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-19 160
38-
sudo update-alternatives --install /usr/bin/lli lli /usr/bin/lli-19 160
39-
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-19 160
40-
41-
- name: Setup LLVM and GCC (MacOS)
42-
if: ${{ runner.os == 'macOS' }}
43-
run: |
44-
brew install llvm@19
45-
echo "$(brew --prefix llvm@19)/bin" >> $GITHUB_PATH
46-
echo "CC=$(brew --prefix llvm@19)/bin/clang" >> $GITHUB_ENV
47-
echo "CXX=$(brew --prefix llvm@19)/bin/clang++" >> $GITHUB_ENV
48-
cd /usr/local/bin
49-
ln -s gcc-11 gcc
50-
51-
- name: Update Python
52-
uses: actions/setup-python@v4
53-
with:
54-
python-version: '3.x'
55-
56-
- name: Install PyTest
57-
run: |
58-
python -m pip install --upgrade pip
59-
pip install pytest pytest-xdist
60-
61-
- name: Check formatting
62-
if: ${{ runner.os == 'Linux' }}
63-
run: find . -iname '*.h' -o -iname '*.cpp' | xargs clang-format -Werror --dry-run --style=LLVM --verbose
64-
65-
- name: Build
66-
run: |
67-
mkdir build
68-
cmake -S . -B build -DLLVM_INCLUDE_TESTS=On -DLLVM_DIR=/usr/lib/llvm-19/cmake
69-
cmake --build build
70-
71-
- name: Test
72-
run: |
73-
gcc --version
74-
pytest -n 16
75-
76-
# The llvm-dev package doesn't exist for Windows, so we need to build LLVM ourselves.
77-
build-windows:
78-
runs-on: windows-latest
79-
env:
80-
SCCACHE_GHA_ENABLED: "true"
81-
steps:
82-
- name: Checkout LLVM
83-
id: checkout-llvm
84-
uses: actions/checkout@master
85-
with:
86-
repository: llvm/llvm-project
87-
ref: llvmorg-19.1.1
88-
89-
- name: Checkout
90-
uses: actions/checkout@v3
91-
with:
92-
path: ${{ github.workspace }}/llvm/projects/llvm-cbe
93-
94-
- name: Update Python
95-
uses: actions/setup-python@v4
96-
with:
97-
python-version: '3.x'
98-
99-
- name: Install PyTest
100-
run: |
101-
python -m pip install --upgrade pip
102-
pip install pytest pytest-xdist
103-
104-
- name: Initialize LLVM build cache
105-
uses: mozilla-actions/sccache-action@v0.0.3
106-
107-
- name: Build
108-
shell: pwsh
109-
run: |
110-
$vsWhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
111-
$visualStudioInstallationPath = & $vsWhere -latest -property installationPath
112-
Import-Module (Join-Path $visualStudioInstallationPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll')
113-
Enter-VsDevShell -VsInstallPath $visualStudioInstallationPath -DevCmdArguments '-arch=x64 -host_arch=x64'
114-
cd ${{ github.workspace }}
115-
if (!(Test-Path '${{ github.workspace }}\build\')) { mkdir '${{ github.workspace }}\build' }
116-
cmake -S llvm -B build -G Ninja -DLLVM_INCLUDE_TESTS=On -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache
117-
cmake --build build
118-
119-
- name: Test
120-
shell: pwsh
121-
run: |
122-
$vsWhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
123-
$visualStudioInstallationPath = & $vsWhere -latest -property installationPath
124-
Import-Module (Join-Path $visualStudioInstallationPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll')
125-
Enter-VsDevShell -VsInstallPath $visualStudioInstallationPath -DevCmdArguments '-arch=x64 -host_arch=x64'
126-
cd (Join-Path '${{ github.workspace }}' 'llvm\projects\llvm-cbe')
127-
$env:PATH=$env:Path + ";${{ github.workspace }}\build\bin"
128-
$env:LLVMToolDir="${{ github.workspace }}\build\bin"
129-
pytest -n 16
1+
name: Build and Test
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- "master"
9+
10+
permissions:
11+
contents: read
12+
13+
# This allows a subsequently queued workflow run to interrupt previous runs
14+
concurrency:
15+
group: '${{ github.workflow }} @ ${{ github.ref_protected && github.run_id || github.event.pull_request.number || github.ref }}'
16+
cancel-in-progress: true
17+
18+
jobs:
19+
build:
20+
strategy:
21+
matrix:
22+
include:
23+
- os: ubuntu-latest
24+
- os: macos-latest
25+
runs-on: ${{ matrix.os }}
26+
steps:
27+
- name: Checkout
28+
uses: actions/checkout@v3
29+
30+
- name: Setup LLVM (Linux)
31+
if: ${{ runner.os == 'Linux' }}
32+
run: |
33+
wget https://apt.llvm.org/llvm.sh
34+
chmod +x llvm.sh
35+
sudo ./llvm.sh 19 all
36+
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-19 160
37+
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-19 160
38+
sudo update-alternatives --install /usr/bin/lli lli /usr/bin/lli-19 160
39+
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-19 160
40+
41+
- name: Setup LLVM and GCC (MacOS)
42+
if: ${{ runner.os == 'macOS' }}
43+
run: |
44+
brew install llvm@19 gcc@14
45+
echo "$(brew --prefix llvm@19)/bin" >> $GITHUB_PATH
46+
echo "CC=$(brew --prefix llvm@19)/bin/clang" >> $GITHUB_ENV
47+
echo "CXX=$(brew --prefix llvm@19)/bin/clang++" >> $GITHUB_ENV
48+
cd /usr/local/bin
49+
ln -s `which gcc-14` gcc
50+
51+
- name: Update Python
52+
uses: actions/setup-python@v4
53+
with:
54+
python-version: '3.x'
55+
56+
- name: Install PyTest
57+
run: |
58+
python -m pip install --upgrade pip
59+
pip install pytest pytest-xdist
60+
61+
- name: Check formatting
62+
if: ${{ runner.os == 'Linux' }}
63+
run: find . -iname '*.h' -o -iname '*.cpp' | xargs clang-format -Werror --dry-run --style=LLVM --verbose
64+
65+
- name: Build
66+
run: |
67+
mkdir build
68+
cmake -S . -B build -DLLVM_INCLUDE_TESTS=On -DLLVM_DIR=/usr/lib/llvm-19/cmake
69+
cmake --build build
70+
71+
- name: Test
72+
run: |
73+
gcc --version
74+
pytest -n 16
75+
76+
# The llvm-dev package doesn't exist for Windows, so we need to build LLVM ourselves.
77+
build-windows:
78+
runs-on: windows-latest
79+
env:
80+
SCCACHE_GHA_ENABLED: "true"
81+
steps:
82+
- name: Checkout LLVM
83+
id: checkout-llvm
84+
uses: actions/checkout@master
85+
with:
86+
repository: llvm/llvm-project
87+
ref: llvmorg-19.1.1
88+
89+
- name: Checkout
90+
uses: actions/checkout@v3
91+
with:
92+
path: ${{ github.workspace }}/llvm/projects/llvm-cbe
93+
94+
- name: Update Python
95+
uses: actions/setup-python@v4
96+
with:
97+
python-version: '3.x'
98+
99+
- name: Install PyTest
100+
run: |
101+
python -m pip install --upgrade pip
102+
pip install pytest pytest-xdist
103+
104+
- name: Initialize LLVM build cache
105+
uses: mozilla-actions/sccache-action@v0.0.3
106+
107+
- name: Build
108+
shell: pwsh
109+
run: |
110+
$vsWhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
111+
$visualStudioInstallationPath = & $vsWhere -latest -property installationPath
112+
Import-Module (Join-Path $visualStudioInstallationPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll')
113+
Enter-VsDevShell -VsInstallPath $visualStudioInstallationPath -DevCmdArguments '-arch=x64 -host_arch=x64'
114+
cd ${{ github.workspace }}
115+
if (!(Test-Path '${{ github.workspace }}\build\')) { mkdir '${{ github.workspace }}\build' }
116+
cmake -S llvm -B build -G Ninja -DLLVM_INCLUDE_TESTS=On -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache
117+
cmake --build build
118+
119+
- name: Test
120+
shell: pwsh
121+
run: |
122+
$vsWhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe'
123+
$visualStudioInstallationPath = & $vsWhere -latest -property installationPath
124+
Import-Module (Join-Path $visualStudioInstallationPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll')
125+
Enter-VsDevShell -VsInstallPath $visualStudioInstallationPath -DevCmdArguments '-arch=x64 -host_arch=x64'
126+
cd (Join-Path '${{ github.workspace }}' 'llvm\projects\llvm-cbe')
127+
$env:PATH=$env:Path + ";${{ github.workspace }}\build\bin"
128+
$env:LLVMToolDir="${{ github.workspace }}\build\bin"
129+
pytest -n 16

CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
if (NOT DEFINED LLVM_VERSION_MAJOR)
22
project(llvm-cbe)
33
set (USE_SYSTEM_LLVM 1)
4-
cmake_minimum_required(VERSION 3.4.3)
5-
find_package(LLVM 19 REQUIRED CONFIG)
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(LLVM 19.1 REQUIRED CONFIG)
66
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
77
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
88
message(STATUS "LLVM_INCLUDE_DIRS: ${LLVM_INCLUDE_DIRS}")

lib/Target/CBackend/CBackend.cpp

+12-10
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,8 @@ void CWriter::printConstant(Constant *CPV, enum OperandContext Context) {
12511251
Out << " >> ";
12521252
break;
12531253
case Instruction::ICmp:
1254-
switch ((dyn_cast<ICmpInst>(CE->getAsInstruction()))->getUnsignedPredicate()) {
1254+
switch ((dyn_cast<ICmpInst>(CE->getAsInstruction()))
1255+
->getUnsignedPredicate()) {
12551256
case ICmpInst::ICMP_EQ:
12561257
Out << " == ";
12571258
break;
@@ -1286,8 +1287,8 @@ void CWriter::printConstant(Constant *CPV, enum OperandContext Context) {
12861287
case Instruction::FCmp: {
12871288
Out << '(';
12881289
bool NeedsClosingParens = printConstExprCast(CE);
1289-
FCmpInst *CmpInst = dyn_cast<FCmpInst>(CE->getAsInstruction());
1290-
const auto Pred = CmpInst -> getPredicate();
1290+
FCmpInst *CmpInst = dyn_cast<FCmpInst>(CE->getAsInstruction());
1291+
const auto Pred = CmpInst->getPredicate();
12911292
if (Pred == FCmpInst::FCMP_FALSE)
12921293
Out << "0";
12931294
else if (Pred == FCmpInst::FCMP_TRUE)
@@ -4645,7 +4646,7 @@ void CWriter::printIntrinsicDefinition(FunctionType *funT, unsigned Opcode,
46454646
cwriter_assert(cast<StructType>(retT)->getElementType(0) == elemT);
46464647
Out << " r.field1 = LLVMMul_sov(8 * sizeof(a), &a, &b, &r.field0);\n";
46474648
break;
4648-
4649+
46494650
case Intrinsic::uadd_sat:
46504651
// r = (a > XX_MAX - b) ? XX_MAX : a + b
46514652
cwriter_assert(retT == elemT);
@@ -4655,7 +4656,7 @@ void CWriter::printIntrinsicDefinition(FunctionType *funT, unsigned Opcode,
46554656
printLimitValue(*elemIntT, false, true, Out);
46564657
Out << " : a + b;\n";
46574658
break;
4658-
4659+
46594660
case Intrinsic::sadd_sat:
46604661
// r = (b > 0 && a > XX_MAX - b) ? XX_MAX : a + b;
46614662
// r = (b < 0 && a < XX_MIN - b) ? XX_MIN : r;
@@ -4671,15 +4672,15 @@ void CWriter::printIntrinsicDefinition(FunctionType *funT, unsigned Opcode,
46714672
printLimitValue(*elemIntT, true, false, Out);
46724673
Out << " : r;\n";
46734674
break;
4674-
4675+
46754676
case Intrinsic::usub_sat:
46764677
// r = (a < b) ? XX_MIN : a - b;
46774678
cwriter_assert(retT == elemT);
46784679
Out << " r = (a < b) ? ";
46794680
printLimitValue(*elemIntT, false, false, Out);
46804681
Out << " : a - b;\n";
46814682
break;
4682-
4683+
46834684
case Intrinsic::ssub_sat:
46844685
// r = (b > 0 && a < XX_MIN + b) ? XX_MIN : a - b;
46854686
// r = (b < 0 && a > XX_MAX + b) ? XX_MAX : r;
@@ -4697,7 +4698,8 @@ void CWriter::printIntrinsicDefinition(FunctionType *funT, unsigned Opcode,
46974698
break;
46984699

46994700
case Intrinsic::ushl_sat:
4700-
// There's no poison value handler in llvm-cbe yet, so this code don't consider that.
4701+
// There's no poison value handler in llvm-cbe yet, so this code don't
4702+
// consider that.
47014703
// r = (a > (XX_MAX >> b)) ? XX_MAX : a << b;
47024704
cwriter_assert(retT == elemT);
47034705
Out << " r = (a > (";
@@ -4708,8 +4710,8 @@ void CWriter::printIntrinsicDefinition(FunctionType *funT, unsigned Opcode,
47084710
break;
47094711

47104712
case Intrinsic::sshl_sat:
4711-
// (XX_MAX) = 0111... Therfore, shifting this value by b to the right yields the
4712-
// maximum/minimum value that can be shifted without overflow.
4713+
// (XX_MAX) = 0111... Therfore, shifting this value by b to the right
4714+
// yields the maximum/minimum value that can be shifted without overflow.
47134715
// r = (a >= 0 && a > (XX_MAX >> b)) ? XX_MAX : a << b;
47144716
// r = (a < 0 && a < ((XX_MAX >> b) | XX_MIN))) ? XX_MIN : r;
47154717
cwriter_assert(retT == elemT);

test/cpp_tests/test_dtor.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ class Foo {
77

88
int main() {
99
int y = 0;
10-
{ Foo f(&y); }
10+
{
11+
Foo f(&y);
12+
}
1113
return y;
1214
}

0 commit comments

Comments
 (0)