Skip to content

Commit 66930d3

Browse files
author
owen-jones-diffblue
authored
Merge pull request diffblue#473 from diffblue/CBMC_merge_2018-06-26
SEC-518: Cbmc merge 2018-06-26
2 parents 4e2c87b + 0b2e3a6 commit 66930d3

File tree

315 files changed

+3783
-1075
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

315 files changed

+3783
-1075
lines changed

cbmc/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Release/*
2828
*.obj
2929
*.a
3030
*.lib
31+
version.h
3132
src/ansi-c/arm_builtin_headers.inc
3233
src/ansi-c/clang_builtin_headers.inc
3334
src/ansi-c/cprover_builtin_headers.inc

cbmc/CMakeLists.txt

+43
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
2020
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
2121

2222
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
23+
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang" OR
2324
"${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU"
2425
)
2526
# Ensure NDEBUG is not set for release builds
@@ -41,6 +42,48 @@ if(${enable_cbmc_tests})
4142
enable_testing()
4243
endif()
4344

45+
# based on https://cmake.org/pipermail/cmake/2010-July/038015.html
46+
find_package(Git)
47+
if(GIT_FOUND)
48+
file(WRITE ${CMAKE_BINARY_DIR}/version.cmake
49+
"
50+
file(STRINGS \${CBMC_SOURCE_DIR}/config.inc
51+
config_inc_v REGEX \"CBMC_VERSION *= *[0-9\.]+\")
52+
string(REGEX REPLACE \"^CBMC_VERSION *= *\" \"\" CBMC_RELEASE \${config_inc_v})
53+
execute_process(
54+
COMMAND \"${GIT_EXECUTABLE}\" \"describe\" \"--tags\" \"--always\" \"--dirty\"
55+
OUTPUT_VARIABLE GIT_INFO
56+
OUTPUT_STRIP_TRAILING_WHITESPACE
57+
)
58+
configure_file(\${CUR}/version.h.in version.h)
59+
"
60+
)
61+
else()
62+
file(WRITE ${CMAKE_BINARY_DIR}/version.cmake
63+
"
64+
file(STRINGS \${CBMC_SOURCE_DIR}/config.inc
65+
config_inc_v REGEX \"CBMC_VERSION *= *[0-9\.]+\")
66+
string(REGEX REPLACE \"^CBMC_VERSION *= *\" \"\" CBMC_RELEASE \${config_inc_v})
67+
set(GIT_INFO \"n/a\")
68+
configure_file(\${CUR}/version.h.in version.h)
69+
"
70+
)
71+
endif()
72+
73+
macro(git_revision target)
74+
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/version.h.in
75+
"\#define CBMC_VERSION \"@CBMC_RELEASE@ (@GIT_INFO@)\"\n")
76+
add_custom_target(
77+
${target}-version.h
78+
COMMAND ${CMAKE_COMMAND}
79+
-D CBMC_SOURCE_DIR=${CBMC_SOURCE_DIR}
80+
-D CUR=${CMAKE_CURRENT_BINARY_DIR}
81+
-P ${CMAKE_BINARY_DIR}/version.cmake
82+
)
83+
add_dependencies(${target} ${target}-version.h)
84+
endmacro()
85+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
86+
4487
add_subdirectory(src)
4588
add_subdirectory(regression)
4689
add_subdirectory(unit)

cbmc/CODING_STANDARD.md

+94
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,97 @@ or use a symbolic link. Then, when running git commit, you should get the
240240
linter output (if any) before being prompted to enter a commit message. To
241241
bypass the check (e.g. if there was a false positive), add the option
242242
`--no-verify`.
243+
244+
# CODE COVERAGE
245+
246+
Code coverage metrics are provided using gcov and lcov. Ensure that you have
247+
installed lcov from http://ltp.sourceforge.net/coverage/lcov.php note for
248+
ubuntu lcov is available in the standard apt-get repos.
249+
250+
To get coverage metrics run the following script from the regression directory:
251+
```
252+
get_coverage.sh
253+
```
254+
This will:
255+
1) Rebuild CBMC with gcov enabled
256+
2) Run all the regression tests
257+
3) Collate the coverage metrics
258+
4) Provide an HTML report of the current coverage
259+
260+
# USING CLANG-FORMAT
261+
262+
CBMC uses clang-format to ensure that the formatting of new patches is readable
263+
and consistent. There are two main ways of running clang-format: remotely, and
264+
locally.
265+
266+
## RUNNING CLANG-FORMAT REMOTELY
267+
268+
When patches are submitted to CBMC, they are automatically run through
269+
continuous integration (CI). One of the CI checks will run clang-format over
270+
the diff that your pull request introduces. If clang-format finds formatting
271+
issues at this point, the build will be failed, and a patch will be produced
272+
in the CI output that you can apply to your code so that it conforms to the
273+
style guidelines.
274+
275+
To apply the patch, copy and paste it into a local file (`patch.txt`) and then
276+
run:
277+
```
278+
patch -p1 -i patch.txt
279+
```
280+
Now, you can commit and push the formatting fixes.
281+
282+
## RUNNING CLANG-FORMAT LOCALLY
283+
284+
### INSTALLATION
285+
286+
To avoid waiting until you've made a PR to find formatting issues, you can
287+
install clang-format locally and run it against your code as you are working.
288+
289+
Different versions of clang-format have slightly different behaviors. CBMC uses
290+
clang-format-3.8 as it is available the repositories for Ubuntu 16.04 and
291+
Homebrew.
292+
To install on a Unix-like system, try installing using the system package
293+
manager:
294+
```
295+
apt-get install clang-format-3.8 # Run this on Ubuntu, Debian etc.
296+
brew install [email protected] # Run this on a Mac with Homebrew installed
297+
```
298+
299+
If your platform doesn't have a package for clang-format, you can download a
300+
pre-built binary, or compile clang-format yourself using the appropriate files
301+
from the [LLVM Downloads page](http://releases.llvm.org/download.html).
302+
303+
An installer for Windows (along with a Visual Studio plugin) can be found at
304+
the [LLVM Snapshot Builds page](http://llvm.org/builds/).
305+
306+
### FORMATTING A RANGE OF COMMITS
307+
308+
Clang-format is distributed with a driver script called git-clang-format-3.8.
309+
This script can be used to format git diffs (rather than entire files).
310+
311+
After committing some code, it is recommended to run:
312+
```
313+
git-clang-format-3.8 upstream/develop
314+
```
315+
*Important:* If your branch is based on a branch other than `upstream/develop`,
316+
use the name or checksum of that branch instead. It is strongly recommended to
317+
rebase your work onto the tip of the branch it's based on before running
318+
`git-clang-format` in this way.
319+
320+
### RETROACTIVELY FORMATTING INDIVIDUAL COMMITS
321+
322+
If your works spans several commits and you'd like to keep the formatting
323+
correct in each individual commit, you can automatically rewrite the commits
324+
with correct formatting.
325+
326+
The following command will stop at each commit in the range and run
327+
clang-format on the diff at that point. This rewrites git history, so it's
328+
*unsafe*, and you should back up your branch before running this command:
329+
```
330+
git filter-branch --tree-filter 'git-clang-format-3.8 upstream/develop' \
331+
-- upstream/develop..HEAD
332+
```
333+
*Important*: `upstream/develop` should be changed in *both* places in the
334+
command above if your work is based on a different branch. It is strongly
335+
recommended to rebase your work onto the tip of the branch it's based on before
336+
running `git-clang-format` in this way.

0 commit comments

Comments
 (0)