Skip to content

Checked C Convert

Aaron Eline edited this page Dec 21, 2020 · 4 revisions

Instructions to setting up Checked C clang and the porting tool

Cloning the correct repos

  1. Go to this link

  2. Go to the Cloning LLVM/clang on Unix/Linux section

  3. Clone the first repo

    • $ git clone https://github.com/Microsoft/checkedc-llvm llvm
  4. Instead of cloning the second repo, clone our plum-umd/checkedc-clang repo

    • $ git clone https://github.com/plum-umd/checkedc-clang.git clang
  5. Clone the 3rd repo and following the rest of the steps as usual

Building 3c

  1. From your build directory run (they tell you to name it llvm.obj):
    • $ make 3c
    • The 3c executable now lives in your BUILD_DIR/bin/ directory

Running 3c

  1. This directory has the instructions on how to use 3c
  2. Things they don't tell you or have changed
    • For single file you just need to run $ path/to/3c/path/to/<file_name>.c

      • The checkedc code will be sent to std_out, you can redirect it of course. The convention is <file_name>.checked.c
    • For a multi-file project

      • You have to configure the Makefiles first to run the checkedc clang instead of gcc.

      • I use these flags:

        • External library: LDFLAGS=-I/path/to/llvm/projects/checkedc-wrapper/checkedc/include
        • Remove limit for number of errors: CFLAGS=-ferror-limit=0
        • Checked C Clang: CC=path/to/BUILD_DIR/bin/clang
      • To generate the compile_commands.json database run $ bear make

      • You need to generate a file with the full path names of all the .c and .h files that will be converted

        • I run this command: $ find `pwd` -regex '.*/.*\.\(c\|h\)$' > file_list.txt
      • Run the update-includes.py first!

        • $ python path/to/llvm/tools/clang/tools/3c/utils/update-includes.py --includeDir path/to/llvm/projects/checkedc-wrapper/checkedc/include/ file_list.txt
      • Run convert-commands.py

        • $ nohup python path/to/llvm/tools/clang/tools/3c/utils/convert-commands.py -cc compile_commands.json -p path/to/BUILD_DIR/bin/3c > output.txt 2>&1 &

        • I use nohup because this step usually takes a long time depending on the project size.

        • This step will produce three files output.txt, convert_individual.sh, and convert_all.sh

        • Running convert_all.sh will run the whole conversion again. And running convert_individual.sh can be used for individual files.

        • The will produce a <file_name>.checked.c and <file_name>.checked.h for every file that is in compile_commands.json (so not necessarily all of files in file_list.txt).

        • I wrote a script to move all the <file_name>.checked.c and <file_name>.checked.h to <file_name>.c and <file_name>.h files: convert_script.rb