Skip to content

Commit f3bc3ed

Browse files
authored
Merge branch 'master' into invariantquery
2 parents 66ca36d + 82de696 commit f3bc3ed

File tree

11 files changed

+467
-56
lines changed

11 files changed

+467
-56
lines changed

README.md

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,28 @@ Sound Static Analysis of C for Memory Safety (Undefined Behavior)
44
### Quick start
55

66
The CodeHawk-C Analyzer consists of two parts:
7-
- A python front end (this repository) through which all user interaction
7+
- A Python front end (this repository) through which all user interaction
88
is performed, and
9-
- An ocaml abstract-interpretation engine that powers the analysis.
9+
- An OCaml abstract-interpretation engine that powers the analysis.
1010

11-
To use the CodeHawk-C Analyzer first clone or download the ocaml application
11+
To use the CodeHawk-C Analyzer first clone or download the OCaml application
1212
from
1313
```
1414
https://github.com/static-analysis-engineering/codehawk
1515
```
16-
and build according to the accompanying instructions given there.
17-
Then copy the following files from that build:
18-
```
19-
codehawk/CodeHawk/CHC/cchcil/parseFile
20-
codehawk/CodeHawk/CHC/cchcmdline/canalyzer
21-
```
22-
to the following location in this repository:
23-
```
24-
CodeHawk-C/chc/bin/linux/
25-
```
26-
or
27-
```
28-
CodeHawk-C/chc/bin/macOS
29-
```
30-
depending on the platform where the executables were built.
31-
Alternatively, you can edit the path to these two executables directly
32-
in chc/util/Config.py or chc/util/ConfigLocal.py, so there is no need
33-
to copy them or update them with each new version of the ocaml analyzer.
16+
and build with `dune` according to the accompanying instructions given there.
17+
18+
You can either:
19+
- Copy `chc/util/ConfigLocal.template` to `chc/util/ConfigLocal.py`
20+
in this repository, and edit the latter file to set the paths for
21+
`config.canalyzer` and `config.cparser` to the `dune`-built binaries,
22+
which should be in `your-path-to-codehawk/CodeHawk/_build/install/default/bin/`.
23+
This allows CodeHawk-C to automatically use newly-built versions of the
24+
OCaml analyzer.
25+
- Or, you can copy the `canalyzer` and `parseFile` binaries from that location
26+
into `chc/bin/linux/` or `chc/bin/macOS` within this repository.
27+
To allow CodeHawk-C to use newly-built versions of the OCaml analyzer,
28+
you will have to re-copy the binaries after every build.
3429

