-
Notifications
You must be signed in to change notification settings - Fork 5
Checked C Convert
-
Go to this link
-
Go to the
Cloning LLVM/clang on Unix/Linux
section -
Clone the first repo
$ git clone https://github.com/Microsoft/checkedc-llvm llvm
-
Instead of cloning the second repo, clone our
plum-umd/checkedc-clang
repo$ git clone https://github.com/plum-umd/checkedc-clang.git clang
-
Clone the 3rd repo and following the rest of the steps as usual
- From your build directory run (they tell you to name it
llvm.obj
):$ make 3c
- The
3c
executable now lives in yourBUILD_DIR/bin/
directory
-
This directory has the instructions on how to use
3c
- 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
- The checkedc code will be sent to
-
For a multi-file project
-
You have to configure the Makefiles first to run the checkedc
clang
instead ofgcc
. -
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
- External library:
-
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
- I run this command:
-
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
, andconvert_all.sh
-
Running
convert_all.sh
will run the whole conversion again. And runningconvert_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 incompile_commands.json
(so not necessarily all of files infile_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
-
-
-