Skip to content

Instantly share code, notes, and snippets.

@folkertdev
Created July 6, 2026 20:33
Show Gist options
  • Select an option

  • Save folkertdev/e6dcafdc79d9c14020e47ba0ed753e8f to your computer and use it in GitHub Desktop.

Select an option

Save folkertdev/e6dcafdc79d9c14020e47ba0ed753e8f to your computer and use it in GitHub Desktop.
C test case generation
#!/usr/bin/env bash
set -euo pipefail
file=${1:?usage: ./normalize-checks.sh FILE}
python3 ~/c/llvm-project/llvm/utils/update_cc_test_checks.py --clang=clang --filter-out ".*" "$file"
vim -Nu NONE -n -es "$file" <<'VIM'
g/-SAME:/s/\v^(.*\)).*/\1/
%s#// \(.\{-}\)-LABEL: \(.*\)\n// \1-SAME: \(.*\)#// \1: \2\3#
%s/\<define\>\s\+\%(\%(dso_local\|hidden\)\s\+\)\=\%(noundef\s\+\)\=/define /g
%s/\s*\[\[TMP[0-9]\+:%\.\*\]\]/{{.*}}/g
%s/\v<(noundef|readonly|writeonly|writable|noalias|returned|inreg|dead_on_unwind|dead_on_return)>|captures\(none\)|alignstack\([0-9]+\)|align [0-9]+|initializes\(\([^)]*\)\)|range\([^)]*\)/{{.*}}/g
%s/\v(\{\{\.\*\}\}\s*)+/\{\{\.\*\}\}/g
%s/\V{{.*}} /{{.*}} /g
%s/\V{{.*}}/{{.*}} /g
%s/\V {{.*}} / {{.*}} /g
%s/ \+/ /g
%s/ ,/,/g
%s/ )/)/g
%s/\<define\>\s\+/define {{.*}} /g
%s/^\(\/\/ [^:]\+:\)\s*/\=printf('%-18s ', submatch(1))/
wq
VIM
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --filter-out ".*" --version 6
// RUN: %clang --target=aarch64-apple-darwin -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=AARCH64_DARWIN
// RUN: %clang --target=aarch64-pc-windows-msvc -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=AARCH64_MSVC
// RUN: %clang --target=aarch64-unknown-linux-gnu -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=AARCH64
// RUN: %clang --target=arm-unknown-linux-gnueabihf -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM
// RUN: %clang --target=arm64ec-pc-windows-msvc -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=ARM64EC
// RUN: %clang --target=bpfel -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=BPF
// RUN: %clang --target=csky -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=CSKY
// RUN: %clang --target=i686-pc-windows-gnu -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=WIN32_GNU
// RUN: %clang --target=i686-pc-windows-msvc -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=WIN32_MSVC
// RUN: %clang --target=i686-unknown-linux-gnu -msse2 -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=I686
// RUN: %clang --target=loongarch32-unknown-none -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LOONGARCH32
// RUN: %clang --target=loongarch64-unknown-linux-gnu -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=LOONGARCH64
// RUN: %clang --target=mips-unknown-linux-gnu -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=MIPS
// RUN: %clang --target=mips64el-unknown-linux-gnuabi64 -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=MIPS64EL
// RUN: %clang --target=nvptx64-nvidia-cuda -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=NVPTX
// RUN: %clang --target=powerpc-unknown-linux-gnu -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=POWERPC
// RUN: %clang --target=powerpc64-ibm-aix -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=AIX
// RUN: %clang --target=powerpc64-unknown-linux-gnu -mabi=elfv1 -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=POWERPC64
// RUN: %clang --target=powerpc64le-unknown-linux-gnu -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=POWERPC64LE
// RUN: %clang --target=riscv32-unknown-linux-gnu -march=rv32gc -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=RISCV32
// RUN: %clang --target=riscv64-unknown-linux-gnu -march=rv64gc -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=RISCV64
// RUN: %clang --target=s390x-unknown-linux-gnu -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=S390X
// RUN: %clang --target=sparc-unknown-linux-gnu -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=SPARC
// RUN: %clang --target=sparc64-unknown-linux-gnu -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=SPARC64
// RUN: %clang --target=wasm32-unknown-unknown -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=WASM32
// RUN: %clang --target=wasm64-unknown-unknown -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=WASM64
// RUN: %clang --target=x86_64-pc-windows-gnu -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=WINDOWS_GNU
// RUN: %clang --target=x86_64-pc-windows-msvc -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=WINDOWS_MSVC
// RUN: %clang --target=x86_64-unknown-linux-gnu -O2 -S -emit-llvm -o - %s | FileCheck %s --check-prefix=X86_64
// Instructions
//
// - first run the LLVM utils/update_cc_test_checks.py script. This will generate LLVM-style CHECKs.
#ifdef __FLT16_MANT_DIG__
_Complex _Float16 cplx_f16(_Complex _Float16 x) { return x; }
#endif
_Complex float cplx_f32(_Complex float x) { return x; }
_Complex double cplx_f64(_Complex double x) { return x; }
#if defined(__FLOAT128__) || defined(__SIZEOF_FLOAT128__)
_Complex __float128 cplx_f128(_Complex __float128 x) { return x; }
#endif
_Complex __INT8_TYPE__ cplx_i8(_Complex __INT8_TYPE__ x) { return x; }
_Complex __INT16_TYPE__ cplx_i16(_Complex __INT16_TYPE__ x) { return x; }
_Complex __INT32_TYPE__ cplx_i32(_Complex __INT32_TYPE__ x) { return x; }
_Complex __INT64_TYPE__ cplx_i64(_Complex __INT64_TYPE__ x) { return x; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment