From 8647f134675242c7b37e64391c1bd1097412c5fb Mon Sep 17 00:00:00 2001 From: Alexander Penev <7923188+alexander-penev@users.noreply.github.com> Date: Thu, 30 Nov 2023 15:34:23 +0200 Subject: [PATCH] [ci] Add a debug build of Clang (#662) This patch builds clang and llvm from source in debug mode and run clad. We have several test failures which are marked with XFAIL now. --- .github/workflows/ci.yml | 80 ++++++++++++++++++++-- test/Arrays/ArrayInputsReverseMode.C | 2 + test/Arrays/ArrayInputsVectorForwardMode.C | 2 + test/FirstDerivative/Overloads.C | 1 + test/FirstDerivative/VirtualMethodsCall.C | 1 + test/ForwardMode/UserDefinedTypes.C | 2 + test/ForwardMode/VectorMode.C | 2 + test/ForwardMode/VectorModeInterface.C | 2 + test/Gradient/MemberFunctions.C | 2 + test/Gradient/UserDefinedTypes.C | 1 + test/Misc/RunDemos.C | 1 + test/lit.cfg | 12 +++- test/lit.site.cfg.in | 3 + 13 files changed, 104 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3f7ce6623..7b38ba666 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,6 +170,7 @@ jobs: os: ubuntu-20.04 compiler: gcc-9 clang-runtime: '12' + - name: ubu20-clang8-runtime12 os: ubuntu-20.04 compiler: clang-8 @@ -381,6 +382,12 @@ jobs: compiler: clang-15 clang-runtime: '16' + - name: ubu22-clang15-runtime16-debug + os: ubuntu-22.04 + compiler: clang-15 + clang-runtime: '16' + debug_build: true + steps: - uses: actions/checkout@v3 with: @@ -401,11 +408,15 @@ jobs: name: pr path: pr/ - uses: nelonoel/branch-name@v1.0.1 - - name: Setup default Build Type on *nux - if: runner.os != 'windows' + - name: Setup default Build Type on *nux (coverity) + if: ${{ (matrix.debug_build != true) && (runner.os != 'windows') }} run: | echo "BUILD_TYPE=Release" >> $GITHUB_ENV echo "CODE_COVERAGE=0" >> $GITHUB_ENV + - name: Setup default Build Type on *nux (build_debug & asserts) + if: ${{ (matrix.debug_build == true) && (runner.os != 'windows') }} + run: | + echo "BUILD_TYPE=Debug" >> $GITHUB_ENV - name: Setup default Build Type on Windows if: runner.os == 'windows' run: | @@ -546,8 +557,65 @@ jobs: done # We need PATH_TO_LLVM_BUILD later echo "PATH_TO_LLVM_BUILD=$PATH_TO_LLVM_BUILD" >> $GITHUB_ENV + + - name: Restore Cache LLVM/Clang runtime build directory (debug_build==true) + if: ${{ (matrix.debug_build == true) && (runner.os != 'windows') }} + uses: actions/cache/restore@v3 + id: cache + with: + path: | + llvm-project + key: ${{ matrix.os }}-clang-${{ matrix.clang-runtime }}.x-${{ env.BUILD_TYPE }} + - name: Build LLVM/Cling on Unix if the cache is invalid (debug_build==true) + if: ${{ (matrix.debug_build == true) && (runner.os != 'windows') && (steps.cache.outputs.cache-hit != 'true') }} + run: | + os="${{ matrix.os }}" + git clone --depth=1 -b release/${{ matrix.clang-runtime }}.x https://github.com/llvm/llvm-project.git + cd llvm-project + # Build + mkdir build + cd build + export CPU_COUNT="$(nproc --all)" + cmake \ + -DLLVM_ENABLE_PROJECTS="clang" \ + -DLLVM_TARGETS_TO_BUILD="host;NVPTX" \ + -DCMAKE_BUILD_TYPE=`[[ -z "$BUILD_TYPE" ]] && echo RelWithDebInfo || echo $BUILD_TYPE` \ + -DLLVM_ENABLE_ASSERTIONS=ON \ + -DCLANG_ENABLE_STATIC_ANALYZER=OFF \ + -DCLANG_ENABLE_ARCMT=OFF \ + -DCLANG_ENABLE_FORMAT=OFF \ + -DCLANG_ENABLE_BOOTSTRAP=OFF \ + -DLLVM_ENABLE_TERMINFO=OFF \ + -DCLANG_INCLUDE_TESTS=OFF \ + -DCLANG_INCLUDE_DOCS=OFF \ + -DLLVM_INCLUDE_TESTS=OFF \ + -DLLVM_INCLUDE_DOCS=OFF \ + ../llvm + cmake --build . --target clang FileCheck llvm-config --parallel ${CPU_COUNT} + cd ../../ + - name: Save Cache LLVM/Clang runtime build directory (debug_build==true) + uses: actions/cache/save@v3 + if: ${{ (matrix.debug_build == true) && (runner.os != 'windows') && (steps.cache.outputs.cache-hit != 'true') }} + with: + path: | + llvm-project + key: ${{ steps.cache.outputs.cache-primary-key }} + - name: Set LLVM/Cling build path on Unix (debug_build==true) + if: ${{ (matrix.debug_build == true) && (runner.os != 'windows') }} + run: | + export PATH_TO_LLVM_BUILD="$PWD/llvm-project/build" + echo "PATH_TO_LLVM_BUILD=$PATH_TO_LLVM_BUILD" + echo "PATH_TO_LLVM_BUILD=$PATH_TO_LLVM_BUILD" >> $GITHUB_ENV + pip3 install lit # LLVM lit is not part of the llvm releases... + vers="${compiler#*-}" + if [[ ! -f "$PATH_TO_LLVM_BUILD/bin/FileCheck" ]]; then + ln -s /usr/bin/FileCheck-$vers $PATH_TO_LLVM_BUILD/bin/FileCheck + fi + env: + compiler: ${{ matrix.compiler }} + - name: Setup LLVM/Clang on Linux - if: runner.os == 'Linux' + if: ${{ (runner.os == 'Linux') && (matrix.debug_build != true) }} run: | UNIX_DISTRO=$(lsb_release -rs) PATH_TO_LLVM_BUILD=/usr/lib/llvm-${{ matrix.clang-runtime }}/ @@ -564,7 +632,7 @@ jobs: # We need PATH_TO_LLVM_BUILD later echo "PATH_TO_LLVM_BUILD=$PATH_TO_LLVM_BUILD" >> $GITHUB_ENV - name: Setup LLVM/Clang on Windows - if: runner.os == 'windows' + if: ${{ runner.os == 'windows' }} run: | C:\Miniconda\condabin\conda.bat install -y -c conda-forge "clangdev=${{ matrix.clang-runtime }}" $env:PATH_TO_LLVM_BUILD="$env:CONDA\Library" @@ -593,7 +661,7 @@ jobs: echo "CODE_COVERAGE=1" >> $GITHUB_ENV echo "BUILD_TYPE=Debug" >> $GITHUB_ENV - name: Display config *nix - if: runner.os != 'windows' + if: ${{ runner.os != 'windows' }} run: | cmake --version $CC --version @@ -604,7 +672,7 @@ jobs: echo "Building clad in `[[ -z "$BUILD_TYPE" ]] && echo RelWithDebInfo || echo $BUILD_TYPE`" python3 --version - name: Display config Windows - if: runner.os == 'windows' + if: ${{ runner.os == 'windows' }} run: | cmake --version echo "CC=$env:CC" diff --git a/test/Arrays/ArrayInputsReverseMode.C b/test/Arrays/ArrayInputsReverseMode.C index aaa2d5a63..44d433838 100644 --- a/test/Arrays/ArrayInputsReverseMode.C +++ b/test/Arrays/ArrayInputsReverseMode.C @@ -1,6 +1,8 @@ // RUN: %cladclang %s -I%S/../../include -Wno-unused-value -oArrayInputsReverseMode.out 2>&1 | FileCheck %s // RUN: ./ArrayInputsReverseMode.out | FileCheck -check-prefix=CHECK-EXEC %s +// XFAIL: asserts + //CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" diff --git a/test/Arrays/ArrayInputsVectorForwardMode.C b/test/Arrays/ArrayInputsVectorForwardMode.C index 2ff769216..98230abbd 100644 --- a/test/Arrays/ArrayInputsVectorForwardMode.C +++ b/test/Arrays/ArrayInputsVectorForwardMode.C @@ -1,6 +1,8 @@ // RUN: %cladclang %s -I%S/../../include -oArrayInputsVectorForwardMode.out 2>&1 | FileCheck %s // RUN: ./ArrayInputsVectorForwardMode.out | FileCheck -check-prefix=CHECK-EXEC %s +// XFAIL: asserts + // CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" diff --git a/test/FirstDerivative/Overloads.C b/test/FirstDerivative/Overloads.C index 1e70f8aca..f69b13be5 100644 --- a/test/FirstDerivative/Overloads.C +++ b/test/FirstDerivative/Overloads.C @@ -1,5 +1,6 @@ // RUN: %cladclang %s -I%S/../../include -oOverloads.out 2>&1 | FileCheck %s // RUN: ./Overloads.out | FileCheck -check-prefix=CHECK-EXEC %s +// XFAIL: asserts //CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" diff --git a/test/FirstDerivative/VirtualMethodsCall.C b/test/FirstDerivative/VirtualMethodsCall.C index 2ef52b667..606625a5d 100644 --- a/test/FirstDerivative/VirtualMethodsCall.C +++ b/test/FirstDerivative/VirtualMethodsCall.C @@ -1,5 +1,6 @@ // RUN: %cladclang %s -I%S/../../include -oVirtualMethodsCall.out 2>&1 | FileCheck %s // RUN: ./VirtualMethodsCall.out | FileCheck -check-prefix=CHECK-EXEC %s +// XFAIL: asserts //CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" diff --git a/test/ForwardMode/UserDefinedTypes.C b/test/ForwardMode/UserDefinedTypes.C index 568ca261d..232e6b51b 100644 --- a/test/ForwardMode/UserDefinedTypes.C +++ b/test/ForwardMode/UserDefinedTypes.C @@ -1,6 +1,8 @@ // RUN: %cladclang %s -I%S/../../include -oUserDefinedTypes.out | FileCheck %s // RUN: ./UserDefinedTypes.out | FileCheck -check-prefix=CHECK-EXEC %s +// XFAIL: asserts + // CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" diff --git a/test/ForwardMode/VectorMode.C b/test/ForwardMode/VectorMode.C index 08fdfad2b..aacdb37a8 100644 --- a/test/ForwardMode/VectorMode.C +++ b/test/ForwardMode/VectorMode.C @@ -1,6 +1,8 @@ // RUN: %cladclang %s -I%S/../../include -oVectorMode.out 2>&1 | FileCheck %s // RUN: ./VectorMode.out | FileCheck -check-prefix=CHECK-EXEC %s +// XFAIL: asserts + //CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" diff --git a/test/ForwardMode/VectorModeInterface.C b/test/ForwardMode/VectorModeInterface.C index 3c809ab67..bc597670b 100644 --- a/test/ForwardMode/VectorModeInterface.C +++ b/test/ForwardMode/VectorModeInterface.C @@ -1,5 +1,7 @@ // RUN: %cladclang %s -I%S/../../include -fsyntax-only -Xclang -verify 2>&1 | FileCheck %s +// XFAIL: asserts + //CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" diff --git a/test/Gradient/MemberFunctions.C b/test/Gradient/MemberFunctions.C index 950889531..1b0582fef 100644 --- a/test/Gradient/MemberFunctions.C +++ b/test/Gradient/MemberFunctions.C @@ -5,6 +5,8 @@ // RUN: %cladclang -std=c++17 %s -fno-exceptions -I%S/../../include -oMemberFunctions-cpp17.out 2>&1 | FileCheck %s // RUN: ./MemberFunctions-cpp17.out | FileCheck -check-prefix=CHECK-EXEC %s +// XFAIL: asserts + //CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" diff --git a/test/Gradient/UserDefinedTypes.C b/test/Gradient/UserDefinedTypes.C index d10b41857..068c6ed06 100644 --- a/test/Gradient/UserDefinedTypes.C +++ b/test/Gradient/UserDefinedTypes.C @@ -1,5 +1,6 @@ // RUN: %cladclang %s -I%S/../../include -oUserDefinedTypes.out 2>&1 | FileCheck %s // RUN: ./UserDefinedTypes.out | FileCheck -check-prefix=CHECK-EXEC %s +// XFAIL: asserts // CHECK-NOT: {{.*error|warning|note:.*}} #include "clad/Differentiator/Differentiator.h" diff --git a/test/Misc/RunDemos.C b/test/Misc/RunDemos.C index 4eb001176..736793560 100644 --- a/test/Misc/RunDemos.C +++ b/test/Misc/RunDemos.C @@ -4,6 +4,7 @@ // RUN: %cladclang %S/../../demos/RosenbrockFunction.cpp -I%S/../../include 2>&1 // RUN: %cladclang %S/../../demos/ComputerGraphics/smallpt/SmallPT.cpp -I%S/../../include 2>&1 +// XFAIL: asserts //-----------------------------------------------------------------------------/ // Demo: Gradient.cpp diff --git a/test/lit.cfg b/test/lit.cfg index 62ba8de32..1797ec687 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -6,8 +6,10 @@ import os import platform import re -import lit.util import lit.formats +import lit.util + +from lit.llvm import llvm_config # name: The name of this test suite. config.name = 'clad' @@ -322,3 +324,11 @@ if libcudart_path is not None: if(config.have_enzyme): config.available_features.add('Enzyme') + +# Ask llvm-config about asserts and build mode +llvm_config.feature_config( + [ + ("--assertion-mode", {"ON": "asserts"}), + ("--build-mode", {"[Dd][Ee][Bb][Uu][Gg]": "debug"}), + ] +) diff --git a/test/lit.site.cfg.in b/test/lit.site.cfg.in index dd865ad9a..a82bd36d7 100644 --- a/test/lit.site.cfg.in +++ b/test/lit.site.cfg.in @@ -22,5 +22,8 @@ except KeyError: key, = e.args lit_config.fatal("unable to find %r parameter, use '--param=%s=VALUE'" % (key,key)) +import lit.llvm +lit.llvm.initialize(lit_config, config) + # Let the main config do the real work. lit_config.load_config(config, "@CLAD_SOURCE_DIR@/test/lit.cfg")