|
| 1 | +#! /usr/bin/env bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +COMMIT=$1 |
| 6 | + |
| 7 | +if [ -z "$COMMIT" ]; then |
| 8 | + if [ ! -z "$OPENAI_API_KEY" ]; then |
| 9 | + echo "Usage: $0 <commit> [<target_file> <target_line>]" |
| 10 | + echo "Example: $0 abcdef1234 (OPENAI_API_KEY is currently set to use LLM)" |
| 11 | + echo "<target_file> and <target_line> are optional. If not provided, the script will use the LLM to determine them." |
| 12 | + echo "If you want to use a specific target file and line, please provide them as arguments." |
| 13 | + else |
| 14 | + echo "Usage: $0 <commit> <target_file> <target_line>" |
| 15 | + echo "Example: $0 abcdef1234 llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp 1629" |
| 16 | + echo "<target_file> and <target_line> are required as OPENAI_API_KEY is not set." |
| 17 | + fi |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +if [ -z "$LLVM_BUILDS" ]; then |
| 22 | + echo "Error: LLVM_BUILDS is not set. Please set it before running the script." |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +if [ -z "$LLVM_PATH" ]; then |
| 27 | + echo "Error: LLVM_PATH is not set. Please set it before running the script." |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +if [ -z "$SEEDS" ]; then |
| 32 | + echo "Error: SEEDS is not set. Please set it before running the script." |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | + |
| 36 | +# Check if required toolchain is installed to build LLVM under test |
| 37 | +which clang |
| 38 | +which clang++ |
| 39 | +which lld |
| 40 | + |
| 41 | +if [ ! -z "$2" ] && [ ! -z "$3" ]; then |
| 42 | + echo "Using target file and line from command line arguments." |
| 43 | + TARGET_FILE=$2 |
| 44 | + TARGET_LINE=$3 |
| 45 | +else |
| 46 | + echo "Using target file and line from LLM." |
| 47 | + |
| 48 | + if [ -z "$OPENAI_API_KEY" ]; then |
| 49 | + echo "OPENAI_API_KEY is not set. Please set it before running the script." |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + |
| 53 | + TARGET=$(tools/targetline.py $COMMIT) |
| 54 | + TARGET_FILE=$(echo "$TARGET" | head -n 1 | cut -d':' -f2) |
| 55 | + TARGET_LINE=$(echo "$TARGET" | tail -n 1 | cut -d':' -f2) |
| 56 | +fi |
| 57 | + |
| 58 | +echo "target file: $TARGET_FILE" |
| 59 | +echo "target line: $TARGET_LINE" |
| 60 | + |
| 61 | +LLVM_DIR=$(tools/build.py commit $COMMIT $TARGET_FILE) |
| 62 | +echo "LLVM_DIR: $LLVM_DIR" |
| 63 | + |
| 64 | +SEEDS=$SEEDS/$COMMIT |
| 65 | +mkdir -p $SEEDS |
| 66 | +LLVM_PATH=$LLVM_BUILDS/commit/$COMMIT tools/harvest.py -f -o $SEEDS |
| 67 | + |
| 68 | +RUN_DIR=$HOME/optimuzz-runs/$COMMIT/$TARGET_LINE |
| 69 | +tools/fuzz.py $LLVM_DIR $SEEDS $TARGET_FILE $TARGET_LINE \ |
| 70 | + -r $HOME/optimuzz-runs/$COMMIT/$TARGET_LINE |
0 commit comments