3530
Set the python path and path:
3631
```
@@ -47,8 +42,8 @@ which should show something like:
4742
Analyzer configuration:
4843
-----------------------
4944
platform : linux
50-
parser : /home/user/codehawk/CodeHawk/CHC/cchcil/parseFile (found)
51-
analyzer : /home/user/codehawk/CodeHawk/CHC/cchcmdline/canalyzer (found)
45+
parser : /home/user/codehawk/CodeHawk/_build/install/default/bin/parseFile (found)
46+
analyzer : /home/user/codehawk/CodeHawk/_build/install/default/bin/canalyzer (found)
5247
5348
summaries: /home/user/CodeHawk-C/chc/summaries/cchsummaries.jar (found)
5449
```
@@ -60,9 +55,9 @@ Interaction with the analyzer is primarily through the command-line interpreter
6055
```
6156
> chkc c-file parse <filename>
6257
> chkc c-file analyze <filename>
63-
> chkc c-file report-file <filename>
58+
> chkc c-file report <filename>
6459
```
65-
The first command preprocesses the file with gcc; the preprocessed file (.i file)
60+
The first command preprocesses the file with `cc`; the preprocessed file (.i file)
6661
is then parsed with **parseFile** (a wrapper for goblint-cil,
6762
https://opam.ocaml.org/packages/goblint-cil/).
6863
The second command analyzes the parsed artifacts, and the third command (and

chc/app/CPrettyPrinter.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,12 @@ def visit_funarg(self, funarg: CT.CFunArg) -> None:
310310
self.funtypptr_with_name(ptx, funarg.name)
311311
return
312312

313-
if (
314-
argtyp.attributes.length > 0
315-
and argtyp.attributes.attributes[0].name == "arraylen"):
316-
self.ptrarg_with_attribute_length(
317-
ptargtyp, argtyp.attributes.attributes[0], funarg.name)
318-
return
313+
# if (
314+
# argtyp.attributes.length > 0
315+
# and argtyp.attributes.attributes[0].name == "arraylen"):
316+
# self.ptrarg_with_attribute_length(
317+
# ptargtyp, argtyp.attributes.attributes[0], funarg.name)
318+
# return
319319

320320
funarg.typ.accept(self)
321321
self.ccode.write(" ")

chc/app/CTyp.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ def is_pointer(self) -> bool:
184184
def is_struct(self) -> bool:
185185
return False
186186

187+
@property
188+
def is_union(self) -> bool:
189+
return False
190+
187191
@property
188192
def is_void(self) -> bool:
189193
return False
@@ -388,6 +392,10 @@ def name(self) -> str:
388392
def is_struct(self) -> bool:
389393
return self.compinfo.is_struct
390394

395+
@property
396+
def is_union(self) -> bool:
397+
return not self.compinfo.is_struct
398+
391399
def accept(self, visitor: "CVisitor") -> None:
392400
visitor.visit_comptyp(self)
393401

chc/cmdline/ParseManager.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,32 +221,32 @@ def save_semantics(self) -> None:
221221
)
222222
os.chdir(cwd)
223223

224-
def preprocess_file_with_gcc(
224+
def preprocess_file_with_cc(
225225
self,
226226
cfilename: str,
227227
copyfiles: bool = True,
228228
moreoptions: List[str] = []) -> str:
229-
"""Invoke gcc preprocessor on c source file.
229+
"""Invoke C preprocessor on c source file.
230230
231231
Args:
232232
cfilename: c source code filename relative to cpath
233233
moreoptions: list of additional options to be given to the
234234
preprocessor
235235
236236
Effects:
237-
invokes the gcc preprocessor on the c source file and optionally
237+
invokes the C preprocessor on the c source file and optionally
238238
copies the original source file and the generated .i file to the
239-
tgtpath/sourcefiles directory
239+
tgtpath/sourcefiles directory.
240240
"""
241241

242-
chklogger.logger.info("Preprocess file with gcc: %s", cfilename)
242+
chklogger.logger.info("Preprocess file with cc: %s", cfilename)
243243
cwd = os.getcwd()
244244
mac = self.config.platform == "mac"
245245
ifilename = cfilename[:-1] + "i"
246246
macoptions = [
247247
"-U___BLOCKS___", "-D_DARWIN_C_SOURCE", "-D_FORTIFY_SOURCE=0"]
248248
cmd = [
249-
"gcc",
249+
"cc",
250250
"-fno-inline",
251251
"-fno-builtin",
252252
"-E",
@@ -498,7 +498,7 @@ def parse_ifiles(self, copyfiles: bool = True) -> None:
498498
targetfiles.save_xml_file(self.analysisresultspath)
499499

500500
def parse_cfiles(self, copyfiles: bool = True) -> None:
501-
"""Preprocess (with gcc) and run the CodeHawk C parser on all .c
501+
"""Preprocess and run the CodeHawk C parser on all .c
502502
files in the directory."""
503503

504504
os.chdir(self.projectpath)
@@ -509,7 +509,7 @@ def parse_cfiles(self, copyfiles: bool = True) -> None:
509509
fname = self.normalize_filename(os.path.join(d, fname))
510510
if fname.startswith("semantics"):
511511
continue
512-
ifilename = self.preprocess_file_with_gcc(fname, copyfiles)
512+
ifilename = self.preprocess_file_with_cc(fname, copyfiles)
513513
self.parse_ifile(ifilename)
514514
targetfiles.add_file(self.normalize_filename(fname))
515515
targetfiles.save_xml_file(self.analysisresultspath)
@@ -585,7 +585,7 @@ def save_xml_file(self, tgtpath: str) -> None:
585585

586586
if __name__ == "__main__":
587587

588-
# preprocess and parse single files with gcc
588+
# preprocess and parse single files with cc
589589
thisdir = os.path.dirname(os.path.abspath(__file__))
590590
topdir = os.path.dirname(os.path.dirname(thisdir))
591591
testsdir = os.path.join(topdir, "tests")
@@ -594,5 +594,5 @@ def save_xml_file(self, tgtpath: str) -> None:
594594
pm = ParseManager(id115dir, "kendra115", id115dir)
595595
pm.initialize_paths()
596596
for f in ["id115.c", "id116.c", "id117.c", "id118.c"]:
597-
ifilename = pm.preprocess_file_with_gcc(f)
597+
ifilename = pm.preprocess_file_with_cc(f)
598598
pm.parse_ifile(ifilename)

0 commit comments

Comments
 (0)