From 6c545ce6a5143da43ff05ca76540e6f8002a00ef Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Tue, 13 May 2025 00:32:00 +0800 Subject: [PATCH 1/5] Support LLVM 21.0 (development branch) --- src/llvm/enums.cr | 2 ++ src/llvm/ext/llvm-versions.txt | 2 +- src/llvm/lib_llvm.cr | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/llvm/enums.cr b/src/llvm/enums.cr index c944e360574d..3db87270300d 100644 --- a/src/llvm/enums.cr +++ b/src/llvm/enums.cr @@ -7,6 +7,7 @@ module LLVM ArgMemOnly Builtin ByVal + Captures Cold Convergent Dereferenceable @@ -91,6 +92,7 @@ module LLVM kinds[ArgMemOnly] = kind_for_name("argmemonly") kinds[Builtin] = kind_for_name("builtin") kinds[ByVal] = kind_for_name("byval") + kinds[Captures] = kind_for_name("captures") kinds[Cold] = kind_for_name("cold") kinds[Convergent] = kind_for_name("convergent") kinds[Dereferenceable] = kind_for_name("dereferenceable") diff --git a/src/llvm/ext/llvm-versions.txt b/src/llvm/ext/llvm-versions.txt index a5d4cfac2515..7e0184868f7b 100644 --- a/src/llvm/ext/llvm-versions.txt +++ b/src/llvm/ext/llvm-versions.txt @@ -1 +1 @@ -20.1 19.1 18.1 17.0 16.0 15.0 14.0 13.0 12.0 11.1 11.0 10.0 9.0 8.0 +21.0 20.1 19.1 18.1 17.0 16.0 15.0 14.0 13.0 12.0 11.1 11.0 10.0 9.0 8.0 diff --git a/src/llvm/lib_llvm.cr b/src/llvm/lib_llvm.cr index 7369026e12a5..db82fae25b72 100644 --- a/src/llvm/lib_llvm.cr +++ b/src/llvm/lib_llvm.cr @@ -73,6 +73,7 @@ IS_LT_180 = {{compare_versions(LibLLVM::VERSION, "18.0.0") < 0}} IS_LT_190 = {{compare_versions(LibLLVM::VERSION, "19.0.0") < 0}} IS_LT_200 = {{compare_versions(LibLLVM::VERSION, "20.0.0") < 0}} + IS_LT_210 = {{compare_versions(LibLLVM::VERSION, "21.0.0") < 0}} end {% end %} From 73edf50464a3b9759356f2c424258c29a9d0fb5c Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Tue, 13 May 2025 01:21:56 +0800 Subject: [PATCH 2/5] ci --- .github/workflows/llvm.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/llvm.yml b/.github/workflows/llvm.yml index 4d8929492a82..429569d78ab1 100644 --- a/.github/workflows/llvm.yml +++ b/.github/workflows/llvm.yml @@ -41,6 +41,7 @@ jobs: - {llvm_version: 18, runs-on: ubuntu-24.04, codename: noble} - {llvm_version: 19, runs-on: ubuntu-24.04, codename: noble} - {llvm_version: 20, runs-on: ubuntu-24.04, codename: noble} + - {llvm_version: 21, runs-on: ubuntu-24.04, codename: noble} name: "LLVM ${{ matrix.llvm_version }}" steps: - name: Checkout Crystal source From f6719b7c71e9c769ed33725a907162336268309e Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Tue, 13 May 2025 02:32:20 +0800 Subject: [PATCH 3/5] ci fixup --- .github/workflows/llvm.yml | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/llvm.yml b/.github/workflows/llvm.yml index 429569d78ab1..6857f23cbbf4 100644 --- a/.github/workflows/llvm.yml +++ b/.github/workflows/llvm.yml @@ -41,18 +41,22 @@ jobs: - {llvm_version: 18, runs-on: ubuntu-24.04, codename: noble} - {llvm_version: 19, runs-on: ubuntu-24.04, codename: noble} - {llvm_version: 20, runs-on: ubuntu-24.04, codename: noble} - - {llvm_version: 21, runs-on: ubuntu-24.04, codename: noble} - name: "LLVM ${{ matrix.llvm_version }}" + - {runs-on: ubuntu-24.04, codename: noble} + name: "LLVM ${{ matrix.llvm_version || 'Nightly' }}" steps: - name: Checkout Crystal source uses: actions/checkout@v4 - - name: Install LLVM ${{ matrix.llvm_version }} + - name: Install LLVM ${{ matrix.llvm_version || 'Nightly' }} run: | sudo apt remove 'llvm-*' 'libllvm*' wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc - sudo apt-add-repository -y deb http://apt.llvm.org/${{ matrix.codename }}/ llvm-toolchain-${{ matrix.codename }}-${{ matrix.llvm_version }} main - sudo apt install -y llvm-${{ matrix.llvm_version }}-dev lld + sudo apt-add-repository -y \ + deb \ + http://apt.llvm.org/${{ matrix.codename }}/ \ + llvm-toolchain-${{ matrix.codename }}${{ matrix.llvm_version && format('-{0}', matrix.llvm_version) || '' }} \ + main + sudo apt install -y llvm${{ matrix.llvm_version && format('-{0}', matrix.llvm_version) || '' }}-dev lld - name: Install Crystal uses: crystal-lang/install-crystal@v1 From 6cb93252b5d8603ecb23bf6994aa9e1295d995c9 Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Tue, 13 May 2025 19:22:37 +0800 Subject: [PATCH 4/5] fixup2 --- src/llvm/enums.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm/enums.cr b/src/llvm/enums.cr index 3db87270300d..8203df32da8a 100644 --- a/src/llvm/enums.cr +++ b/src/llvm/enums.cr @@ -7,7 +7,6 @@ module LLVM ArgMemOnly Builtin ByVal - Captures Cold Convergent Dereferenceable @@ -58,6 +57,7 @@ module LLVM WillReturn WriteOnly ZExt + Captures # NOTE: enum body does not allow `class_getter` or `TypeDeclaration`, hence # the nil cast From b1e323b3c0ec36f116a53f33cd9542daec0e677f Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Mon, 19 May 2025 12:49:13 +0800 Subject: [PATCH 5/5] fix string constant symbol name mangling --- src/compiler/crystal/codegen/codegen.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/crystal/codegen/codegen.cr b/src/compiler/crystal/codegen/codegen.cr index 07153e3a7789..c6b4b3d7bca7 100644 --- a/src/compiler/crystal/codegen/codegen.cr +++ b/src/compiler/crystal/codegen/codegen.cr @@ -2544,7 +2544,7 @@ module Crystal name = "'#{name}'" key = StringKey.new(@llvm_mod, str) @strings[key] ||= begin - global = @llvm_mod.globals.add(@llvm_typer.llvm_string_type(str.bytesize), name) + global = @llvm_mod.globals.add(@llvm_typer.llvm_string_type(str.bytesize), name.gsub('\\', "\\\\")) global.linkage = LLVM::Linkage::Private global.global_constant = true global.initializer = llvm_context.const_struct [