├── .gitignore ├── LICENSE ├── README ├── SConstruct ├── _tags ├── abstract_c ├── architecture_spec.v ├── architectures.v ├── frontend.v ├── frontend_sound.v ├── interpreter.v └── natural_type_environment.v ├── axiomatic ├── assertions.v ├── assignments_separation.v ├── axiomatic.v ├── axiomatic_adequate.v ├── axiomatic_expressions.v ├── axiomatic_expressions_help.v ├── axiomatic_functions.v ├── axiomatic_graph.v ├── axiomatic_simple.v ├── axiomatic_statements.v ├── example_gcd.v └── expression_eval_separation.v ├── core_c ├── assignments.v ├── contexts.v ├── executable.v ├── executable_complete.v ├── executable_sound.v ├── expression_eval.v ├── expression_eval_smallstep.v ├── expressions.v ├── operations.v ├── restricted_smallstep.v ├── smallstep.v ├── state.v ├── statements.v ├── type_preservation.v ├── type_system.v └── type_system_decidable.v ├── doc ├── index.html ├── scripts.js └── style.css ├── extraction └── extraction.v ├── include ├── limits.h ├── prelude.c ├── stddef.h ├── stdio.h └── stdlib.h ├── memory ├── addresses.v ├── aliasing.v ├── base_values.v ├── bits.v ├── constant_propagation.v ├── fragmented.v ├── memory.v ├── memory_basics.v ├── memory_map.v ├── memory_trees.v ├── permission_bits.v ├── pointer_bits.v ├── pointer_casts.v ├── pointers.v ├── references.v └── values.v ├── memory_refinements ├── addresses_refine.v ├── base_values_refine.v ├── bits_refine.v ├── memory_injections.v ├── memory_map_refine.v ├── memory_refine.v ├── memory_trees_refine.v ├── permission_bits_refine.v ├── pointer_bits_refine.v ├── pointers_refine.v ├── refinement_classes.v ├── refinements.v └── values_refine.v ├── memory_separation ├── cmap.v ├── ctrees.v ├── flat_cmap.v ├── memory_map_separation.v ├── memory_separation.v ├── memory_singleton.v ├── memory_trees_separation.v ├── permission_bits_separation.v └── values_separation.v ├── parser ├── Cabs.ml ├── Cabshelper.ml ├── Cerrors.ml ├── Cerrors.mli ├── Lexer.mli ├── Lexer.mll ├── Main.ml ├── Parse_aux.ml ├── Parse_aux.mli └── Parser.mly ├── prelude ├── base.v ├── error.v ├── list.v ├── option.v ├── optionmap.v ├── orders.v ├── prelude.v ├── stringmap.v └── tactics.v ├── refinements ├── operations_refine.v ├── refinement_preservation.v └── refinement_system.v ├── separation ├── permissions.v ├── separation.v └── separation_instances.v ├── site_scons └── site_tools │ └── Coq.py ├── tests ├── defined-ellison │ ├── LICENSE │ └── unsorted │ │ ├── j004a.c │ │ ├── j004b.c │ │ ├── j004c.c │ │ ├── j004d.c │ │ ├── j008.c │ │ ├── j009.c │ │ ├── j010.c │ │ ├── j011.c │ │ ├── j012.c │ │ ├── j013.c │ │ ├── j014.c │ │ ├── j015.c │ │ ├── j016.c │ │ ├── j017.c │ │ ├── j018.c │ │ ├── j019.c │ │ ├── j020.c │ │ ├── j021.c │ │ ├── j022.c │ │ ├── j023.c │ │ ├── j024.c │ │ ├── j025.c │ │ ├── j026.c │ │ ├── j032.c │ │ ├── j033.c │ │ ├── j035.c │ │ ├── j036.c │ │ ├── j037.c │ │ ├── j038.c │ │ ├── j039.c │ │ ├── j040.c │ │ ├── j041.c │ │ ├── j042.c │ │ ├── j043.c │ │ ├── j044.c │ │ ├── j045.c │ │ ├── j046.c │ │ ├── j047.c │ │ ├── j048.c │ │ ├── j049.c │ │ ├── j050.c │ │ ├── j051.c │ │ ├── j052.c │ │ ├── j053.c │ │ ├── j054.c │ │ ├── j055.c │ │ ├── j056.c │ │ ├── j057.c │ │ ├── j058.c │ │ ├── j059.c │ │ ├── j060.c │ │ ├── j061.c │ │ ├── j062.c │ │ ├── j063.c │ │ ├── j064.c │ │ ├── j065.c │ │ ├── j066.c │ │ ├── j067.c │ │ ├── j068.c │ │ ├── j069.c │ │ ├── j070.c │ │ ├── j071.c │ │ ├── j072.c │ │ ├── j073-link1.c │ │ ├── j073-link2.c │ │ ├── j074.c │ │ ├── j075.c │ │ ├── j076.c │ │ ├── j077.c │ │ ├── j078.c │ │ ├── j079.c │ │ ├── j080.c │ │ ├── j081.c │ │ ├── j082.c │ │ ├── j083.c │ │ ├── j084-link1.c │ │ ├── j084-link2.c │ │ ├── j085.c │ │ ├── j086.c │ │ ├── j087.c │ │ ├── j088.c │ │ └── j089.c ├── defined │ ├── abort.c │ ├── assignment_plus.c │ ├── big_array.c │ ├── boring_slow_nondet.c │ ├── byte_copy.c │ ├── duff.c │ ├── end_of_array.c │ ├── fib.c │ ├── gcd.c │ ├── global_initializer.c │ ├── incomplete_typedef.c │ ├── int_regehr.c │ ├── malloc_nondet.c │ ├── memoization.c │ ├── mutual_recursion.c │ ├── my_memcpy.c │ ├── no_return.c │ ├── non_det_function_call.c │ ├── non_det_prinfs.c │ ├── overflow.c │ ├── pointer_comp.c │ ├── recursion.c │ ├── return_pointer.c │ └── shadowing.c ├── slow │ └── Y.c ├── undefined-ellison │ ├── LICENSE │ └── unsorted │ │ ├── j004a.c │ │ ├── j004b.c │ │ ├── j004c.c │ │ ├── j004d.c │ │ ├── j004e.c │ │ ├── j004f.c │ │ ├── j004g.c │ │ ├── j004h.c │ │ ├── j008a.c │ │ ├── j008b.c │ │ ├── j008c.c │ │ ├── j008d.c │ │ ├── j008e.c │ │ ├── j008f.c │ │ ├── j009a.c │ │ ├── j009b.c │ │ ├── j009c.c │ │ ├── j009d.c │ │ ├── j009e.c │ │ ├── j009f.c │ │ ├── j009g.c │ │ ├── j009h.c │ │ ├── j009i.c │ │ ├── j009j.c │ │ ├── j010a.c │ │ ├── j010b.c │ │ ├── j010c.c │ │ ├── j010d.c │ │ ├── j010e.c │ │ ├── j010f.c │ │ ├── j011a.c │ │ ├── j011b.c │ │ ├── j012a.c │ │ ├── j013a.c │ │ ├── j014a.c │ │ ├── j014b.c │ │ ├── j014c.c │ │ ├── j014d.c │ │ ├── j015a.c │ │ ├── j015b.c │ │ ├── j015c.c │ │ ├── j015d-link1.c │ │ ├── j015d-link2.c │ │ ├── j016a.c │ │ ├── j016b.c │ │ ├── j017a.c │ │ ├── j017b.c │ │ ├── j017c.c │ │ ├── j018a.c │ │ ├── j019a.c │ │ ├── j019b.c │ │ ├── j020a.c │ │ ├── j020b.c │ │ ├── j021a.c │ │ ├── j021b.c │ │ ├── j021c.c │ │ ├── j021d.c │ │ ├── j021e.c │ │ ├── j022a.c │ │ ├── j022b.c │ │ ├── j023a.c │ │ ├── j023b.c │ │ ├── j023c.c │ │ ├── j023d.c │ │ ├── j023e.c │ │ ├── j023f.c │ │ ├── j024a.c │ │ ├── j025a.c │ │ ├── j026a.c │ │ ├── j026b.c │ │ ├── j026c.c │ │ ├── j032a.c │ │ ├── j032b.c │ │ ├── j033a.c │ │ ├── j033b.c │ │ ├── j033c.c │ │ ├── j035a.c │ │ ├── j035b.c │ │ ├── j035c.c │ │ ├── j035d.c │ │ ├── j035e.c │ │ ├── j035f.c │ │ ├── j036a.c │ │ ├── j036b.c │ │ ├── j036c.c │ │ ├── j037a.c │ │ ├── j037b.c │ │ ├── j037c.c │ │ ├── j037d.c │ │ ├── j037e.c │ │ ├── j037f.c │ │ ├── j037g.c │ │ ├── j037h.c │ │ ├── j038a.c │ │ ├── j038b.c │ │ ├── j038c.c │ │ ├── j039a.c │ │ ├── j039b.c │ │ ├── j039c-link1.c │ │ ├── j039c-link2.c │ │ ├── j039d-link1.c │ │ ├── j039d-link2.c │ │ ├── j039e-link1.c │ │ ├── j039e-link2.c │ │ ├── j040a.c │ │ ├── j040b.c │ │ ├── j040c.c │ │ ├── j041a.c │ │ ├── j041b-link1.c │ │ ├── j041b-link2.c │ │ ├── j041c-link1.c │ │ ├── j041c-link2.c │ │ ├── j041d-link1.c │ │ ├── j041d-link2.c │ │ ├── j042a.c │ │ ├── j042b.c │ │ ├── j043a.c │ │ ├── j043b.c │ │ ├── j044a.c │ │ ├── j044b.c │ │ ├── j044c.c │ │ ├── j044d.c │ │ ├── j045a.c │ │ ├── j045b.c │ │ ├── j045c.c │ │ ├── j045d.c │ │ ├── j045e.c │ │ ├── j045f.c │ │ ├── j046a.c │ │ ├── j046b.c │ │ ├── j046c.c │ │ ├── j047a.c │ │ ├── j047b.c │ │ ├── j047c.c │ │ ├── j047d.c │ │ ├── j048a.c │ │ ├── j048b.c │ │ ├── j049a.c │ │ ├── j049b.c │ │ ├── j049c.c │ │ ├── j050a.c │ │ ├── j051a.c │ │ ├── j051b.c │ │ ├── j051c.c │ │ ├── j051d.c │ │ ├── j052a.c │ │ ├── j052b.c │ │ ├── j053a.c │ │ ├── j053b.c │ │ ├── j053c.c │ │ ├── j054a.c │ │ ├── j054b.c │ │ ├── j054c.c │ │ ├── j055a.c │ │ ├── j055b.c │ │ ├── j055c.c │ │ ├── j055d.c │ │ ├── j055e.c │ │ ├── j056a.c │ │ ├── j056b.c │ │ ├── j056c.c │ │ ├── j057a.c │ │ ├── j057b.c │ │ ├── j058a.c │ │ ├── j058b.c │ │ ├── j058c.c │ │ ├── j058d.c │ │ ├── j058e.c │ │ ├── j059a.c │ │ ├── j059b.c │ │ ├── j059c.c │ │ ├── j059d.c │ │ ├── j059e.c │ │ ├── j059f.c │ │ ├── j060a.c │ │ ├── j060b.c │ │ ├── j061a.c │ │ ├── j061b.c │ │ ├── j062a.c │ │ ├── j062b.c │ │ ├── j063a.c │ │ ├── j063b.c │ │ ├── j064a.c │ │ ├── j064b.c │ │ ├── j065a.c │ │ ├── j065b.c │ │ ├── j066a.c │ │ ├── j066b.c │ │ ├── j066c.c │ │ ├── j066d.c │ │ ├── j067a.c │ │ ├── j067b.c │ │ ├── j067c.c │ │ ├── j067d.c │ │ ├── j068a.c │ │ ├── j068b.c │ │ ├── j068c.c │ │ ├── j069a.c │ │ ├── j069b.c │ │ ├── j069c.c │ │ ├── j070a.c │ │ ├── j071a.c │ │ ├── j071b.c │ │ ├── j071c.c │ │ ├── j072a.c │ │ ├── j072b.c │ │ ├── j073a-link1.c │ │ ├── j073a-link2.c │ │ ├── j074a.c │ │ ├── j074b.c │ │ ├── j074c.c │ │ ├── j074d.c │ │ ├── j075a.c │ │ ├── j075b.c │ │ ├── j076a.c │ │ ├── j076b.c │ │ ├── j076c.c │ │ ├── j076d.c │ │ ├── j076e.c │ │ ├── j076f.c │ │ ├── j076g.c │ │ ├── j076h.c │ │ ├── j077a.c │ │ ├── j077b.c │ │ ├── j077c.c │ │ ├── j078a.c │ │ ├── j078b.c │ │ ├── j078c.c │ │ ├── j078d.c │ │ ├── j078e.c │ │ ├── j078f.c │ │ ├── j078g.c │ │ ├── j078h.c │ │ ├── j078i.c │ │ ├── j078j.c │ │ ├── j079a.c │ │ ├── j079b.c │ │ ├── j079c.c │ │ ├── j079d.c │ │ ├── j079e.c │ │ ├── j079f.c │ │ ├── j079g.c │ │ ├── j079h.c │ │ ├── j079i.c │ │ ├── j080a.c │ │ ├── j081a.c │ │ ├── j081b.c │ │ ├── j082a.c │ │ ├── j082b.c │ │ ├── j083a.c │ │ ├── j083b.c │ │ ├── j083c.c │ │ ├── j084a.c │ │ ├── j084b.c │ │ ├── j084c.c │ │ ├── j084d.c │ │ ├── j084e.c │ │ ├── j084f-link1.c │ │ ├── j084f-link2.c │ │ ├── j085a.c │ │ ├── j085b.c │ │ ├── j085c.c │ │ ├── j086a.c │ │ ├── j086b.c │ │ ├── j087a.c │ │ ├── j088a.c │ │ ├── j088b.c │ │ ├── j089a.c │ │ ├── j089b.c │ │ └── j089c.c └── undefined │ ├── abort.c │ ├── alias.c │ ├── big_constant.c │ ├── chucky.c │ ├── compare_after_free.c │ ├── end_of_array.c │ ├── goto_out_of_life.c │ ├── incomplete_function.c │ ├── indet_byte_read.c │ ├── int_regehr1.c │ ├── int_regehr2.c │ ├── int_regehr3.c │ ├── int_regehr4.c │ ├── int_regehr5.c │ ├── int_regehr6.c │ ├── int_regehr7.c │ ├── int_regehr8.c │ ├── local_unitialized.c │ ├── no_return.c │ ├── overflow.c │ ├── overlapping_array.c │ ├── pointer_comp.c │ ├── sequence_point_violation.c │ ├── type_punning.c │ ├── wrong_args_prototypes.c │ └── wrong_return_prototypes.c ├── types ├── integer_coding.v ├── integer_operations.v ├── type_classes.v ├── type_environment.v └── types.v └── utils ├── coq2html.mll └── linecount.ml /.gitignore: -------------------------------------------------------------------------------- 1 | *.vo 2 | *.vos 3 | *.vok 4 | *.glob 5 | .sconsign.dblite 6 | deps 7 | old/* 8 | coqidescript 9 | \#*\# 10 | *.pyc 11 | *~ 12 | *.cmi 13 | *.cmx 14 | *.cmo 15 | *.o 16 | utils/coq2html 17 | utils/coq2html.ml 18 | doc/ch2o.*.html 19 | *.cache 20 | *.broken 21 | broken/* 22 | *.patch 23 | parser/Extracted.* 24 | parser/Lexer.ml 25 | parser/Parser.ml 26 | parser/Parser.mli 27 | parser/Include.* 28 | _build/ 29 | ch2o 30 | *.native 31 | *.byte 32 | a.out 33 | *.aux 34 | .coq-native/ 35 | _opam 36 | .vscode 37 | Makefile.coq 38 | Makefile.coq.conf 39 | .Makefile.coq.d -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | PREREQUISITES 2 | ------------- 3 | 4 | This version is known to compile with: 5 | 6 | - Coq 8.13.2 or higher 7 | - SCons 4.0.1.post1 8 | - OCaml 4.12 9 | - OCaml-Num 1.4.2 10 | - OCamlbuild 0.14.0 11 | - GNU C preprocessor 8.3.0 12 | - stdpp 1.6.0 13 | 14 | BUILDING INSTRUCTIONS 15 | --------------------- 16 | 17 | Say "scons" to build the full library, or "scons some_module.vo" to just 18 | build some_module.vo (and its dependencies). 19 | 20 | In addition to common Make options like -j N and -k, SCons supports some 21 | useful options of its own, such as --debug=time, which displays the time 22 | spent executing individual build commands. 23 | 24 | scons -c replaces Make clean 25 | 26 | -------------------------------------------------------------------------------- /SConstruct: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2012-2015, Robbert Krebbers. 2 | # This file is distributed under the terms of the BSD license. 3 | import os, glob, string 4 | 5 | modules = ["prelude", "separation", "types", "memory", "refinements", 6 | "memory_refinements", "memory_separation", "core_c", "abstract_c", 7 | "axiomatic", "extraction"] 8 | Rs = '-R . ch2o' 9 | env = DefaultEnvironment(ENV = os.environ,tools=['default', 'Coq'], COQFLAGS=Rs) 10 | 11 | # Coq dependencies 12 | vs = [x for m in modules for x in glob.glob(m + '/*.v')] 13 | if os.system('coqdep ' + Rs + ' ' + ' '.join(map(str, vs)) + ' > deps'): Exit(2) 14 | ParseDepends('deps') 15 | 16 | # coq2html 17 | env.Command('./utils/coq2html.ml', 'utils/coq2html.mll', 18 | 'ocamllex -q $SOURCE -o $TARGET') 19 | t = env.Command('utils/coq2html', 'utils/coq2html.ml', 20 | 'ocamlopt -o $TARGET str.cmxa $SOURCE') 21 | env.Clean(t, 'utils/coq2html.o') 22 | env.Clean(t, 'utils/coq2html.cmi') 23 | env.Clean(t, 'utils/coq2html.cmx') 24 | 25 | # Coq files 26 | for v in vs: 27 | env.Coq(v) 28 | h = 'doc/ch2o.' + os.path.splitext(v)[0].replace('/','.') + '.html' 29 | glo = os.path.splitext(v)[0] + '.glob' 30 | env.Command(h, ['utils/coq2html',v,glo],'utils/coq2html -o '+h+' '+v) 31 | 32 | # Parser 33 | include = env.Command('parser/Include.ml', '', 34 | 'echo let include_dir = ref \\"' + os.getcwd() + '/include\\" > $TARGET') 35 | main = env.Command(['ch2o','ch2o.byte'], '', 36 | 'ocamlbuild -j 2 -libs nums,str,unix\ 37 | -I parser parser/Main.native parser/Main.byte &&\ 38 | mv Main.native ch2o && mv Main.byte ch2o.byte') 39 | AlwaysBuild(main) 40 | env.Clean('extraction/extraction.vo', 'parser/Extracted.ml') 41 | env.Clean('extraction/extraction.vo', 'parser/Extracted.mli') 42 | env.Depends(main, include) 43 | env.Depends(main, 'extraction/extraction.vo') 44 | env.Clean(main, '_build') 45 | 46 | # Coqidescript 47 | env.CoqIdeScript('coqidescript', []) 48 | -------------------------------------------------------------------------------- /_tags: -------------------------------------------------------------------------------- 1 | "parser/Main.ml": pp(grep -v '^#') 2 | -------------------------------------------------------------------------------- /abstract_c/architectures.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Export architecture_spec. 4 | 5 | Definition ilp32 : architecture_sizes. 6 | Proof. 7 | refine {| 8 | arch_char_bits := 8; 9 | arch_size k := 10 | match k with 11 | | CharRank => 1 | ShortRank => 2 | IntRank | LongRank | PtrRank => 4 12 | | LongLongRank => 8 13 | end; 14 | arch_align k := 15 | match k with 16 | | CharRank => 1 | ShortRank => 2 | IntRank | LongRank | PtrRank => 4 17 | | LongLongRank => 8 18 | end 19 | |}; by apply (bool_decide_unpack _); vm_compute. 20 | Defined. 21 | 22 | (** See http://en.wikipedia.org/wiki/64-bit_computing#64-bit_data_models *) 23 | (** LLP64 is used by Microsoft Windows (x86-64 and IA-64) *) 24 | Definition llp64 : architecture_sizes. 25 | Proof. 26 | refine {| 27 | arch_char_bits := 8; 28 | arch_size k := 29 | match k with 30 | | CharRank => 1 | ShortRank => 2 | IntRank | LongRank => 4 31 | | PtrRank | LongLongRank => 8 32 | end; 33 | arch_align k := 34 | match k with 35 | | CharRank => 1 | ShortRank => 2 | IntRank | LongRank => 4 36 | | PtrRank | LongLongRank => 8 37 | end 38 | |}; by apply (bool_decide_unpack _); vm_compute. 39 | Defined. 40 | 41 | (** LP64 is used by most Unix and Unix-like systems, e.g. Solaris, Linux, BSD, 42 | and OS X; z/OS *) 43 | Definition lp64 : architecture_sizes. 44 | Proof. 45 | refine {| 46 | arch_char_bits := 8; 47 | arch_size k := 48 | match k with 49 | | CharRank => 1 | ShortRank => 2 | IntRank => 4 50 | | LongRank | PtrRank | LongLongRank => 8 51 | end; 52 | arch_align k := 53 | match k with 54 | | CharRank => 1 | ShortRank => 2 | IntRank => 4 55 | | LongRank | PtrRank | LongLongRank => 8 56 | end 57 | |}; by apply (bool_decide_unpack _); vm_compute. 58 | Defined. 59 | -------------------------------------------------------------------------------- /abstract_c/interpreter.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | From stdpp Require Import hashset streams. 4 | Require Import String stringmap. 5 | Require Export executable frontend architecture_spec. 6 | 7 | Local Open Scope string_scope. 8 | Local Open Scope list_scope. 9 | Local Open Scope ctype_scope. 10 | Local Coercion Z.of_nat: nat >-> Z. 11 | 12 | Record istate (K E : iType) : iType := IState { 13 | events_new : list E; (**i the events generated in the last step *) 14 | events_all : list E; (**i all previously generated events, 15 | including those in the last step *) 16 | sem_state : state K 17 | }. 18 | Arguments IState {_ _} _ _ _. 19 | #[global] Instance istate_dec {K E} `{Env K, EqDecision E}: EqDecision (istate K E). 20 | Proof. solve_decision. Defined. 21 | 22 | Section interpreter. 23 | Context (A : architecture). 24 | Notation K := (arch_rank A). 25 | Context `{EqDecision E}. 26 | Context (e : ∀ `{Env K}, env K → state K → list E). 27 | Notation M := (error (frontend_state K) string). 28 | 29 | Fixpoint interpreter_args_go (args : list (list Z)) : M (list (val K)) := 30 | match args with 31 | | [] => mret [ptrV (NULL (charT{K}))] 32 | | zs :: args => 33 | '(v,n) ← error_of_option (to_string_const zs) 34 | "char of string constant out of range"; 35 | o ← insert_object perm_full v; 36 | vs ← interpreter_args_go args; 37 | mret (ptrV (Ptr (addr_top_array o (charT{K}) (Z.of_nat n))) :: vs) 38 | end. 39 | Definition interpreter_args (σs : list (type K)) 40 | (args : list (list Z)) : M (list (val K)) := 41 | if decide (σs = []) then mret (M := M) [] 42 | else if decide (σs = [sintT; charT{K}.*.*])%T then 43 | vs ← interpreter_args_go args; 44 | o ← insert_object perm_full (VArray (charT{K}.*) vs); 45 | mret (M := M) [intV{sintT} (length vs); 46 | ptrV (Ptr (addr_top_array o (charT{K}.*) (length vs)))] 47 | else fail "function `main` should have argument types `int` and `char*`". 48 | Definition interpreter_initial (Θ : list (string * decl)) 49 | (args : list (list Z)) : M (istate K E) := 50 | _ ← alloc_program Θ; 51 | Δg ← gets to_globals; 52 | '(_,σs,σ,_) ← error_of_option (Δg !! "main" ≫= maybe4 Fun) 53 | ("function `main` undeclared`"); 54 | guard (σ = sintT%T ∨ σ = uintT%T) with 55 | ("function `main` should have return type `int`"); 56 | vs ← interpreter_args σs args; 57 | m ← gets to_mem; 58 | mret (IState [] [] (initial_state m "main" vs)). 59 | Definition interpreter_initial_eval (Θ : list (string * decl)) 60 | (args : list (list Z)) : string + istate K E := 61 | error_eval (interpreter_initial Θ args) ∅. 62 | 63 | Definition cexec' (Γ : env K) (δ : funenv K) 64 | (iS : istate K E) : listset (istate K E) := 65 | let (_,εs,S) := iS in 66 | (λ S_new, 67 | let εs_new := e _ Γ S_new in IState εs_new (εs ++ εs_new) S_new 68 | ) <$> cexec Γ δ S. 69 | 70 | Context (hash : istate K E → Z). 71 | Definition cexec_all (Γ : env K) (δ : funenv K) (iS : istate K E) : 72 | listset (istate K E) * listset (istate K E) := 73 | let nexts := cexec' Γ δ iS in 74 | if decide (nexts ≡ ∅) then (∅, {[ iS ]}) else (nexts, ∅). 75 | Definition csteps_exec_all (Γ : env K) (δ : funenv K) : 76 | listset (istate K E) → 77 | stream (listset (istate K E) * listset (istate K E)) := 78 | cofix go iSs := 79 | let nexts := cexec_all Γ δ <$> iSs in 80 | let reds := listset_normalize hash (nexts ≫= fst) in 81 | let nfs := listset_normalize hash (nexts ≫= snd) in 82 | (reds,nfs) :.: go reds. 83 | Definition interpreter_all 84 | (Θ : list (string * decl)) (args : list (list Z)) : 85 | M (stream (listset (istate K E) * listset (istate K E))) := 86 | iS ← interpreter_initial Θ args; 87 | Γ ← gets to_env; δ ← gets to_funenv; 88 | mret (csteps_exec_all Γ δ {[ iS ]}). 89 | Definition interpreter_all_eval 90 | (Θ : list (string * decl)) (args : list (list Z)) : 91 | string + stream (listset (istate K E) * listset (istate K E)) := 92 | error_eval (interpreter_all Θ args) ∅. 93 | 94 | Context (rand : nat → nat). 95 | Definition csteps_exec_rand (Γ : env K) (δ : funenv K) : 96 | istate K E → stream (istate K E + istate K E) := 97 | cofix go iS := 98 | match listset_car (cexec' Γ δ iS) with 99 | | [] => srepeat (inr iS) 100 | | (iS' :: _) as iSs => 101 | let next := default iS' (iSs !! rand (length iSs)) in 102 | inl next :.: go next 103 | end. 104 | Definition interpreter_rand 105 | (Θ : list (string * decl)) (args : list (list Z)) : 106 | M (stream (istate K E + istate K E)) := 107 | iS ← interpreter_initial Θ args; 108 | Γ ← gets to_env; δ ← gets to_funenv; 109 | mret (csteps_exec_rand Γ δ iS). 110 | Definition interpreter_rand_eval 111 | (Θ : list (string * decl)) (args : list (list Z)) : 112 | string + stream (istate K E + istate K E) := 113 | error_eval (interpreter_rand Θ args) ∅. 114 | End interpreter. 115 | -------------------------------------------------------------------------------- /axiomatic/assignments_separation.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Import memory_separation assignments. 4 | 5 | Lemma assign_sem_subseteq `{EnvSpec K} Γ Δ m1 m2 a v ass va v' τ1 τ2 : 6 | ✓ Γ → ✓{Γ,Δ} m1 → assign_typed τ1 τ2 ass → 7 | (Γ,Δ) ⊢ a : TType τ1 → (Γ,Δ) ⊢ v : τ2 → 8 | assign_sem Γ m1 a v ass va v' → m1 ⊆ m2 → assign_sem Γ m2 a v ass va v'. 9 | Proof. 10 | destruct 3; inversion 3; econstructor; simplify_type_equality'; eauto 8 using 11 | mem_lookup_subseteq, val_cast_ok_weaken, val_binop_ok_weaken, 12 | cmap_subseteq_index_alive, mem_lookup_typed, val_binop_typed. 13 | Qed. -------------------------------------------------------------------------------- /axiomatic/axiomatic_adequate.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Export axiomatic. 4 | Require Import axiomatic_graph type_preservation. 5 | 6 | Local Hint Extern 1 (## _) => solve_mem_disjoint: core. 7 | Local Hint Extern 1 (sep_valid _) => solve_mem_disjoint: core. 8 | Local Hint Extern 1 (_ ≤ _) => lia: core. 9 | 10 | (** * Adequacy *) 11 | (** We prove that the Hoare judgment indeed implies partial program 12 | correctness. *) 13 | Lemma ax_stmt_adequate `{EnvSpec K} Γ δ Q s m S' cmτ : 14 | ✓ Γ → ✓{Γ,'{m}} δ → ✓{Γ} m → mem_locks m = ∅ → (Γ,'{m},[]) ⊢ s : cmτ → 15 | Γ\ δ ⊨ₛ {{ assert_eq_mem (cmap_erase m) }} s {{ Q }} → 16 | Γ\ δ ⊢ₛ State [] (Stmt ↘ s) m ⇒* S' → 17 | (**i 1.) *) (∃ n' m', 18 | S' = State [] (Stmt ↗ s) m' ∧ 19 | assert_holds (Q voidV) Γ '{m'} δ [] n' (cmap_erase m')) ∨ 20 | (**i 2.) *) (∃ n' m' v, 21 | S' = State [] (Stmt (⇈ v) s) m' ∧ 22 | assert_holds (Q v) Γ '{m'} δ [] n' (cmap_erase m')) ∨ 23 | (**i 3.) *) red (cstep Γ δ) S'. 24 | Proof. 25 | intros ?. revert m S'. cut (∀ P n1 n2 k φ m S' τf, 26 | ✓{Γ,'{m} } δ → 27 | (Γ,'{m},(locals k).*2) ⊢ φ : τf → (Γ,'{m}) ⊢ k : τf ↣ Stmt_type cmτ → 28 | ✓{Γ} m → maybe Undef φ = None → focus_locks_valid φ m → 29 | ax_graph ax_disjoint_cond (ax_stmt_post (dassert_pack_top P Q) s cmτ) 30 | Γ δ '{m} [] (n1 + n2) k φ m → 31 | Γ\ δ\ [] ⊢ₛ State k φ m ⇒^n1 S' → ∃ k' φ' m', 32 | S' = State k' φ' m' ∧ 33 | maybe Undef φ' = None ∧ focus_locks_valid φ' m' ∧ ✓{Γ} m' ∧ 34 | ax_graph ax_disjoint_cond (ax_stmt_post (dassert_pack_top P Q) s cmτ) 35 | Γ δ '{m'} [] n2 k' φ' m'). 36 | { intros help m S' ???? Hax p. 37 | apply csteps_rcsteps, rtc_bsteps in p; destruct p as [n p]. 38 | destruct (help (assert_eq_mem (cmap_erase m)) n 1 [] (Stmt ↘ s) m S' 39 | (Stmt_type cmτ)) as (k'&φ'&m'&->&?&?&?&Hax'); done || eauto. 40 | { by repeat typed_constructor. } 41 | { typed_constructor. } 42 | { by apply Hax. } 43 | inversion Hax' as [|??? [d' ????]|???? Hred]; clear Hax'; subst. 44 | { destruct d'; naive_solver. } 45 | do 2 right; apply (red_subrel (rcstep Γ δ [])); auto using rcstep_cstep. 46 | apply (Hred '{m'} 0 _ ∅); auto. 47 | split; rewrite ?sep_right_id by auto; 48 | eauto using cmap_valid_memenv_valid, cmap_empty_valid. } 49 | intros P n1 n2; induction n1 as [n1 IH] using lt_wf_ind. 50 | intros k φ m S' τf ?????? Hax p. 51 | inv_rcsteps p as [|n' ? S ? p1 p2]; eauto 10 using mk_ax_next, ax_weaken. 52 | assert (ax_next ax_disjoint_cond (ax_stmt_post (dassert_pack_top P Q) s cmτ) 53 | Γ δ '{m} [] (n' + n2) ∅ S) as Hnext. 54 | { eapply ax_step; eauto. 55 | + split; rewrite ?sep_right_id by auto; 56 | eauto using cmap_valid_memenv_valid, cmap_empty_valid. 57 | + rewrite cmap_dom_memenv_of; set_solver. } 58 | inversion Hnext as [Δ2 k2 ? φ2 m2 m2' mf (Hm2'&?) ????? Hax']; 59 | rewrite sep_right_id in Hm2' by auto; subst. 60 | assert (Γ ⊢ State k2 φ2 m2 : Stmt_type cmτ ∧ '{m} ⇒ₘ '{m2}) as [(τf2&?&?&?)]. 61 | { eapply (cstep_preservation _ _ (State _ _ _) (State _ _ _)); 62 | eauto using rcstep_cstep; exists τf; eauto. } 63 | cut (Δ2 = '{m2}); [intros ->; eauto using funenv_valid_weaken|]. 64 | apply (anti_symm memenv_forward); 65 | eauto using memenv_subseteq_forward, cmap_memenv_of_subseteq. 66 | Qed. -------------------------------------------------------------------------------- /axiomatic/expression_eval_separation.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Export memory_separation expression_eval. 4 | 5 | Lemma expr_eval_subseteq `{EnvSpec K} Γ Δ ρ m1 m2 e ν τlr : 6 | ✓ Γ → ✓{Γ,Δ} m1 → ✓{Δ}* ρ → (Γ,Δ,ρ.*2) ⊢ e : τlr → 7 | ⟦ e ⟧ Γ ρ m1 = Some ν → m1 ⊆ m2 → ⟦ e ⟧ Γ ρ m2 = Some ν. 8 | Proof. 9 | intros. eapply expr_eval_weaken; eauto using cmap_subseteq_index_alive, 10 | mem_lookup_subseteq, mem_forced_subseteq. 11 | Qed. 12 | -------------------------------------------------------------------------------- /core_c/assignments.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Export memory operations. 4 | Local Open Scope ctype_scope. 5 | 6 | Inductive assign := 7 | | Assign (**i ordinary assignment *) 8 | | PreOp : binop → assign (**i assignment operators and prefix increment, 9 | decrement, etc. *) 10 | | PostOp : binop → assign (**i postfix increment, decrement, etc. *). 11 | 12 | (** * Semantics of assignments *) 13 | (** The judgment [assign_sem Γ m a v ass va' v'] describes the resulting value 14 | [v'] of an assignment [%{Ω1} a ::={ass} #{Ω2} v], and the value [va'] that needs 15 | to be stored at [a] in [m]. *) 16 | Inductive assign_sem `{Env K} (Γ : env K) (m : mem K) 17 | (a : addr K) (v : val K) : assign → val K → val K → Prop := 18 | | Assign_sem v' : 19 | val_cast_ok Γ m (type_of a) v → 20 | v' = val_cast (type_of a) v → 21 | assign_sem Γ m a v Assign v' v' 22 | | PreOp_sem op va v' : 23 | m !!{Γ} a = Some va → val_binop_ok Γ m op va v → 24 | val_cast_ok Γ m (type_of a) (val_binop Γ op va v) → 25 | v' = val_cast (type_of a) (val_binop Γ op va v) → 26 | assign_sem Γ m a v (PreOp op) v' v' 27 | | PostOp_sem op va v' : 28 | m !!{Γ} a = Some va → val_binop_ok Γ m op va v → 29 | val_cast_ok Γ m (type_of a) (val_binop Γ op va v) → 30 | v' = val_cast (type_of a) (val_binop Γ op va v) → 31 | assign_sem Γ m a v (PostOp op) v' va. 32 | 33 | Inductive assign_typed `{Env K} (τ1 : type K) : type K → assign → Prop := 34 | | Assign_typed τ2 : cast_typed τ2 τ1 → assign_typed τ1 τ2 Assign 35 | | PreOp_typed op τ2 σ : 36 | binop_typed op τ1 τ2 σ → cast_typed σ τ1 → 37 | assign_typed τ1 τ2 (PreOp op) 38 | | PostOp_typed op τ2 σ : 39 | binop_typed op τ1 τ2 σ → cast_typed σ τ1 → 40 | assign_typed τ1 τ2 (PostOp op). 41 | 42 | Section assignments. 43 | Context `{EnvSpec K}. 44 | 45 | Lemma assign_typed_type_valid Γ ass τ1 τ2 : 46 | assign_typed τ1 τ2 ass → ✓{Γ} (TType τ1) → ✓{Γ} τ2 → ✓{Γ} τ1. 47 | Proof. 48 | destruct 1; eauto using cast_typed_type_valid, 49 | binop_typed_type_valid, type_valid_ptr_type_valid. 50 | Qed. 51 | Lemma assign_sem_erase Γ m a v ass va v' : 52 | assign_sem Γ (cmap_erase m) a v ass va v' ↔ assign_sem Γ m a v ass va v'. 53 | Proof. 54 | split. 55 | * destruct 1; econstructor; rewrite <-1?val_binop_ok_erase, 56 | <-1?val_cast_ok_erase, <-1?mem_lookup_erase; eauto. 57 | * destruct 1; econstructor; rewrite ?val_binop_ok_erase, 58 | ?val_cast_ok_erase, ?mem_lookup_erase; eauto. 59 | Qed. 60 | Lemma assign_sem_deterministic Γ m a v ass va1 va2 v1 v2 : 61 | assign_sem Γ m a v ass va1 v1 → assign_sem Γ m a v ass va2 v2 → 62 | va1 = va2 ∧ v1 = v2. 63 | Proof. by destruct 1; inversion 1; simplify_option_eq. Qed. 64 | Lemma assign_preservation Γ Δ m ass a v va' v' τ1 τ2 : 65 | ✓ Γ → ✓{Γ,Δ} m → assign_typed τ1 τ2 ass → 66 | (Γ,Δ) ⊢ a : TType τ1 → (Γ,Δ) ⊢ v : τ2 → 67 | assign_sem Γ m a v ass va' v' → (Γ,Δ) ⊢ va' : τ1 ∧ (Γ,Δ) ⊢ v' : τ1. 68 | Proof. 69 | destruct 3; inversion 3; simplify_type_equality'; split; eauto using 70 | val_cast_typed, val_binop_typed, mem_lookup_typed, addr_typed_type_valid. 71 | Qed. 72 | Lemma assign_preservation_1 Γ Δ m ass a v va' v' τ1 τ2 : 73 | ✓ Γ → ✓{Γ,Δ} m → assign_typed τ1 τ2 ass → 74 | (Γ,Δ) ⊢ a : TType τ1 → (Γ,Δ) ⊢ v : τ2 → 75 | assign_sem Γ m a v ass va' v' → (Γ,Δ) ⊢ va' : τ1. 76 | Proof. eapply assign_preservation. Qed. 77 | Lemma assign_preservation_2 Γ Δ m ass a v va' v' τ1 τ2 : 78 | ✓ Γ → ✓{Γ,Δ} m → assign_typed τ1 τ2 ass → 79 | (Γ,Δ) ⊢ a : TType τ1 → (Γ,Δ) ⊢ v : τ2 → 80 | assign_sem Γ m a v ass va' v' → (Γ,Δ) ⊢ v' : τ1. 81 | Proof. eapply assign_preservation. Qed. 82 | End assignments. 83 | -------------------------------------------------------------------------------- /core_c/contexts.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | (** This development makes use of contexts to define the semantics of various 4 | constructs. This file collects some general purpose definitions, theorems, and 5 | tactics. *) 6 | Require Export list. 7 | Require Import tactics. 8 | 9 | (** * Contexts with one hole *) 10 | (** The most commonly used kind of context is the one with exactly one hole. 11 | A context equipped with a value for its hole is known as a zipper. We define 12 | an operational type class for substitution. The function [subst E x] is 13 | supposed to substitute the value [x] in the hole of the context [E]. *) 14 | Class Subst A B C := subst: A → B → C. 15 | #[global] Instance: Params (@subst) 4 := {}. 16 | Arguments subst {_ _ _ _} !_ _ / : simpl nomatch. 17 | 18 | (** We generally define contexts as lists of singular contexts. For example 19 | for binary trees [Inductive tree := leaf | branch : tree → tree → tree], we 20 | would first define 21 | [Inductive tree_ctx := branchL : tree → tree_ctx | branchR : tree → tree_ctx], 22 | and then the actual context is defined as [list tree_ctx]. A pair 23 | [tree * list tree_ctx] is a zipper, where the second projection is a tree 24 | turned inside-out representing a path from the top. *) 25 | 26 | (** We define subsitution for contexts as singular contexts in a generic way. *) 27 | #[global] Instance list_subst `{Subst A B B} : Subst (list A) B B := 28 | fix go (l : list A) (b : B) : B := let _ : Subst _ _ _ := @go in 29 | match l with [] => b | a :: l => subst l (subst a b) end. 30 | Lemma subst_nil `{Subst A B B} b : subst [] b = b. 31 | Proof. done. Qed. 32 | Lemma subst_app `{Subst A B B} (l1 l2 : list A) b : 33 | subst (l1 ++ l2) b = subst l2 (subst l1 b). 34 | Proof. revert b. induction l1; simpl; auto. Qed. 35 | Lemma subst_snoc `{Subst A B B} (l1 : list A) a b : 36 | subst (l1 ++ [a]) b = subst a (subst l1 b). 37 | Proof. exact (subst_app l1 [a] b). Qed. 38 | 39 | #[global] Instance list_subst_injective `{Subst A B B} : 40 | (∀ a, Inj (=) (=) (subst a)) → 41 | ∀ l : list A, Inj (=) (=) (subst l). 42 | Proof. 43 | intros ? l. red. induction l as [|x l IH]; simpl; intros; auto. 44 | eapply (inj (subst _)), IH; eassumption. 45 | Qed. 46 | 47 | (** * Contexts with multiple holes *) 48 | (** Less commonly used kinds of contexts are those with multiple holes. These 49 | can be represented as dependent types indexed by the number of holes. We define 50 | a class [DepSubst] for substitution. The function [depsubst E xs] is supposed to 51 | substitute the values of the vector [xs] in the holes of [E]. *) 52 | Class DepSubst {I} (A : I → Type) (B : I → Type) C := 53 | depsubst : ∀ {i}, A i → B i → C. 54 | #[global] Instance: Params (@depsubst) 6 := {}. 55 | Arguments depsubst {_ _ _ _ _ _} !_ _ / : simpl nomatch. 56 | 57 | (** * Tactics *) 58 | (** The tactic [simplify_subst_equality H] simplifies an assumption [H] that 59 | is an equality involving [subst]. It repeatedly tries to use injectivity of 60 | [subst], or to perform case analysis on the context. Such case analyses are 61 | only performed for contexts for which an instance of [DestructSubst] is 62 | declared. *) 63 | Class DestructSubst `(Subst A B C) := {}. 64 | 65 | Tactic Notation "simplify_subst_equality" hyp(H) := 66 | match type of H with 67 | | subst ?a _ = subst ?a _ => apply (inj a) in H 68 | | @subst _ _ _ ?sub ?a _ = _ => 69 | is_var a; let ssub := constr:(_ : DestructSubst sub) in 70 | destruct a; first [discriminate H | injection' H] 71 | | _ = @subst _ _ _ ?sub ?a _ => 72 | is_var a; let ssub := constr:(_ : DestructSubst sub) in 73 | destruct a; first [discriminate H | injection' H] 74 | end; 75 | list_simplifier. 76 | Tactic Notation "simplify_subst_equality" := 77 | repeat_on_hyps (fun H => simplify_subst_equality H); 78 | list_simplifier. 79 | 80 | (** The tactic [simplify_list_subst_equality] behaves like the previous tactic, 81 | but then for the case of lists as contexts. *) 82 | Tactic Notation "simplify_list_subst_equality" hyp(H) := 83 | match type of H with 84 | | subst ?l _ = subst ?l _ => apply (list_subst_injective _ l) in H 85 | | @subst _ _ _ list_subst ?l _ = _ => 86 | destruct l as [|?? _] using rev_ind; 87 | [ rewrite subst_nil in H; simplify_equality 88 | | rewrite subst_snoc in H; simplify_subst_equality H] 89 | | _ = @subst _ _ _ list_subst ?l _ => 90 | destruct l as [|?? _] using rev_ind; 91 | [ rewrite subst_nil in H; simplify_equality 92 | | rewrite subst_snoc in H; simplify_subst_equality H] 93 | | _ => simplify_subst_equality H 94 | end. 95 | Tactic Notation "simplify_list_subst_equality" := 96 | repeat_on_hyps (fun H => simplify_list_subst_equality H); 97 | list_simplifier. 98 | -------------------------------------------------------------------------------- /core_c/executable_sound.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Export tactics smallstep executable. 4 | 5 | Section soundness. 6 | Context `{EnvSpec K}. 7 | 8 | Lemma assign_exec_correct Γ m a v ass va' v' : 9 | assign_exec Γ m a v ass = Some (va',v') ↔ assign_sem Γ m a v ass va' v'. 10 | Proof. 11 | split; [|by destruct 1; simplify_option_eq]. 12 | intros. destruct ass; simplify_option_eq; econstructor; eauto. 13 | Qed. 14 | Lemma ctx_lookup_correct (k : ctx K) i : ctx_lookup i k = locals k !! i. 15 | Proof. 16 | revert i. 17 | induction k as [|[]]; intros [|x]; f_equal'; rewrite ?list_lookup_fmap; auto. 18 | Qed. 19 | Lemma ehexec_sound Γ k m1 m2 e1 e2 : 20 | (e2,m2) ∈ ehexec Γ k e1 m1 → Γ\ locals k ⊢ₕ e1, m1 ⇒ e2, m2. 21 | Proof. 22 | intros. destruct e1; 23 | repeat match goal with 24 | | H : assign_exec _ _ _ _ _ = Some _ |- _ => 25 | apply assign_exec_correct in H 26 | | _ => progress decompose_elem_of 27 | | H : ctx_lookup _ _ = _ |- _ => rewrite ctx_lookup_correct in H 28 | | _ => progress simplify_equality' 29 | | _ => case_match 30 | end; do_ehstep. 31 | Qed. 32 | Lemma ehexec_weak_complete Γ k e1 m1 e2 m2 : 33 | ehexec Γ k e1 m1 ≡ ∅ → 34 | ¬Γ\ locals k ⊢ₕ e1, m1 ⇒ e2, m2. 35 | Proof. 36 | destruct 2; 37 | repeat match goal with 38 | | H : assign_sem _ _ _ _ _ _ _ |- _ => 39 | apply assign_exec_correct in H 40 | | H : is_Some _ |- _ => destruct H as [??] 41 | | _ => progress decompose_empty 42 | | H : locals _ !! _ = Some _ |- _ => rewrite <-ctx_lookup_correct in H 43 | | H : option_to_set ?o ≫= _ ≡ _, Ho : ?o = Some _ |- _ => 44 | rewrite Ho in H; csimpl in H; rewrite set_bind_singleton in H 45 | | _ => progress simplify_option_eq 46 | | _ => case_match 47 | | H : mguard (_) (_) ≡ ∅ |- _ => apply guard_empty in H 48 | | H : _ ∨ _ |- _ => destruct H 49 | end; eauto. 50 | Qed. 51 | Lemma ehstep_dec Γ ρ e1 m1 : 52 | (∃ e2 m2, Γ\ ρ ⊢ₕ e1, m1 ⇒ e2, m2) ∨ ∀ e2 m2, ¬Γ\ ρ ⊢ₕ e1, m1 ⇒ e2, m2. 53 | Proof. 54 | set (k:=(λ oτ, CLocal (oτ.1) (oτ.2)) <$> ρ). 55 | replace ρ with (locals k) by (induction ρ as [|[]]; f_equal'; auto). 56 | destruct (set_choose_or_empty (ehexec Γ k e1 m1)) as [[[e2 m2]?]|]; 57 | eauto using ehexec_sound, ehexec_weak_complete. 58 | Qed. 59 | Lemma cexec_sound Γ δ S1 S2 : Γ\ δ ⊢ₛ S1 ⇒ₑ S2 → Γ\ δ ⊢ₛ S1 ⇒ S2. 60 | Proof. 61 | intros. assert ( 62 | ∀ (k : ctx K) e m, 63 | ehexec Γ k e m ≡ ∅ → 64 | maybe_ECall_redex e = None → 65 | is_redex e → 66 | ¬Γ\ locals k ⊢ₕ safe e, m 67 | ). 68 | { intros k e m He. rewrite eq_None_not_Some. 69 | intros Hmaybe Hred Hsafe; apply Hmaybe; destruct Hsafe. 70 | * eexists; apply maybe_ECall_redex_Some; eauto. 71 | * edestruct ehexec_weak_complete; eauto. } 72 | destruct S1; 73 | repeat match goal with 74 | | H : _ ∈ ehexec _ _ _ _ |- _ => apply ehexec_sound in H 75 | | H : _ ∈ expr_redexes _ |- _ => 76 | apply expr_redexes_correct in H; destruct H 77 | | H : maybe VBase ?vb = _ |- _ => is_var vb; destruct vb 78 | | H : maybe_ECall_redex _ = Some _ |- _ => 79 | apply maybe_ECall_redex_Some in H; destruct H 80 | | _ => progress decompose_elem_of 81 | | _ => case_decide 82 | | _ => case_match 83 | | _ => progress simplify_equality' 84 | | H : maybe2 _ ?e = Some _ |- _ => is_var e; destruct e 85 | end; do_cstep. 86 | Qed. 87 | Lemma cexecs_sound Γ δ S1 S2 : Γ\ δ ⊢ₛ S1 ⇒ₑ* S2 → Γ\ δ ⊢ₛ S1 ⇒* S2. 88 | Proof. induction 1; econstructor; eauto using cexec_sound. Qed. 89 | Lemma cexec_ex_loop Γ δ S : 90 | ex_loop (λ S1 S2, Γ\ δ ⊢ₛ S1 ⇒ₑ S2) S → ex_loop (cstep Γ δ) S. 91 | Proof. 92 | revert S; cofix COH; intros S; destruct 1 as [S1 S2 p]. 93 | econstructor; eauto using cexec_sound. 94 | Qed. 95 | End soundness. 96 | -------------------------------------------------------------------------------- /core_c/expression_eval_smallstep.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | (** We prove some correspondence results between the denotation semantics for 4 | pure expressions and the small step operational semantics. *) 5 | From stdpp Require Import fin_maps. 6 | Require Export restricted_smallstep expression_eval. 7 | 8 | Section expression_eval. 9 | Context `{EnvSpec K}. 10 | Implicit Types e : expr K. 11 | Implicit Types a : addr K. 12 | Implicit Types v : val K. 13 | Implicit Types ν : lrval K. 14 | Implicit Types E : ectx K. 15 | 16 | Lemma expr_eval_ehstep Γ ρ e1 m ν : 17 | ⟦ e1 ⟧ Γ ρ m = Some ν → is_redex e1 → 18 | ∃ e2, Γ\ ρ ⊢ₕ e1, m ⇒ e2, m ∧ ⟦ e2 ⟧ Γ ρ m = Some ν. 19 | Proof. 20 | revert e1 ν. assert (∀ a v, 21 | mem_forced Γ a m → m !!{Γ} a = Some v → 22 | Γ\ ρ ⊢ₕ load (% (Ptr a)), m ⇒ #v, m). 23 | { intros a v Hm ?. rewrite <-Hm at 2. do_ehstep. } 24 | apply (expr_eval_ind Γ ρ m (λ e _, is_redex e → (_:Prop))); intros; 25 | repeat match goal with 26 | | H : is_redex _ |- _ => inversion H; clear H 27 | | H : is_nf _ |- _ => inversion H; clear H 28 | | H : Forall is_nf ?es |- _ => erewrite (help es) by eauto; clear H 29 | | _ => progress simplify_option_eq 30 | | _ => by eexists; split; [do_ehstep|] 31 | end. 32 | Qed. 33 | Lemma expr_eval_subst_ehstep Γ ρ m E e1 ν : 34 | ⟦ subst E e1 ⟧ Γ ρ m = Some ν → is_redex e1 → 35 | ∃ e2, Γ\ ρ ⊢ₕ e1, m ⇒ e2, m ∧ ⟦ subst E e2 ⟧ Γ ρ m = Some ν. 36 | Proof. 37 | rewrite expr_eval_subst; intros (ν'&Heval'&<-) ?. 38 | destruct (expr_eval_ehstep _ _ _ _ _ Heval') as (e2&?&?); trivial. 39 | exists e2; split; auto using subst_preserves_expr_eval. 40 | Qed. 41 | Lemma expr_eval_sound Γ δ m ρ e ν : 42 | ⟦ e ⟧ Γ ρ m = Some ν → 43 | Γ\ δ\ ρ ⊢ₛ State [] (Expr e) m ⇒* State [] (Expr (%# ν)) m. 44 | Proof. 45 | induction e as [e IH] using expr_wf_ind; intros He. 46 | destruct (is_nf_or_redex e) as [He'|(E&e1&?&->)]. 47 | { by destruct He'; simplify_option_eq. } 48 | destruct (expr_eval_subst_ehstep Γ ρ m E e1 ν) 49 | as (e2&?&?); simplify_map_eq; auto. 50 | econstructor; [do_cstep|]. apply IH; auto. 51 | rewrite !ectx_subst_size, <-Nat.add_lt_mono_l; eauto using ehstep_size. 52 | Qed. 53 | Lemma ehstep_expr_eval_locks Γ ρ m1 m2 e1 e2 ν : 54 | Γ\ ρ ⊢ₕ e1, m1 ⇒ e2, m2 → ⟦ e1 ⟧ Γ ρ m1 = Some ν → 55 | locks e1 = empty → locks e2 = ∅. 56 | Proof. destruct 1; intros; simplify_option_eq; set_solver. Qed. 57 | Lemma ehstep_expr_eval Γ ρ m1 m1' m2 e1 e2 ν : 58 | Γ\ ρ ⊢ₕ e1, m1 ⇒ e2, m2 → ⟦ e1 ⟧ Γ ρ m1 = Some ν → 59 | ⟦ e1 ⟧ Γ ρ m1' = Some ν → ⟦ e2 ⟧ Γ ρ m1' = Some ν. 60 | Proof. destruct 1; intros; simplify_option_eq; set_solver. Qed. 61 | Lemma ehstep_expr_eval_mem Γ ρ m1 m2 e1 e2 ν : 62 | Γ\ ρ ⊢ₕ e1, m1 ⇒ e2, m2 → ⟦ e1 ⟧ Γ ρ m1 = Some ν → m1 = m2. 63 | Proof. 64 | destruct 1; intros; simplify_option_eq; eauto; 65 | rewrite ?mem_unlock_empty; 66 | try destruct (val_true_false_dec _ _) as [[[??]|[??]]|[??]]; 67 | set_solver. 68 | Qed. 69 | Hint Extern 0 (_ ⊢ _ : _) => typed_constructor: core. 70 | Lemma ehstep_expr_eval_typed Γ Δ ρ m1 m2 e1 e2 ν τlr : 71 | ✓ Γ → Γ\ ρ ⊢ₕ e1, m1 ⇒ e2, m2 → 72 | ✓{Γ,Δ} m1 → ⟦ e1 ⟧ Γ ρ m1 = Some ν → ✓{Δ}* ρ → 73 | (Γ,Δ,ρ.*2) ⊢ e1 : τlr → (Γ,Δ,ρ.*2) ⊢ e2 : τlr. 74 | Proof. 75 | destruct 2; intros; simplify_option_eq; 76 | typed_inversion_all; decompose_Forall_hyps; 77 | repeat match goal with 78 | | H : ?ρ.*2 !! ?i = Some ?τ1, H2 : ?ρ !! _ = Some (_,?τ2) |- _ => 79 | rewrite list_lookup_fmap, H2 in H; decompose_Forall_hyps 80 | end; try typed_constructor; eauto using 81 | val_unop_typed, val_binop_typed, val_cast_typed, addr_top_typed, 82 | cmap_index_typed_valid, addr_top_strict, lockset_empty_valid, 83 | addr_elt_typed, addr_elt_strict, addr_elt_typed, addr_elt_strict, 84 | val_lookup_seg_typed, val_alter_const_typed, mem_lookup_typed. 85 | Qed. 86 | Lemma ehstep_pure_expr_eval Γ ρ m1 m2 e1 e2 : 87 | Γ\ ρ ⊢ₕ e1, m1 ⇒ e2, m2 → is_pure e1 → ⟦ e1 ⟧ Γ ρ m1 = ⟦ e2 ⟧ Γ ρ m1. 88 | Proof. 89 | destruct 1; inversion 1; 90 | by repeat match goal with 91 | | H : is_pure (%#{_} _) |- _ => inversion H; clear H 92 | | _ => progress simplify_option_eq 93 | end || set_solver. 94 | Qed. 95 | Lemma expr_eval_complete Γ δ m1 m2 ρ e ν : 96 | Γ\ δ\ ρ ⊢ₛ State [] (Expr e) m1 ⇒* State [] (Expr (%# ν)) m2 → 97 | is_pure e → ⟦ e ⟧ Γ ρ m1 = Some ν ∧ m1 = m2. 98 | Proof. 99 | remember (State [] (Expr e) m1) as S eqn:He; intros p; revert S p m1 e He. 100 | refine (rtc_ind_l _ _ _ _); [naive_solver|]. 101 | intros S1 S2 p p' IH m1 e -> Hsafe; revert p' Hsafe IH. pattern S2. 102 | apply (rcstep_focus_inv _ _ _ _ _ _ p); clear p; try done. 103 | * intros E e1 e2 m1' -> p' p Hpure IH. 104 | assert (is_pure e1) as Hpure' by eauto using ectx_is_pure. 105 | assert (m1' = m1) by eauto using ehstep_pure_mem, eq_sym; subst. 106 | destruct (IH m1 (subst E e2)) as [<- ->]; eauto using ehstep_pure_mem, 107 | eq_sym, f_equal, ectx_subst_is_pure, ehstep_pure_pure. 108 | eauto using subst_preserves_expr_eval, ehstep_pure_expr_eval. 109 | * intros E Ω f τs τ Ωs vs -> _ _ Hsafe. 110 | apply ectx_is_pure in Hsafe; inversion Hsafe. 111 | * intros E e1 -> ?? p'. inv_rcsteps p'; inv_rcstep. 112 | Qed. 113 | Lemma expr_eval_subst_ehsafe Γ ρ m E e ν : 114 | ⟦ subst E e ⟧ Γ ρ m = Some ν → is_redex e → Γ\ ρ ⊢ₕ safe e, m. 115 | Proof. 116 | intros. destruct (expr_eval_subst_ehstep Γ ρ m E e ν) 117 | as (e2&?&?); eauto using ehsafe_step. 118 | Qed. 119 | End expression_eval. 120 | -------------------------------------------------------------------------------- /doc/scripts.js: -------------------------------------------------------------------------------- 1 | window.onload = function() { 2 | var elems = document.getElementsByTagName('span'); 3 | for(i in elems) { 4 | if(elems[i].className != 'toggleproof') 5 | continue; 6 | 7 | elems[i].onclick = function() { 8 | var e = this; 9 | while(e.nodeType !== 1 || e.className != "proofscript") 10 | e = e.nextSibling 11 | 12 | if (e.style.display != 'inline') 13 | e.style.display = 'inline'; 14 | else 15 | e.style.display = 'none'; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /doc/style.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: black; 3 | background: white; 4 | margin-left: 10%; 5 | margin-right: 10%; 6 | } 7 | 8 | body, h1, h2, h3, a { 9 | font-family: sans; 10 | } 11 | 12 | h1 { font-size: 22px; } 13 | h2 { font-size: 20px; } 14 | h3 { font-size: 18px; } 15 | 16 | p, td, th, li { 17 | font-weight: normal; 18 | font-size: 13px; 19 | line-height: 18px; 20 | } 21 | a { 22 | color: #416DFF; 23 | text-decoration: none; 24 | } 25 | 26 | /** 27 | Classes: 28 | div.coq encloses all generated body 29 | div.doc contents of (** *) comments 30 | div.footer footer 31 | div.togglescript "Proof." line 32 | div.proofscript contents of proof script 33 | span.docright contents of (**r *) comments 34 | span.bracket contents of [ ] within comments 35 | span.kwd Coq keyword 36 | span.tactic Coq tactic 37 | span.id any other identifier 38 | */ 39 | div.coq { 40 | margin-left: 30px; 41 | font-size: 12px; 42 | font-family: monospace; 43 | } 44 | div.coq div.doc, div.coq h2, div.coq h3 { 45 | margin-left: -30px; 46 | font-family: sans; 47 | } 48 | div.coq div.doc { 49 | line-height: 18px; 50 | font-size: 14px; 51 | padding-bottom: 20px; 52 | } 53 | div.coq div.doc h2 { 54 | font-size: 20px; 55 | } 56 | div.footer { 57 | margin-top: 30px; 58 | border-top: 1px solid black; 59 | padding-top: 10px; 60 | padding-bottom: 10px; 61 | font-size: 10px; 62 | font-style: italic; 63 | } 64 | 65 | .proofscript { 66 | display: none; 67 | } 68 | .toggleproof { 69 | font-size: 10px; 70 | text-decoration: underline; 71 | } 72 | .toggleproof:hover { 73 | cursor: pointer; 74 | } 75 | .proofscript { 76 | font-size: 0.8em; 77 | } 78 | 79 | .docright { 80 | font-family: sans; 81 | font-style: italic; 82 | position: relative; 83 | float: right; 84 | width: 40%; 85 | } 86 | .docinline, .docinline .bracket, .docinline .kwd { 87 | color: #008000; 88 | } 89 | .bracket, .bracket .kwd { 90 | font-family: monospace; 91 | margin-right: 2px; 92 | color: #008000; 93 | } 94 | .kwd { 95 | color: #cf1d1d; 96 | } 97 | span.id a { 98 | font-family: monospace; 99 | } 100 | .publinks { font-size: 10px } 101 | .publinks a { text-decoration: none; } 102 | -------------------------------------------------------------------------------- /extraction/extraction.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Import interpreter ExtrOcamlBasic ExtrOcamlString architectures. 4 | 5 | Extraction Blacklist list. 6 | Extraction "parser/Extracted.ml" 7 | interpreter.interpreter_all_eval 8 | interpreter.interpreter_rand_eval 9 | interpreter.interpreter_initial_eval 10 | ilp32 llp64 lp64. 11 | -------------------------------------------------------------------------------- /include/limits.h: -------------------------------------------------------------------------------- 1 | #define CHAR_BIT __ch2o_builtin_bits((char)0) 2 | #define CHAR_MIN __ch2o_builtin_min((char)0) 3 | #define CHAR_MAX __ch2o_builtin_max((char)0) 4 | #define SCHAR_MIN __ch2o_builtin_min((signed char)0) 5 | #define SCHAR_MAX __ch2o_builtin_max((signed char)0) 6 | #define UCHAR_MAX __ch2o_builtin_max((unsigned char)0) 7 | #define SHRT_MIN __ch2o_builtin_min((short)0) 8 | #define SHRT_MAX __ch2o_builtin_max((short)0) 9 | #define USHRT_MAX __ch2o_builtin_max((unsigned short)0) 10 | #define INT_MIN __ch2o_builtin_min((int)0) 11 | #define INT_MAX __ch2o_builtin_max((int)0) 12 | #define UINT_MAX __ch2o_builtin_max((unsigned int)0) 13 | #define LONG_MIN __ch2o_builtin_min((long)0) 14 | #define LONG_MAX __ch2o_builtin_max((long)0) 15 | #define ULONG_MAX __ch2o_builtin_max((unsigned lond)0) 16 | #define LLONG_MIN __ch2o_builtin_min((long long)0) 17 | #define LLONG_MAX __ch2o_builtin_max((long long)0) 18 | #define ULLONG_MAX __ch2o_builtin_max((unsigned long long)0) 19 | -------------------------------------------------------------------------------- /include/prelude.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012-2015, Freek Wiedijk and Robbert Krebbers. */ 2 | /* This file is distributed under the terms of the BSD license. */ 3 | /** Helpers for the emulation of printf that compute the length of a printed 4 | string */ 5 | 6 | int __ch2o_len_core(int n, unsigned long long i, int w) { 7 | if (i == 0) { n = 1; } 8 | while (0 < i) { n++; i /= 10; } 9 | return n < w ? w : n; 10 | } 11 | 12 | int __ch2o_len_core_signed(int n, long long i, int w) { 13 | if (0 <= i) { 14 | return __ch2o_len_core(n,i,w); 15 | } else if (i == __ch2o_builtin_min((long long)0)) { 16 | return __ch2o_len_core(n,i,w); 17 | } else { 18 | return __ch2o_len_core(n,i * -1,w); 19 | } 20 | } 21 | 22 | int __ch2o_len_core_string(int n, char *p, int w) { 23 | while (*p) { n++; p++; } 24 | return n < w ? w : n; 25 | } 26 | -------------------------------------------------------------------------------- /include/stddef.h: -------------------------------------------------------------------------------- 1 | /* Dummy types, these will be overwritten by Main.ml */ 2 | typedef unsigned long size_t; 3 | typedef long ptrdiff_t; 4 | 5 | #define NULL 0 6 | 7 | /* Horrible way to encode offsetof in way that CIL parses it */ 8 | #define offsetof(t,x) __ch2o_builtin_offsetof((t)0->x) 9 | -------------------------------------------------------------------------------- /include/stdio.h: -------------------------------------------------------------------------------- 1 | #define printf(...) __ch2o_builtin_printf(__VA_ARGS__) 2 | -------------------------------------------------------------------------------- /include/stdlib.h: -------------------------------------------------------------------------------- 1 | #define malloc(size) __ch2o_builtin_malloc(size) 2 | #define free(p) __ch2o_builtin_free(p) 3 | #define abort() __ch2o_builtin_abort() 4 | -------------------------------------------------------------------------------- /memory/constant_propagation.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Export memory_refine. 4 | 5 | Lemma mem_constant_prop `{EnvSpec K} Γ Δ m a v τ : 6 | ✓ Γ → ✓{Γ,Δ} m → 7 | (Γ,Δ) ⊢ a : TType τ → mem_writable Γ a m → (Γ,Δ) ⊢ v : τ → 8 | ∃ v', <[a:=v]{Γ}>m !!{Γ} a = Some v' ∧ v' ⊑{Γ,true@Δ} v : τ. 9 | Proof. 10 | unfold insertE, lookupE, mem_insert, mem_lookup. intros ??? (w&?&Hw) ?. 11 | assert (ctree_Forall (λ γb, Some Writable ⊆ pbit_kind γb) 12 | (of_val Γ (tagged_perm <$> ctree_flatten w) v)). 13 | { erewrite ctree_flatten_of_val by (rewrite ?fmap_length; 14 | eauto using ctree_flatten_length, cmap_lookup_typed). 15 | generalize (val_flatten Γ v). 16 | induction Hw; intros [|??]; simpl; constructor; auto. } 17 | destruct (cmap_lookup_alter_refine Γ Δ 18 | (λ w, of_val Γ (tagged_perm <$> ctree_flatten w) v) m a w τ) 19 | as (w'&->&?); simpl; eauto using of_val_flatten_typed, 20 | cmap_lookup_typed, of_val_flatten_unshared. 21 | exists (to_val Γ w'); split. 22 | { by rewrite option_guard_True by eauto using pbits_kind_weaken, 23 | pbits_refine_kind_subseteq_inv, ctree_flatten_refine. } 24 | apply (val_refine_compose _ true true meminj_id meminj_id _ Δ _ _ 25 | (freeze true v) _ τ τ); auto using val_freeze_refine_l. 26 | erewrite <-(to_of_val _ _ (tagged_perm <$> ctree_flatten w)) by 27 | (rewrite ?fmap_length; 28 | eauto using ctree_flatten_length, cmap_lookup_typed). 29 | auto using to_val_refine. 30 | Qed. 31 | -------------------------------------------------------------------------------- /memory/fragmented.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | (** This file defines a type [frag A] to represent symbolic fragments of a 4 | data type [A]. The representation of [x : A] as a list of [n] fragments is: 5 | "frag 0 of x", ..., "frag n of x". We provide functions to ``split'' an 6 | element of type [A] into fragments, and to go back. Fragments are used to 7 | describe abstract fragments of pointers so as to encode and decode pointers as 8 | bytes in the file [pointers]. *) 9 | Require Export base. 10 | 11 | Record fragment (A : Type) := Fragment { frag_item : A; frag_index : nat }. 12 | Add Printing Constructor fragment. 13 | Arguments Fragment {_} _ _. 14 | Arguments frag_item {_} _. 15 | Arguments frag_index {_} _. 16 | 17 | #[global] Instance fragment_eq_dec `{EqDecision A}: EqDecision (fragment A). 18 | Proof. solve_decision. Defined. 19 | 20 | Section fragmented. 21 | Context {A : Type} `{EqDecision A}. 22 | Context (len : nat) {len_pos : PropHolds (len ≠ 0)}. 23 | 24 | Definition fragmented (x : A) (i : nat) (xss : list (fragment A)) : Prop := 25 | xss = Fragment x <$> seq i (len - i). 26 | #[global] Instance fragmented_dec x : ∀ i xss, Decision (fragmented x i xss). 27 | Proof. intros. unfold Decision, fragmented. decide equality. solve_decision. Defined. 28 | Typeclasses Opaque fragmented. 29 | 30 | Definition to_fragments (x : A) : list (fragment A) := Fragment x <$> seq 0 len. 31 | Definition of_fragments (xss : list (fragment A)) : option A := 32 | match xss with 33 | | Fragment x 0 :: xss => guard (fragmented x 1 xss); Some x 34 | | _ => None 35 | end. 36 | 37 | Lemma to_fragments_fragmented x : fragmented x 0 (to_fragments x). 38 | Proof. unfold fragmented, to_fragments. by rewrite Nat.sub_0_r. Qed. 39 | Lemma to_fragments_length x : length (to_fragments x) = len. 40 | Proof. unfold to_fragments. by rewrite fmap_length, seq_length. Qed. 41 | 42 | Lemma of_to_fragments x xss : of_fragments xss = Some x ↔ to_fragments x = xss. 43 | Proof. 44 | unfold of_fragments, to_fragments, fragmented, fragmented_dec, PropHolds in *. 45 | destruct len as [|n]; [lia|]. 46 | by destruct xss as [|[y [|?]] xss]; split; intros; 47 | simplify_option_eq; rewrite ?Nat.sub_0_r, ?Nat.sub_0_r in *. 48 | Qed. 49 | Lemma of_to_fragments_1 x xss : 50 | of_fragments xss = Some x → to_fragments x = xss. 51 | Proof. by apply of_to_fragments. Qed. 52 | Lemma of_to_fragments_2 x : of_fragments (to_fragments x) = Some x. 53 | Proof. by apply of_to_fragments. Qed. 54 | #[global] Instance to_fragments_inj: Inj (=) (=) to_fragments. 55 | Proof. 56 | intros x y. generalize (eq_refl (to_fragments y)). 57 | rewrite <-!of_to_fragments. congruence. 58 | Qed. 59 | 60 | Lemma Forall_to_fragments (P : fragment A → Prop) x : 61 | (∀ i, i < len → P (Fragment x i)) → Forall P (to_fragments x). 62 | Proof. 63 | unfold to_fragments. intros. apply Forall_fmap, Forall_seq; auto with lia. 64 | Qed. 65 | Lemma Forall_of_fragments (P : fragment A → Prop) x xss i : 66 | of_fragments xss = Some x → i < len → Forall P xss → P (Fragment x i). 67 | Proof. 68 | revert xss i. assert (∀ i xss, 69 | S i < len → fragmented x 1 xss → Forall P xss → P (Fragment x (S i))). 70 | { intros i xss ? ->. rewrite Forall_fmap, Forall_seq. 71 | intros Hx. apply Hx; auto with lia. } 72 | unfold of_fragments. intros. destruct xss as [|[? [|?]]], i; 73 | simplify_option_eq; decompose_Forall_hyps; eauto. 74 | Qed. 75 | End fragmented. 76 | -------------------------------------------------------------------------------- /memory/pointer_casts.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Export type_environment. 4 | Local Open Scope ctype_scope. 5 | 6 | (** * Pointer casts *) 7 | Reserved Infix ">*>" (at level 70). 8 | Inductive castable `{Env K} : type K → ptr_type K → Prop := 9 | | castable_TAny τ : τ >*> TAny 10 | | castable_uchar τ : τ >*> TType ucharT 11 | | castable_TType τ : τ >*> TType τ 12 | where "τ >*> τp" := (@castable _ _ τ τp) : C_scope. 13 | Notation "(>*>)" := castable (only parsing) : C_scope. 14 | Local Hint Extern 0 (_ >*> _) => reflexivity: core. 15 | 16 | Section castable. 17 | Context `{EqDecision K, EnvSpec K}. 18 | #[global] Instance castable_dec (τ : type K) τp : Decision (τ >*> τp). 19 | Proof. 20 | refine 21 | match τp with 22 | | TAny => left _ 23 | | TType τ' => cast_if (decide (τ' = ucharT ∨ τ = τ')) 24 | | _ => right _ 25 | end; abstract (try inversion 1; naive_solver constructor). 26 | Defined. 27 | Lemma size_of_castable Γ τ τp : τ >*> τp → (ptr_size_of Γ τp | size_of Γ τ). 28 | Proof. destruct 1; simpl; rewrite ?size_of_char; auto using Nat.divide_1_l. Qed. 29 | Lemma align_of_castable Γ τ1 τ2 : 30 | ✓ Γ → τ1 >*> TType τ2 → (align_of Γ τ2 | align_of Γ τ1). 31 | Proof. 32 | inversion_clear 2; rewrite ?align_of_char; auto using Nat.divide_1_l. 33 | Qed. 34 | Lemma bit_align_of_castable Γ τ1 τ2 : 35 | ✓ Γ → τ1 >*> TType τ2 → (bit_align_of Γ τ2 | bit_align_of Γ τ1). 36 | Proof. eauto using Nat.mul_divide_mono_r, align_of_castable. Qed. 37 | Lemma castable_type_valid Γ τ1 τ2 : ✓{Γ} τ1 → τ1 >*> TType τ2 → ✓{Γ} τ2. 38 | Proof. by inversion 2; subst; repeat constructor. Qed. 39 | Lemma castable_ptr_type_valid Γ τp1 τp2 : ✓{Γ} τp1 → τp1 >*> τp2 → ✓{Γ} τp2. 40 | Proof. 41 | destruct 2; repeat constructor; auto using type_valid_ptr_type_valid. 42 | Qed. 43 | End castable. 44 | -------------------------------------------------------------------------------- /memory/pointers.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Export addresses. 4 | 5 | Local Open Scope ctype_scope. 6 | 7 | Inductive ptr (K : iType) : iType := 8 | | NULL : ptr_type K → ptr K 9 | | Ptr : addr K → ptr K 10 | | FunPtr : funname → list (type K) → type K → ptr K. 11 | Arguments NULL {_} _. 12 | Arguments Ptr {_} _. 13 | Arguments FunPtr {_} _ _ _. 14 | 15 | #[global] Instance ptr_eq_dec `{EqDecision K}: EqDecision (ptr K). 16 | Proof. solve_decision. Defined. 17 | 18 | #[global] Instance maybe_NULL {K} : Maybe (@NULL K) := λ p, 19 | match p with NULL τ => Some τ | _ => None end. 20 | #[global] Instance maybe_Ptr {K} : Maybe (@Ptr K) := λ p, 21 | match p with Ptr a => Some a | _ => None end. 22 | #[global] Instance maybe_FunPtr {K} : Maybe3 (@FunPtr K) := λ p, 23 | match p with FunPtr f τs τ => Some (f,τs,τ) | _ => None end. 24 | 25 | Section pointer_operations. 26 | Context `{EqDecision K, Env K}. 27 | 28 | Inductive ptr_typed' (Γ : env K) (Δ : memenv K) : 29 | ptr K → ptr_type K → Prop := 30 | | NULL_typed τp : ✓{Γ} τp → ptr_typed' Γ Δ (NULL τp) τp 31 | | Ptr_typed a τp : (Γ,Δ) ⊢ a : τp → ptr_typed' Γ Δ (Ptr a) τp 32 | | FunPtr_typed f τs τ : 33 | Γ !! f = Some (τs,τ) → ptr_typed' Γ Δ (FunPtr f τs τ) (τs ~> τ). 34 | Global Instance ptr_typed: 35 | Typed (env K * memenv K) (ptr_type K) (ptr K) := uncurry ptr_typed'. 36 | Global Instance ptr_freeze : Freeze (ptr K) := λ β p, 37 | match p with Ptr a => Ptr (freeze β a) | _ => p end. 38 | 39 | Global Instance type_of_ptr: TypeOf (ptr_type K) (ptr K) := λ p, 40 | match p with 41 | | NULL τp => τp 42 | | Ptr a => type_of a 43 | | FunPtr _ τs τ => τs ~> τ 44 | end. 45 | Global Instance ptr_type_check: 46 | TypeCheck (env K * memenv K) (ptr_type K) (ptr K) := λ ΓΔ p, 47 | let (Γ,Δ) := ΓΔ in 48 | match p with 49 | | NULL τp => guard (✓{Γ} τp); Some τp 50 | | Ptr a => type_check (Γ,Δ) a 51 | | FunPtr f τs τ => 52 | '(τs',τ') ← Γ !! f; guard (τs' = τs); guard (τ' = τ); Some (τs ~> τ) 53 | end. 54 | Inductive is_NULL : ptr K → Prop := mk_is_NULL τ : is_NULL (NULL τ). 55 | Definition ptr_alive (Δ : memenv K) (p : ptr K) : Prop := 56 | match p with Ptr a => index_alive Δ (addr_index a) | _ => True end. 57 | End pointer_operations. 58 | 59 | Section pointers. 60 | Context `{EqDecision K, EnvSpec K}. 61 | Implicit Types Γ : env K. 62 | Implicit Types Δ : memenv K. 63 | Implicit Types τp : ptr_type K. 64 | Implicit Types a : addr K. 65 | Implicit Types p : ptr K. 66 | 67 | Lemma Ptr_typed_inv Γ Δ a τp : (Γ, Δ) ⊢ Ptr a : τp → (Γ, Δ) ⊢ a : τp. 68 | Proof. by inversion 1. Qed. 69 | #[global] Instance: Inj (=) (=) (@Ptr K). 70 | Proof. by injection 1. Qed. 71 | Lemma ptr_typed_type_valid Γ Δ p τp : ✓ Γ → (Γ,Δ) ⊢ p : τp → ✓{Γ} τp. 72 | Proof. 73 | destruct 2; eauto using addr_typed_ptr_type_valid, TFun_ptr_valid, 74 | env_valid_args_valid, env_valid_ret_valid, type_valid_ptr_type_valid. 75 | Qed. 76 | #[global] Instance: TypeOfSpec (env K * memenv K) (ptr_type K) (ptr K). 77 | Proof. 78 | intros [??]. by destruct 1; simpl; erewrite ?type_of_correct by eauto. 79 | Qed. 80 | #[global] Instance: 81 | TypeCheckSpec (env K * memenv K) (ptr_type K) (ptr K) (λ _, True). 82 | Proof. 83 | intros [Γ Δm] p τ _. split. 84 | * destruct p; intros; repeat (case_match || simplify_option_eq); 85 | constructor; auto; by apply type_check_sound. 86 | * by destruct 1; simplify_option_eq; 87 | erewrite ?type_check_complete by eauto. 88 | Qed. 89 | Lemma ptr_typed_weaken Γ1 Γ2 Δ1 Δ2 p τp : 90 | ✓ Γ1 → (Γ1,Δ1) ⊢ p : τp → Γ1 ⊆ Γ2 → Δ1 ⇒ₘ Δ2 → (Γ2,Δ2) ⊢ p : τp. 91 | Proof. 92 | destruct 2; constructor; 93 | eauto using ptr_type_valid_weaken, addr_typed_weaken, lookup_fun_weaken. 94 | Qed. 95 | Lemma ptr_freeze_freeze β1 β2 p : freeze β1 (freeze β2 p) = freeze β1 p. 96 | Proof. destruct p; f_equal'; auto using addr_freeze_freeze. Qed. 97 | Lemma ptr_typed_freeze Γ Δ β p τp : (Γ,Δ) ⊢ freeze β p : τp ↔ (Γ,Δ) ⊢ p : τp. 98 | Proof. 99 | split. 100 | * destruct p; inversion_clear 1; constructor; auto. 101 | by apply addr_typed_freeze with β. 102 | * destruct 1; constructor; auto. by apply addr_typed_freeze. 103 | Qed. 104 | Lemma ptr_type_of_freeze β p : type_of (freeze β p) = type_of p. 105 | Proof. by destruct p; simpl; rewrite ?addr_type_of_freeze. Qed. 106 | #[global] Instance is_NULL_dec p : Decision (is_NULL p). 107 | Proof. 108 | refine match p with NULL _ => left _ | _ => right _ end; 109 | first [by constructor | abstract by inversion 1]. 110 | Defined. 111 | Lemma ptr_alive_weaken Δ1 Δ2 p : 112 | ptr_alive Δ1 p → (∀ o, index_alive Δ1 o → index_alive Δ2 o) → 113 | ptr_alive Δ2 p. 114 | Proof. destruct p; simpl; auto. Qed. 115 | Lemma ptr_dead_weaken Γ Δ1 Δ2 p τp : 116 | (Γ,Δ1) ⊢ p : τp → ptr_alive Δ2 p → Δ1 ⇒ₘ Δ2 → ptr_alive Δ1 p. 117 | Proof. destruct 1; simpl; eauto using addr_dead_weaken. Qed. 118 | #[global] Instance ptr_alive_dec Δ p : Decision (ptr_alive Δ p). 119 | Proof. destruct p; apply _. Defined. 120 | End pointers. 121 | -------------------------------------------------------------------------------- /memory_refinements/pointers_refine.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Export pointers addresses_refine. 4 | Local Open Scope ctype_scope. 5 | 6 | Inductive ptr_refine' `{Env K} (Γ : env K) (α : bool) (f : meminj K) 7 | (Δ1 Δ2 : memenv K) : ptr K → ptr K → ptr_type K → Prop := 8 | | NULL_refine τp : 9 | ✓{Γ} τp → ptr_refine' Γ α f Δ1 Δ2 (NULL τp) (NULL τp) τp 10 | | Ptr_refine a1 a2 τp : 11 | a1 ⊑{Γ,α,f@Δ1↦Δ2} a2 : τp → 12 | ptr_refine' Γ α f Δ1 Δ2 (Ptr a1) (Ptr a2) τp 13 | | FunPtr_refine g τs τ : 14 | Γ !! g = Some (τs,τ) → 15 | ptr_refine' Γ α f Δ1 Δ2 (FunPtr g τs τ) (FunPtr g τs τ) (τs ~> τ). 16 | #[global] Instance ptr_refine `{Env K} : 17 | RefineT K (env K) (ptr_type K) (ptr K) := ptr_refine'. 18 | 19 | Section pointers. 20 | Context `{EnvSpec K}. 21 | Implicit Types Γ : env K. 22 | Implicit Types Δ : memenv K. 23 | Implicit Types α : bool. 24 | Implicit Types τp : ptr_type K. 25 | Implicit Types a : addr K. 26 | Implicit Types p : ptr K. 27 | 28 | Lemma ptr_refine_typed_l Γ α f Δ1 Δ2 p1 p2 τp : 29 | ✓ Γ → p1 ⊑{Γ,α,f@Δ1↦Δ2} p2 : τp → (Γ,Δ1) ⊢ p1 : τp. 30 | Proof. destruct 2; constructor; eauto using addr_refine_typed_l. Qed. 31 | Lemma ptr_refine_typed_r Γ α f Δ1 Δ2 p1 p2 τp : 32 | ✓ Γ → p1 ⊑{Γ,α,f@Δ1↦Δ2} p2 : τp → (Γ,Δ2) ⊢ p2 : τp. 33 | Proof. destruct 2; constructor; eauto using addr_refine_typed_r. Qed. 34 | Lemma ptr_refine_type_of_l Γ α f Δ1 Δ2 p1 p2 τp : 35 | p1 ⊑{Γ,α,f@Δ1↦Δ2} p2 : τp → type_of p1 = τp. 36 | Proof. destruct 1; simpl; eauto using addr_refine_type_of_l. Qed. 37 | Lemma ptr_refine_type_of_r Γ α f Δ1 Δ2 p1 p2 τp : 38 | p1 ⊑{Γ,α,f@Δ1↦Δ2} p2 : τp → type_of p2 = τp. 39 | Proof. destruct 1; simpl; eauto using addr_refine_type_of_r. Qed. 40 | Lemma ptr_refine_frozen Γ α f Δ1 Δ2 p1 p2 τp : 41 | p1 ⊑{Γ,α,f@Δ1↦Δ2} p2 : τp → frozen p2 → frozen p1. 42 | Proof. 43 | unfold frozen. destruct 1; simpl; auto. 44 | rewrite !(inj_iff Ptr). eapply addr_refine_frozen; eauto. 45 | Qed. 46 | Lemma ptr_refine_id Γ α Δ p τp : (Γ,Δ) ⊢ p : τp → p ⊑{Γ,α@Δ} p : τp. 47 | Proof. destruct 1; constructor; eauto using addr_refine_id. Qed. 48 | Lemma ptr_refine_compose Γ α1 α2 f1 f2 Δ1 Δ2 Δ3 p1 p2 p3 τp τp' : 49 | ✓ Γ → p1 ⊑{Γ,α1,f1@Δ1↦Δ2} p2 : τp → p2 ⊑{Γ,α2,f2@Δ2↦Δ3} p3 : τp' → 50 | p1 ⊑{Γ,α1||α2,f2 ◎ f1@Δ1↦Δ3} p3 : τp. 51 | Proof. 52 | destruct 2; inversion_clear 1; constructor; eauto using addr_refine_compose. 53 | Qed. 54 | Lemma ptr_refine_inverse Γ f Δ1 Δ2 p1 p2 τp : 55 | p1 ⊑{Γ,false,f@Δ1↦Δ2} p2 : τp → 56 | p2 ⊑{Γ,false,meminj_inverse f@Δ2↦Δ1} p1 : τp. 57 | Proof. destruct 1; constructor; eauto using addr_refine_inverse. Qed. 58 | Lemma ptr_refine_weaken Γ Γ' α α' f f' Δ1 Δ2 Δ1' Δ2' p1 p2 τp : 59 | ✓ Γ → p1 ⊑{Γ,α,f@Δ1↦Δ2} p2 : τp → Γ ⊆ Γ' → (α → α') → 60 | Δ1' ⊑{Γ',α',f'} Δ2' → Δ1 ⇒ₘ Δ1' → 61 | meminj_extend f f' Δ1 Δ2 → p1 ⊑{Γ',α',f'@Δ1'↦Δ2'} p2 : τp. 62 | Proof. 63 | destruct 2; constructor; 64 | eauto using ptr_type_valid_weaken, addr_refine_weaken, lookup_fun_weaken. 65 | Qed. 66 | Lemma ptr_refine_unique_l Γ f Δ1 Δ2 p1 p2 p3 τp2 τp3 : 67 | p1 ⊑{Γ,false,f@Δ1↦Δ2} p3 : τp2 → p2 ⊑{Γ,false,f@Δ1↦Δ2} p3 : τp3 → p1 = p2. 68 | Proof. 69 | destruct 1; inversion_clear 1; f_equal; eauto using addr_refine_unique_l. 70 | Qed. 71 | Lemma ptr_refine_unique_r Γ α f Δ1 Δ2 p1 p2 p3 τp2 τp3 : 72 | p1 ⊑{Γ,α,f@Δ1↦Δ2} p2 : τp2 → p1 ⊑{Γ,α,f@Δ1↦Δ2} p3 : τp3 → 73 | frozen p2 → frozen p3 → p2 = p3. 74 | Proof. 75 | unfold frozen. destruct 1; inversion_clear 1; intros; simplify_equality'; 76 | f_equal; eauto using addr_refine_unique_r. 77 | Qed. 78 | Lemma ptr_freeze_refine_l Γ Δ p τp : 79 | (Γ,Δ) ⊢ p : τp → freeze true p ⊑{Γ,true@Δ} p : τp. 80 | Proof. destruct 1; refine_constructor; eauto using addr_freeze_refine_l. Qed. 81 | Lemma ptr_freeze_refine Γ α f Δ1 Δ2 p1 p2 τp : 82 | p1 ⊑{Γ,α,f@Δ1↦Δ2} p2 : τp → 83 | freeze true p1 ⊑{Γ,α,f@Δ1↦Δ2} freeze true p2 : τp. 84 | Proof. destruct 1; simpl; constructor; eauto using addr_freeze_refine. Qed. 85 | Lemma ptr_alive_refine Γ α f Δ1 Δ2 p1 p2 τp : 86 | ptr_alive Δ1 p1 → p1 ⊑{Γ,α,f@Δ1↦Δ2} p2 : τp → ptr_alive Δ2 p2. 87 | Proof. destruct 2; simpl in *; eauto using addr_alive_refine. Qed. 88 | End pointers. 89 | -------------------------------------------------------------------------------- /parser/Cabshelper.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU General Public License as published by *) 10 | (* the Free Software Foundation, either version 2 of the License, or *) 11 | (* (at your option) any later version. This file is also distributed *) 12 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 13 | (* *) 14 | (* *********************************************************************) 15 | 16 | 17 | open Cabs 18 | 19 | let nextident = ref 0 20 | let getident () = 21 | nextident := !nextident + 1; 22 | !nextident 23 | 24 | let currentLoc_lexbuf lb = 25 | let p = Lexing.lexeme_start_p lb in 26 | { lineno = p.Lexing.pos_lnum; 27 | filename = p.Lexing.pos_fname; 28 | byteno = p.Lexing.pos_cnum; 29 | ident = getident ();} 30 | 31 | let currentLoc () = 32 | let p = Parsing.symbol_start_pos() in 33 | { lineno = p.Lexing.pos_lnum; 34 | filename = p.Lexing.pos_fname; 35 | byteno = p.Lexing.pos_cnum; 36 | ident = getident ();} 37 | 38 | let cabslu = {lineno = -10; 39 | filename = "cabs loc unknown"; 40 | byteno = -10; 41 | ident = 0} 42 | 43 | (*********** HELPER FUNCTIONS **********) 44 | 45 | let missingFieldDecl = ("", JUSTBASE, [], cabslu) 46 | 47 | let rec isStatic = function 48 | [] -> false 49 | | (SpecStorage STATIC) :: _ -> true 50 | | _ :: rest -> isStatic rest 51 | 52 | let rec isExtern = function 53 | [] -> false 54 | | (SpecStorage EXTERN) :: _ -> true 55 | | _ :: rest -> isExtern rest 56 | 57 | let rec isInline = function 58 | [] -> false 59 | | SpecInline :: _ -> true 60 | | _ :: rest -> isInline rest 61 | 62 | let rec isTypedef = function 63 | [] -> false 64 | | SpecTypedef :: _ -> true 65 | | _ :: rest -> isTypedef rest 66 | 67 | 68 | let get_definitionloc (d : definition) : cabsloc = 69 | match d with 70 | | FUNDEF(_, _, l, _) -> l 71 | | DECDEF(_, l) -> l 72 | | TYPEDEF(_, l) -> l 73 | | ONLYTYPEDEF(_, l) -> l 74 | | GLOBASM(_, l) -> l 75 | | PRAGMA(_, l) -> l 76 | | LINKAGE (_, l, _) -> l 77 | 78 | let get_statementloc (s : statement) : cabsloc = 79 | begin 80 | match s with 81 | | NOP(loc) -> loc 82 | | COMPUTATION(_,loc) -> loc 83 | | BLOCK(_,loc) -> loc 84 | (* | SEQUENCE(_,_,loc) -> loc *) 85 | | IF(_,_,_,loc) -> loc 86 | | WHILE(_,_,loc) -> loc 87 | | DOWHILE(_,_,loc) -> loc 88 | | FOR(_,_,_,_,loc) -> loc 89 | | BREAK(loc) -> loc 90 | | CONTINUE(loc) -> loc 91 | | RETURN(_,loc) -> loc 92 | | SWITCH(_,_,loc) -> loc 93 | | CASE(_,_,loc) -> loc 94 | | CASERANGE(_,_,_,loc) -> loc 95 | | DEFAULT(_,loc) -> loc 96 | | LABEL(_,_,loc) -> loc 97 | | GOTO(_,loc) -> loc 98 | | COMPGOTO (_, loc) -> loc 99 | | DEFINITION d -> get_definitionloc d 100 | | ASM(_,_,_,loc) -> loc 101 | | TRY_EXCEPT(_, _, _, loc) -> loc 102 | | TRY_FINALLY(_, _, loc) -> loc 103 | end 104 | 105 | 106 | let explodeStringToInts (s: string) : int64 list = 107 | let rec allChars i acc = 108 | if i < 0 then acc 109 | else allChars (i - 1) (Int64.of_int (Char.code (String.get s i)) :: acc) 110 | in 111 | allChars (-1 + String.length s) [] 112 | 113 | let valueOfDigit chr = 114 | let int_value = 115 | match chr with 116 | '0'..'9' -> (Char.code chr) - (Char.code '0') 117 | | 'a'..'z' -> (Char.code chr) - (Char.code 'a') + 10 118 | | 'A'..'Z' -> (Char.code chr) - (Char.code 'A') + 10 119 | | _ -> assert false in 120 | Int64.of_int int_value 121 | 122 | let string_of_cabsloc l = 123 | Printf.sprintf "%s:%d" l.filename l.lineno 124 | 125 | let format_cabsloc pp l = 126 | Format.fprintf pp "%s:%d" l.filename l.lineno 127 | -------------------------------------------------------------------------------- /parser/Cerrors.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU General Public License as published by *) 10 | (* the Free Software Foundation, either version 2 of the License, or *) 11 | (* (at your option) any later version. This file is also distributed *) 12 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 13 | (* *) 14 | (* *********************************************************************) 15 | 16 | (* Management of errors and warnings *) 17 | 18 | open Format 19 | 20 | let warn_error = ref false 21 | 22 | let num_errors = ref 0 23 | let num_warnings = ref 0 24 | 25 | let reset () = num_errors := 0; num_warnings := 0 26 | 27 | exception Abort 28 | 29 | let fatal_error fmt = 30 | incr num_errors; 31 | kfprintf 32 | (fun _ -> raise Abort) 33 | err_formatter 34 | ("@[" ^^ fmt ^^ ".@]@.@[Fatal error; compilation aborted.@]@.") 35 | 36 | let error fmt = 37 | incr num_errors; 38 | eprintf ("@[" ^^ fmt ^^ ".@]@.") 39 | 40 | let warning fmt = 41 | incr num_warnings; 42 | eprintf ("@[" ^^ fmt ^^ ".@]@.") 43 | 44 | let check_errors () = 45 | if !num_errors > 0 then 46 | eprintf "@[%d error%s detected.@]@." 47 | !num_errors 48 | (if !num_errors = 1 then "" else "s"); 49 | if !warn_error && !num_warnings > 0 then 50 | eprintf "@[%d error-enabled warning%s detected.@]@." 51 | !num_warnings 52 | (if !num_warnings = 1 then "" else "s"); 53 | !num_errors > 0 || (!warn_error && !num_warnings > 0) 54 | 55 | 56 | -------------------------------------------------------------------------------- /parser/Cerrors.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU General Public License as published by *) 10 | (* the Free Software Foundation, either version 2 of the License, or *) 11 | (* (at your option) any later version. This file is also distributed *) 12 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 13 | (* *) 14 | (* *********************************************************************) 15 | 16 | val warn_error : bool ref 17 | val reset : unit -> unit 18 | exception Abort 19 | val fatal_error : ('a, Format.formatter, unit, unit, unit, 'b) format6 -> 'a 20 | val error : ('a, Format.formatter, unit, unit, unit, unit) format6 -> 'a 21 | val warning : ('a, Format.formatter, unit, unit, unit, unit) format6 -> 'a 22 | val check_errors : unit -> bool 23 | -------------------------------------------------------------------------------- /parser/Lexer.mli: -------------------------------------------------------------------------------- 1 | (* 2 | * 3 | * Copyright (c) 2001-2002, 4 | * George C. Necula 5 | * Scott McPeak 6 | * Wes Weimer 7 | * All rights reserved. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions are 11 | * met: 12 | * 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 20 | * 3. The names of the contributors may not be used to endorse or promote 21 | * products derived from this software without specific prior written 22 | * permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 25 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 26 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 27 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 28 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 33 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | * 36 | *) 37 | 38 | 39 | (* This interface is generated manually. The corresponding .ml file is 40 | * generated automatically and is placed in ../obj/clexer.ml. The reason we 41 | * want this interface is to avoid confusing make with freshly generated 42 | * interface files *) 43 | 44 | 45 | val init: filename:string -> in_channel -> Lexing.lexbuf 46 | val finish: unit -> unit 47 | 48 | (* This is the main parser function *) 49 | val initial: Lexing.lexbuf -> Parser.token 50 | 51 | 52 | val push_context: unit -> unit (* Start a context *) 53 | val add_type: string -> unit (* Add a new string as a type name *) 54 | val add_identifier: string -> unit (* Add a new string as a variable name *) 55 | val pop_context: unit -> unit (* Remove all names added in this context *) 56 | 57 | -------------------------------------------------------------------------------- /parser/Lexer.mll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robbertkrebbers/ch2o/1afb3f615db053b741341e9bfd1d5c65bddea641/parser/Lexer.mll -------------------------------------------------------------------------------- /parser/Parse_aux.ml: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU General Public License as published by *) 10 | (* the Free Software Foundation, either version 2 of the License, or *) 11 | (* (at your option) any later version. This file is also distributed *) 12 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 13 | (* *) 14 | (* *********************************************************************) 15 | 16 | open Format 17 | open Cerrors 18 | open Cabshelper 19 | 20 | (* Report parsing errors *) 21 | 22 | let parse_error msg = 23 | error "%a: %s" format_cabsloc (currentLoc()) msg 24 | 25 | (* Are we parsing msvc syntax? *) 26 | 27 | let msvcMode = ref false 28 | 29 | (* We provide here a pointer to a function. It will be set by the lexer and 30 | * used by the parser. In Ocaml lexers depend on parsers, so we we have put 31 | * such functions in a separate module. *) 32 | let add_identifier: (string -> unit) ref = 33 | ref (fun _ -> assert false) 34 | 35 | let add_type: (string -> unit) ref = 36 | ref (fun _ -> assert false) 37 | 38 | let push_context: (unit -> unit) ref = 39 | ref (fun _ -> assert false) 40 | 41 | let pop_context: (unit -> unit) ref = 42 | ref (fun _ -> assert false) 43 | 44 | (* Keep here the current pattern for formatparse *) 45 | let currentPattern = ref "" 46 | 47 | -------------------------------------------------------------------------------- /parser/Parse_aux.mli: -------------------------------------------------------------------------------- 1 | (* *********************************************************************) 2 | (* *) 3 | (* The Compcert verified compiler *) 4 | (* *) 5 | (* Xavier Leroy, INRIA Paris-Rocquencourt *) 6 | (* *) 7 | (* Copyright Institut National de Recherche en Informatique et en *) 8 | (* Automatique. All rights reserved. This file is distributed *) 9 | (* under the terms of the GNU General Public License as published by *) 10 | (* the Free Software Foundation, either version 2 of the License, or *) 11 | (* (at your option) any later version. This file is also distributed *) 12 | (* under the terms of the INRIA Non-Commercial License Agreement. *) 13 | (* *) 14 | (* *********************************************************************) 15 | 16 | val parse_error : string -> unit 17 | val msvcMode : bool ref 18 | val add_identifier : (string -> unit) ref 19 | val add_type : (string -> unit) ref 20 | val push_context : (unit -> unit) ref 21 | val pop_context : (unit -> unit) ref 22 | val currentPattern : string ref 23 | -------------------------------------------------------------------------------- /parser/Parser.mly: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/robbertkrebbers/ch2o/1afb3f615db053b741341e9bfd1d5c65bddea641/parser/Parser.mly -------------------------------------------------------------------------------- /prelude/list.v: -------------------------------------------------------------------------------- 1 | (** This file collects general purpose definitions and theorems on lists that 2 | are not in the Coq standard library. *) 3 | Require Export base. 4 | 5 | Definition imap_go {A B} (f : nat → A → B) : nat → list A → list B := 6 | fix go (n : nat) (l : list A) := 7 | match l with [] => [] | x :: l => f n x :: go (S n) l end. 8 | 9 | (** * Basic tactics on lists *) 10 | (** The tactic [discriminate_list_equality] discharges a goal if it contains 11 | a list equality involving [(::)] and [(++)] of two lists that have a different 12 | length as one of its hypotheses. *) 13 | Tactic Notation "discriminate_list_equality" hyp(H) := 14 | apply (f_equal length) in H; 15 | repeat (csimpl in H || rewrite app_length in H); exfalso; lia. 16 | Tactic Notation "discriminate_list_equality" := 17 | match goal with 18 | | H : @eq (list _) _ _ |- _ => discriminate_list_equality H 19 | end. -------------------------------------------------------------------------------- /prelude/option.v: -------------------------------------------------------------------------------- 1 | From stdpp Require Import prelude. 2 | 3 | Tactic Notation "simpl_option_monad" "by" tactic3(tac) := 4 | let assert_Some_None A o H := first 5 | [ let x := fresh in evar (x:A); let x' := eval unfold x in x in clear x; 6 | assert (o = Some x') as H by tac 7 | | assert (o = None) as H by tac ] 8 | in repeat match goal with 9 | | H : context [@mret _ _ ?A] |- _ => 10 | change (@mret _ _ A) with (@Some A) in H 11 | | |- context [@mret _ _ ?A] => change (@mret _ _ A) with (@Some A) 12 | | H : context [mbind (M:=option) (A:=?A) ?f ?o] |- _ => 13 | let Hx := fresh in assert_Some_None A o Hx; rewrite Hx in H; clear Hx 14 | | H : context [fmap (M:=option) (A:=?A) ?f ?o] |- _ => 15 | let Hx := fresh in assert_Some_None A o Hx; rewrite Hx in H; clear Hx 16 | | H : context [from_option (A:=?A) _ _ ?o] |- _ => 17 | let Hx := fresh in assert_Some_None A o Hx; rewrite Hx in H; clear Hx 18 | | H : context [from_option (A:=?A) _ _ ?o] |- _ => 19 | let Hx := fresh in assert_Some_None A o Hx; rewrite Hx in H; clear Hx 20 | | H : context [ match ?o with _ => _ end ] |- _ => 21 | match type of o with 22 | | option ?A => 23 | let Hx := fresh in assert_Some_None A o Hx; rewrite Hx in H; clear Hx 24 | end 25 | | |- context [mbind (M:=option) (A:=?A) ?f ?o] => 26 | let Hx := fresh in assert_Some_None A o Hx; rewrite Hx; clear Hx 27 | | |- context [fmap (M:=option) (A:=?A) ?f ?o] => 28 | let Hx := fresh in assert_Some_None A o Hx; rewrite Hx; clear Hx 29 | | |- context [from_option (A:=?A) _ _ ?o] => 30 | let Hx := fresh in assert_Some_None A o Hx; rewrite Hx; clear Hx 31 | | |- context [from_option (A:=?A) _ _ ?o] => 32 | let Hx := fresh in assert_Some_None A o Hx; rewrite Hx; clear Hx 33 | | |- context [ match ?o with _ => _ end ] => 34 | match type of o with 35 | | option ?A => 36 | let Hx := fresh in assert_Some_None A o Hx; rewrite Hx; clear Hx 37 | end 38 | | H : context [decide _] |- _ => rewrite decide_True in H by tac 39 | | H : context [decide _] |- _ => rewrite decide_False in H by tac 40 | | H : context [mguard _ _] |- _ => rewrite option_guard_False in H by tac 41 | | H : context [mguard _ _] |- _ => rewrite option_guard_True in H by tac 42 | | _ => rewrite decide_True by tac 43 | | _ => rewrite decide_False by tac 44 | | _ => rewrite option_guard_True by tac 45 | | _ => rewrite option_guard_False by tac 46 | end. -------------------------------------------------------------------------------- /prelude/optionmap.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | From stdpp Require Import mapset. 4 | Require Import tactics. 5 | 6 | Record optionmap (M : Type → Type) (A : Type) : Type := 7 | OptionMap { optionmap_None : option A; optionmap_Some : M A }. 8 | Arguments optionmap_None {_ _} _. 9 | Arguments optionmap_Some {_ _} _. 10 | Arguments OptionMap {_ _} _ _. 11 | #[global] Instance optionmap_eq_dec {M : Type → Type} `{EqDecision A} `{EqDecision (M A)}: 12 | EqDecision (optionmap M A). 13 | Proof. solve_decision. Defined. 14 | 15 | Section optionmap. 16 | Context `{FinMap K M}. 17 | 18 | #[global] Instance optionmap_empty {A} : Empty (optionmap M A) := OptionMap None ∅. 19 | Global Opaque optionmap_empty. 20 | #[global] Instance optionmap_lookup {A} : 21 | Lookup (option K) A (optionmap M A) := λ i m, 22 | match i with 23 | | None => optionmap_None m 24 | | Some k => optionmap_Some m !! k 25 | end. 26 | #[global] Instance optionmap_partial_alter {A} : 27 | PartialAlter (option K) A (optionmap M A) := λ f i m, 28 | match i, m with 29 | | None, OptionMap o m => OptionMap (f o) m 30 | | Some k, OptionMap o m => OptionMap o (partial_alter f k m) 31 | end. 32 | #[global] Instance optionmap_to_list {A} : 33 | FinMapToList (option K) A (optionmap M A) := λ m, 34 | match m with 35 | | OptionMap o m => 36 | (from_option (λ x, [(None,x)]) [] o) ++ (prod_map Some id <$> map_to_list m) 37 | end. 38 | #[global] Instance optionmap_omap: OMap (optionmap M) := λ A B f m, 39 | match m with OptionMap o m => OptionMap (o ≫= f) (omap f m) end. 40 | #[global] Instance optionmap_merge: Merge (optionmap M) := λ A B C f m1 m2, 41 | match m1, m2 with 42 | | OptionMap o1 m1, OptionMap o2 m2 => OptionMap (diag_None f o1 o2) (merge f m1 m2) 43 | end. 44 | #[global] Instance optionmap_fmap: FMap (optionmap M) := λ A B f m, 45 | match m with OptionMap o m => OptionMap (f <$> o) (f <$> m) end. 46 | 47 | #[global] Instance: FinMap (option K) (optionmap M). 48 | Proof. 49 | split. 50 | * intros ? [??] [??] Hlookup. f_equal; [apply (Hlookup None)|]. 51 | apply map_eq. intros k. apply (Hlookup (Some k)). 52 | * intros ? [?|]. apply (lookup_empty k). done. 53 | * intros ? f [? t] [k|]; simpl; [|done]. apply lookup_partial_alter. 54 | * intros ? f [? t] [k|] [|]; simpl; try intuition congruence. 55 | intros; apply lookup_partial_alter_ne; congruence. 56 | * intros ??? [??] []; simpl. apply lookup_fmap. done. 57 | * intros ? [[x|] m]; unfold map_to_list; simpl. 58 | + constructor. 59 | - rewrite elem_of_list_fmap. by intros [[??] [??]]. 60 | - by apply (NoDup_fmap _), NoDup_map_to_list. 61 | + apply (NoDup_fmap _), NoDup_map_to_list. 62 | * intros ? m k x. unfold map_to_list. split. 63 | + destruct m as [[y|] m]; simpl. 64 | - rewrite elem_of_cons, elem_of_list_fmap. 65 | intros [? | [[??] [??]]]; simplify_equality'; [done |]. 66 | by apply elem_of_map_to_list. 67 | - rewrite elem_of_list_fmap; intros [[??] [??]]; simplify_equality'. 68 | by apply elem_of_map_to_list. 69 | + destruct m as [[y|] m]; simpl. 70 | - rewrite elem_of_cons, elem_of_list_fmap. 71 | destruct k as [k|]; simpl; [|intuition congruence]. 72 | intros. right. exists (k,x). by rewrite elem_of_map_to_list. 73 | - rewrite elem_of_list_fmap. 74 | destruct k as [k|]; simpl; [|done]. 75 | intros. exists (k,x). by rewrite elem_of_map_to_list. 76 | * intros ?? f [??] [?|]; simpl; [|done]; apply (lookup_omap f). 77 | * intros ??? f [??] [??] [?|]; simpl; [|done]; apply (lookup_merge f). 78 | Qed. 79 | End optionmap. 80 | 81 | (** * Finite sets *) 82 | Notation optionset M := (mapset (optionmap M)). 83 | #[global] Instance optionmap_dom {M : Type → Type} `{∀ A, Empty (M A), Merge M} {A} : 84 | Dom (optionmap M A) (optionset M) := mapset_dom. 85 | #[global] Instance optionmap_domspec `{FinMap K M} : 86 | FinMapDom (option K) (optionmap M) (optionset M) := mapset_dom_spec. 87 | -------------------------------------------------------------------------------- /prelude/prelude.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | Require Export 4 | base 5 | tactics. 6 | -------------------------------------------------------------------------------- /prelude/stringmap.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | (** This files implements an efficient implementation of finite maps whose keys 4 | range over Coq's data type of strings [string]. The implementation uses radix-2 5 | search trees (uncompressed Patricia trees) as implemented in the file [pmap] 6 | and guarantees logarithmic-time operations. *) 7 | 8 | Require Export base. 9 | From stdpp Require Export stringmap. 10 | 11 | Lemma map_subseteq_inv_L {A} (m1 m2 : stringmap A) : m1 ⊆ m2 → m1 ⊂ m2 ∨ m1 = m2. 12 | Proof. 13 | intros. destruct (decide (m2 ∖ m1 = ∅)) as [Hm21|(i&x&Hi)%map_choose]. 14 | - right. by rewrite <-(map_difference_union m1 m2), Hm21, (right_id_L _ _). 15 | - left. apply lookup_difference_Some in Hi as [??]. 16 | apply map_subset_alt; eauto. 17 | Qed. -------------------------------------------------------------------------------- /prelude/tactics.v: -------------------------------------------------------------------------------- 1 | (* Copyright (c) 2012-2015, Robbert Krebbers. *) 2 | (* This file is distributed under the terms of the BSD license. *) 3 | (** This file collects general purpose tactics that are used throughout 4 | the development. *) 5 | 6 | From stdpp Require Import list. 7 | Require Export base. 8 | 9 | Ltac injection' H := 10 | block_goal; injection H; clear H; intros H; intros; unblock_goal. 11 | 12 | Ltac simplify_equality := repeat 13 | match goal with 14 | | H : _ ≠ _ |- _ => by destruct H 15 | | H : _ = _ → False |- _ => by destruct H 16 | | H : ?x = _ |- _ => subst x 17 | | H : _ = ?x |- _ => subst x 18 | | H : _ = _ |- _ => discriminate H 19 | | H : ?f _ = ?f _ |- _ => apply (inj f) in H 20 | | H : ?f _ _ = ?f _ _ |- _ => apply (inj2 f) in H; destruct H 21 | (* before [injection'] to circumvent bug #2939 in some situations *) 22 | | H : ?f _ = ?f _ |- _ => injection' H 23 | | H : ?f _ _ = ?f _ _ |- _ => injection' H 24 | | H : ?f _ _ _ = ?f _ _ _ |- _ => injection' H 25 | | H : ?f _ _ _ _ = ?f _ _ _ _ |- _ => injection' H 26 | | H : ?f _ _ _ _ _ = ?f _ _ _ _ _ |- _ => injection' H 27 | | H : ?f _ _ _ _ _ _ = ?f _ _ _ _ _ _ |- _ => injection' H 28 | | H : ?x = ?x |- _ => clear H 29 | (* unclear how to generalize the below *) 30 | | H1 : ?o = Some ?x, H2 : ?o = Some ?y |- _ => 31 | assert (y = x) by congruence; clear H2 32 | | H1 : ?o = Some ?x, H2 : ?o = None |- _ => congruence 33 | end. 34 | Ltac simplify_equality' := repeat (progress csimpl in * || simplify_equality). 35 | Ltac f_equal' := csimpl in *; f_equal. 36 | Ltac f_lia := 37 | repeat lazymatch goal with 38 | | |- @eq BinNums.Z _ _ => lia 39 | | |- @eq nat _ _ => lia 40 | | |- _ => f_equal 41 | end. 42 | Ltac f_lia' := csimpl in *; f_lia. 43 | 44 | Tactic Notation "decompose_elem_of" hyp(H) := 45 | let rec go H := 46 | lazymatch type of H with 47 | | _ ∈ ∅ => apply elem_of_empty in H; destruct H 48 | | ?x ∈ {[ ?y ]} => 49 | apply elem_of_singleton in H; try first [subst y | subst x] 50 | | ?x ∉ {[ ?y ]} => 51 | apply not_elem_of_singleton in H 52 | | _ ∈ _ ∪ _ => 53 | apply elem_of_union in H; destruct H as [H|H]; [go H|go H] 54 | | _ ∉ _ ∪ _ => 55 | let H1 := fresh H in let H2 := fresh H in apply not_elem_of_union in H; 56 | destruct H as [H1 H2]; go H1; go H2 57 | | _ ∈ _ ∩ _ => 58 | let H1 := fresh H in let H2 := fresh H in apply elem_of_intersection in H; 59 | destruct H as [H1 H2]; go H1; go H2 60 | | _ ∈ _ ∖ _ => 61 | let H1 := fresh H in let H2 := fresh H in apply elem_of_difference in H; 62 | destruct H as [H1 H2]; go H1; go H2 63 | | ?x ∈ _ <$> _ => 64 | apply elem_of_fmap in H; destruct H as [? [? H]]; try (subst x); go H 65 | | _ ∈ _ ≫= _ => 66 | let H1 := fresh H in let H2 := fresh H in apply elem_of_bind in H; 67 | destruct H as [? [H1 H2]]; go H1; go H2 68 | | ?x ∈ mret ?y => 69 | apply elem_of_ret in H; try first [subst y | subst x] 70 | | _ ∈ mjoin _ ≫= _ => 71 | let H1 := fresh H in let H2 := fresh H in apply elem_of_join in H; 72 | destruct H as [? [H1 H2]]; go H1; go H2 73 | | _ ∈ guard _; _ => 74 | let H1 := fresh H in let H2 := fresh H in apply elem_of_guard in H; 75 | destruct H as [H1 H2]; go H2 76 | | _ ∈ option_to_set _ => apply elem_of_option_to_set in H 77 | | _ ∈ list_to_set _ => apply elem_of_list_to_set in H 78 | | _ => idtac 79 | end in go H. 80 | Tactic Notation "decompose_elem_of" := 81 | repeat_on_hyps (fun H => decompose_elem_of H). 82 | 83 | Ltac decompose_empty := repeat 84 | match goal with 85 | | H : ∅ ≡ ∅ |- _ => clear H 86 | | H : ∅ = ∅ |- _ => clear H 87 | | H : ∅ ≡ _ |- _ => symmetry in H 88 | | H : ∅ = _ |- _ => symmetry in H 89 | | H : _ ∪ _ ≡ ∅ |- _ => apply empty_union in H; destruct H 90 | | H : _ ∪ _ ≢ ∅ |- _ => apply non_empty_union in H; destruct H 91 | | H : {[ _ ]} ≡ ∅ |- _ => destruct (non_empty_singleton _ H) 92 | | H : _ ∪ _ = ∅ |- _ => apply empty_union_L in H; destruct H 93 | | H : _ ∪ _ ≠ ∅ |- _ => apply non_empty_union_L in H; destruct H 94 | | H : {[ _ ]} = ∅ |- _ => destruct (non_empty_singleton_L _ H) 95 | | H : guard _ ; _ ≡ ∅ |- _ => apply guard_empty in H; destruct H 96 | end. -------------------------------------------------------------------------------- /site_scons/site_tools/Coq.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2012-2015, Robbert Krebbers. 2 | # This file is distributed under the terms of the BSD license. 3 | import SCons.Defaults, SCons.Tool, SCons.Util, os 4 | 5 | def coq_emitter(target, source, env): 6 | base, _ = os.path.splitext(str(target[0])) 7 | for ext in ['.glob', '.vos', '.vok']: 8 | target.append(base + ext) 9 | return target, source 10 | Coq = SCons.Builder.Builder( 11 | action = '$COQC $COQFLAGS -q $SOURCE', 12 | suffix = '.vo', 13 | src_suffix = '.v', 14 | emitter = coq_emitter 15 | ) 16 | 17 | def make_coqidescript(target, source, env): 18 | open('coqidescript', 'w').write('#!/bin/sh\n' + 19 | env['COQIDE'] + ' ' + env['COQFLAGS'] + ' $@ \n') 20 | os.chmod('coqidescript', 0o755) 21 | return 0 22 | CoqIdeScript = SCons.Builder.Builder(action = make_coqidescript) 23 | 24 | def generate(env): 25 | env['COQC'] = 'coqc' 26 | env['COQIDE'] = 'coqide' 27 | env.Append(BUILDERS = { 28 | 'Coq' : Coq, 'CoqIdeScript' : CoqIdeScript 29 | }) 30 | 31 | def exists(env): 32 | return env.Detect('coqc') 33 | -------------------------------------------------------------------------------- /tests/defined-ellison/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2009-2011 by Charles M. Ellison III 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j004a.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j004b.c: -------------------------------------------------------------------------------- 1 | int main(int argc, char **argv) { 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j004c.c: -------------------------------------------------------------------------------- 1 | int main(int argc, char *argv[]){ 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j004d.c: -------------------------------------------------------------------------------- 1 | typedef int tint; 2 | typedef char tchar; 3 | 4 | tint main(tint a, tchar *b[]) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j008.c: -------------------------------------------------------------------------------- 1 | static int f(void); 2 | 3 | static int f(void){ 4 | return 0; 5 | } 6 | 7 | static int g(void){ 8 | return 0; 9 | } 10 | static int g(void); 11 | 12 | static int x; 13 | static int x; 14 | extern int y; 15 | static int b; 16 | 17 | int main(void){ 18 | return f() + g() + x + b; 19 | } 20 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j009.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void){ 4 | int* p; 5 | { 6 | int x = 5; 7 | p = &x; 8 | } // the memory for x should not be accessible now 9 | 10 | int y = 0; 11 | 12 | { 13 | int y = 5; 14 | } 15 | y; 16 | 17 | p = malloc(sizeof(int)); 18 | *p = 5; 19 | free(p); 20 | 21 | int* q; 22 | { 23 | int x; 24 | q = &x; 25 | } 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j010.c: -------------------------------------------------------------------------------- 1 | int y; 2 | int* f(void) { 3 | int x; 4 | return &y; 5 | } 6 | 7 | int main(void){ 8 | int* p = 0; 9 | { 10 | int x; 11 | p = &x; 12 | } 13 | 14 | p = f(); 15 | 16 | int i = 0; 17 | while (i < 10){ 18 | int x = 2; 19 | i++; 20 | p = &x; 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j011.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 0; 3 | x + 1; 4 | 5 | goto l; 6 | { 7 | l: 8 | ; 9 | int y = 0; 10 | y + 1; 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j012.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | unsigned char x; 3 | x; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j013.c: -------------------------------------------------------------------------------- 1 | struct { 2 | int x; 3 | int y; 4 | } s; 5 | 6 | int main(void) { 7 | unsigned char x; 8 | 9 | *((unsigned char*) &s.x) = x; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j014.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | ~1; 4 | ~(INT_MAX-1); 5 | 6 | -1; 7 | INT_MIN; 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j015.c: -------------------------------------------------------------------------------- 1 | int f(void); 2 | 3 | int f(void); 4 | 5 | int f(void) { 6 | return 0; 7 | } 8 | 9 | float g(void); 10 | 11 | float g(void); 12 | 13 | float g(void) { 14 | return 0; 15 | } 16 | 17 | extern int x; 18 | int x = 0; 19 | 20 | int main(void) { 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j016.c: -------------------------------------------------------------------------------- 1 | void f(int n, int (*a)[n]) { } 2 | 3 | int main(void) { 4 | int a[5] = {0}; 5 | int (*b)[5] = &a; 6 | f(5, b); 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j017.c: -------------------------------------------------------------------------------- 1 | #include 2 | int f(int x){ 3 | return x; 4 | } 5 | int main(void){ 6 | signed char x; 7 | double y = CHAR_MAX; 8 | x = y; 9 | 10 | unsigned char a; 11 | float b = UCHAR_MAX; 12 | a = b; 13 | 14 | f(INT_MAX); 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j018.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | float x = pow(10.0, 38.0); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j019.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int x = 5; 3 | *(char*)(&x); 4 | char a[5] = {1, 2, 3, 4, 5}; 5 | *(char*)(&a[4]); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j020.c: -------------------------------------------------------------------------------- 1 | struct s s0; 2 | 3 | struct s { 4 | int x; 5 | }; 6 | 7 | enum e {x, y, z}; 8 | enum e e0; 9 | 10 | int a[]; 11 | 12 | int main(void) { 13 | struct s s1 = s0; 14 | enum e e1 = e0; 15 | a[0] = 0; 16 | return a[0] + e1 + s1.x; 17 | } 18 | 19 | int a[] = {1, 2, 3}; 20 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j021.c: -------------------------------------------------------------------------------- 1 | int test1(void) { 2 | goto test1a; 3 | int x = 0; // we skip over the init (although the memory is allocated) 4 | test1a: 5 | x = 0; 6 | return x; 7 | } 8 | 9 | union U0 { 10 | int x; 11 | }; 12 | 13 | int main(void) { 14 | int x = 0; 15 | x; 16 | 17 | float y = 0; 18 | y; 19 | 20 | int* p = 0; 21 | p; 22 | 23 | unsigned char uc; 24 | &uc; 25 | uc; 26 | 27 | union U0 u = {0}; 28 | u; 29 | 30 | return test1(); 31 | } 32 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j022.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | register int a[5] = {0}; 3 | sizeof(a); 4 | 5 | int b[10] = {0}; 6 | b[5]; 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j023.c: -------------------------------------------------------------------------------- 1 | void f() { } 2 | int g() { return 0; } 3 | 4 | int main(void) { 5 | f(); 6 | g(); 7 | (void) f(); 8 | 9 | (void) 1; 10 | 11 | int x; 12 | (void)(x = 5); 13 | 14 | (void)(int) 5; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j024.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x; 3 | int *p = (void*) 0; 4 | 5 | x = (int)p; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j025.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | _Alignas(32) int x; 3 | _Alignas(32) int *p; 4 | 5 | _Alignas(32) int y; 6 | int *q; 7 | 8 | p = &x; 9 | q = &y; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j026.c: -------------------------------------------------------------------------------- 1 | int f(int x){ 2 | return x; 3 | } 4 | 5 | int main(void){ 6 | int (*x)(int) = &f; 7 | return x(0); 8 | } 9 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j032.c: -------------------------------------------------------------------------------- 1 | #include 2 | int func(void){ 3 | printf("%s\n", __func__); 4 | return 0; 5 | } 6 | int main(void){ 7 | __func__; 8 | return func(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j033.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void){ 4 | char a[] = "hello"; 5 | a[0] = 'x'; 6 | 7 | char (*b)[6]; 8 | b = &"hello"; 9 | (*b)[0]; 10 | 11 | char c[] = "hello\n"; 12 | c[0] = 'x'; 13 | printf("hello\n"); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j035.c: -------------------------------------------------------------------------------- 1 | int f(int a, int b) { 2 | return 0; 3 | } 4 | 5 | int foo (int *p1, int *p2) { 6 | return (*p1)++ + (*p2)++; 7 | } 8 | 9 | int main(void) { 10 | int x = 0; 11 | int y = 0; 12 | (x = 1) + y; 13 | x + (y = 1); 14 | (x = 1) / (y = 1); 15 | f(x = 0, y); 16 | ++x + y; 17 | 18 | "hi0"[0] + x++; 19 | "hi1"[0] + x++ + "hi2"[0]; 20 | 21 | foo (&x, &y); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j036.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | INT_MIN % 1; 4 | INT_MAX - 1; 5 | (long long) 0 || INT_MAX-1; 6 | return 0; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j037.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | float x = 5; 3 | float* p = (float*)&x; 4 | *p; 5 | 6 | int y = 5; 7 | *((int*)&y); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j038.c: -------------------------------------------------------------------------------- 1 | int foo(); 2 | int bar(); 3 | 4 | int baz(a) 5 | int a; 6 | { 7 | return 0; 8 | } 9 | 10 | int main(void){ 11 | return foo(1, 2) + bar() + baz(5); 12 | } 13 | 14 | int foo(int a, int b){ 15 | return 0; 16 | } 17 | 18 | int bar(){ 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j039.c: -------------------------------------------------------------------------------- 1 | int f(int x, int y) { 2 | return x; 3 | } 4 | 5 | int g(double x) { 6 | return (int) x; 7 | } 8 | 9 | int main(void) { 10 | ((int (*)())f)(0, 0); 11 | 12 | ((int (*)())g)(0.0); 13 | 14 | int bar(); 15 | bar(5.0); 16 | 17 | int baz(); 18 | baz((char)5); 19 | 20 | int bah(); 21 | bah(5); 22 | 23 | return 0; 24 | } 25 | 26 | int bar(double a){ 27 | return 0; 28 | } 29 | 30 | int baz(int x){ 31 | return 0; 32 | } 33 | 34 | int bah(int x){ 35 | return x; 36 | } 37 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j040.c: -------------------------------------------------------------------------------- 1 | int f(x) 2 | int x; 3 | { 4 | return x - x; 5 | } 6 | 7 | int g(p) 8 | int* p; 9 | { 10 | return *p; 11 | } 12 | 13 | int h(x) 14 | float x; 15 | { 16 | return 0; 17 | } 18 | 19 | int main(void) { 20 | int x = 0; 21 | return f(1) + g(&x) + h(3.3); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j041.c: -------------------------------------------------------------------------------- 1 | // based on example by Derek Jones 2 | 3 | #include 4 | #include 5 | 6 | int g(int v) { 7 | return 0; 8 | } 9 | 10 | struct s { 11 | int (*f1)(int); 12 | int (*f2)(int); 13 | } x; 14 | 15 | int (**pf)(int); 16 | 17 | int main(void) { 18 | x.f2 = g; 19 | pf = &x.f1; 20 | pf = (int (**)(int))((char*)&x + offsetof(struct s, f2)); 21 | (**pf)(2); 22 | } 23 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j042.c: -------------------------------------------------------------------------------- 1 | _Atomic struct s { 2 | int x; 3 | } s; 4 | 5 | _Atomic union u { 6 | int x; 7 | } u; 8 | 9 | int main(void) { 10 | struct s t = s; 11 | union u v = u; 12 | return 0; 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j043.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[5] = {1, 2, 3, 4, 5}; 3 | *(&a[4]); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j044.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 5; 3 | int *p = &x; 4 | (int*)p; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j045.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | 1%1; 3 | 1/1; 4 | int x = 1; 5 | 1/x; 6 | 1%x; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j046.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a; 3 | &a+1; 4 | 5 | int b[2]; 6 | (b + 2); 7 | 8 | int c; 9 | &c; 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j047.c: -------------------------------------------------------------------------------- 1 | int b[3]; 2 | int main(void) { 3 | int a = 5; 4 | *(&a); 5 | 6 | b[2]; 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j048.c: -------------------------------------------------------------------------------- 1 | void f(int a, int b) { 2 | &b; 3 | } 4 | 5 | int main(void) { 6 | int a[3]; 7 | int b[2]; 8 | &a[2] - &a[1]; 9 | 10 | f(5, 6); 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j049.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[4][5] = {0}; 3 | a[2][3]; 4 | 5 | int b[4][3] = {0}; // theoretically 4 * 3 memory slots 6 | int z = b[0][0]; // but not allowed to go out of bounds in any dimension 7 | 8 | int c[4][5] = {0}; 9 | *(*c + 2 + 2); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j050.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) { 6 | if (sizeof(ptrdiff_t) == sizeof(int)) { 7 | unsigned char *ptr0 = malloc(((unsigned)INT_MAX) + 1); 8 | 9 | unsigned char *ptr1 = ptr0 + (unsigned)INT_MAX; 10 | 11 | ptr1 - ptr0; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j051.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | unsigned s = 1; 5 | 6 | 1 << s; 7 | 1 >> s; 8 | 9 | s = sizeof(unsigned) * CHAR_BIT - 1; 10 | 11 | ((unsigned)1) << s; 12 | 1 >> s; 13 | 14 | return 0; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j052.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void){ 4 | 1 << 5; 5 | INT_MAX >> 2; 6 | return 0; 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j053.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a; 3 | int b; 4 | if (&a >= &a) { 5 | return 0; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j054.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct big_type { 4 | int arr[32]; 5 | }; 6 | union u { 7 | struct s1 { long long c; struct big_type bt1; } sub1; 8 | struct s2 { long long x; struct big_type bt2; } sub2; 9 | } obj; 10 | 11 | union { int i; int c; } ic; 12 | 13 | int main(void) { 14 | obj.sub2.bt2 = obj.sub1.bt1; 15 | 16 | long long *p = malloc(sizeof(long long)); 17 | 18 | *p = 5; 19 | 20 | *p = *(long long*)p; 21 | 22 | ic.c = ic.i; 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j055.c: -------------------------------------------------------------------------------- 1 | struct s { 2 | int s : 5; 3 | }; 4 | 5 | int x; 6 | enum e1 {a1 = 5}; 7 | enum e2 {a2 = 5 + (int)3}; 8 | 9 | int a[5]; 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j056.c: -------------------------------------------------------------------------------- 1 | struct { 2 | int f; 3 | } s; 4 | 5 | static int f(void) { 6 | return 0; 7 | } 8 | 9 | int x = 5 - 5; 10 | int a[5]; 11 | int* p1 = (int*)0; 12 | int* p2 = &a[2]; 13 | int* p3 = &s.f; 14 | 15 | int main(void){ 16 | return *p2; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j057.c: -------------------------------------------------------------------------------- 1 | int a = 1 + 1; 2 | int b = 1 + sizeof(int); 3 | int c = 1 + _Alignof(int); 4 | int d = 1 + (int)1.0; 5 | 6 | int main(void) { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j058.c: -------------------------------------------------------------------------------- 1 | int a[2] = {0, 1}; 2 | int *p = &(a[0]); 3 | 4 | struct { 5 | int f1; 6 | int f2; 7 | } b = {0, 1}; 8 | int *q = &(b.f1); 9 | 10 | struct c_ { 11 | int f1; 12 | int f2; 13 | } c = {0, 1}; 14 | struct c_ *rr = &c; 15 | int *r = &((&c)->f1); 16 | 17 | double d1, d2; 18 | double *ss = &d1; 19 | double *s = (double*)&d1; 20 | 21 | int e1, e2; 22 | int *ttt = &e1; 23 | int **tt = &ttt; 24 | int *t1 = &*((int*)0); 25 | 26 | int main(void) { 27 | int *t2 = 0; 28 | return *p + *q + *r + *s + (t1 != t2); 29 | } 30 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j059.c: -------------------------------------------------------------------------------- 1 | struct s { int x; }; 2 | union u { int x; int y; }; 3 | 4 | typedef int arr[]; 5 | typedef struct s s; 6 | typedef union u u; 7 | 8 | int main(void) { 9 | int a[] = {0}; 10 | struct s b; 11 | union u c; 12 | struct s d = {0}; 13 | union u e = {0}; 14 | 15 | arr f = {0}, g = {0, 1}; 16 | s h; 17 | u i; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j060.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | extern int f(); 3 | int g(); 4 | return f() + g(); 5 | } 6 | 7 | int f(void) { 8 | return 0; 9 | } 10 | 11 | int g(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j061.c: -------------------------------------------------------------------------------- 1 | struct { 2 | int x; 3 | union { 4 | int y; 5 | } u; 6 | } s; 7 | 8 | union { 9 | int x; 10 | struct { 11 | int y; 12 | } s; 13 | } u; 14 | 15 | int main(void) { 16 | return s.u.y + u.s.y; 17 | } 18 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j062.c: -------------------------------------------------------------------------------- 1 | struct { 2 | int x; 3 | int a[]; 4 | } s; 5 | 6 | int main(void) { 7 | &(s.a[0]); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j063.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | struct s* a; 3 | struct s (*b)(); 4 | typedef struct s s; 5 | 6 | union u* c; 7 | union u (*d)(); 8 | typedef union u u; 9 | 10 | struct s { int x; }; 11 | union u { int x; }; 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j064.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void){ 4 | const int x = 0; 5 | const int* p = &x; 6 | 7 | const char q[] = "hello"; 8 | char *r = strchr(q, q[0]); 9 | r[0]; 10 | 11 | return x; 12 | } 13 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j065.c: -------------------------------------------------------------------------------- 1 | int f(volatile int* x) { 2 | return *x; 3 | } 4 | 5 | int main(void) { 6 | volatile int x = 5; 7 | *(volatile int*)&x; 8 | f(&x); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j066.c: -------------------------------------------------------------------------------- 1 | const int x = 0; 2 | int* restrict y = 0; 3 | volatile int z; 4 | _Atomic int w; 5 | 6 | int f(); 7 | const int g(); // Qualified return types, not function types. 8 | volatile int h(); 9 | _Atomic int k(); 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j067.c: -------------------------------------------------------------------------------- 1 | const int a; 2 | const int a; 3 | 4 | int * restrict b; 5 | int * restrict b; 6 | 7 | volatile int c; 8 | volatile int c; 9 | 10 | _Atomic int d; 11 | _Atomic int d; 12 | 13 | int main(void) { 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j068.c: -------------------------------------------------------------------------------- 1 | int f(int* restrict a, int* restrict b) { 2 | *a = 3; 3 | return 0; 4 | } 5 | 6 | int g(const int* restrict a, int* b) { 7 | *b; 8 | *a; 9 | return 0; 10 | } 11 | 12 | // this example is loosely based on an example in sentence 1509 in http://www.knosof.co.uk/cbook/cbook.html 13 | int g2(); 14 | 15 | int f2(int * restrict p) { 16 | g2(p); 17 | return *p; 18 | } 19 | 20 | int main(void) { 21 | int a = 5; 22 | f(&a, &a); 23 | g(&a, &a); 24 | 25 | int x = 5; 26 | return f2(&x) == 5; 27 | } 28 | 29 | int g2(int * p) { 30 | *p = 10; 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j069.c: -------------------------------------------------------------------------------- 1 | int * restrict p; 2 | int * restrict q; 3 | 4 | int f(int * restrict p, int * restrict q) { 5 | return 0; 6 | } 7 | 8 | int main(void){ 9 | int x = 5; 10 | int y = 6; 11 | p = &x; 12 | q = &y; 13 | 14 | { 15 | int * restrict a = p; 16 | int * restrict b = q; 17 | } 18 | 19 | return f(p, q); 20 | } 21 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j070.c: -------------------------------------------------------------------------------- 1 | inline int f(void); 2 | 3 | int main(void) { 4 | return 0; 5 | } 6 | 7 | inline int f(void){ 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j071.c: -------------------------------------------------------------------------------- 1 | _Noreturn void f(void){ 2 | while (1) {} 3 | } 4 | 5 | int g(void) { return 0; } 6 | 7 | int main(void){ 8 | return g(); 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j072.c: -------------------------------------------------------------------------------- 1 | _Alignas(4) int x; 2 | _Alignas(4) int x; 3 | 4 | _Alignas(int) int y; 5 | _Alignas(int) int y; 6 | 7 | int main(void) { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j073-link1.c: -------------------------------------------------------------------------------- 1 | extern _Alignas(4) int x; 2 | 3 | int main(void) { 4 | return x; 5 | } 6 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j073-link2.c: -------------------------------------------------------------------------------- 1 | _Alignas(4) int x; 2 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j074.c: -------------------------------------------------------------------------------- 1 | int * const x; 2 | int * const x; 3 | 4 | int * restrict y; 5 | int * restrict y; 6 | 7 | const int * z; 8 | const int * z; 9 | 10 | float * const w; 11 | float * const w; 12 | 13 | 14 | int main(void){ 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j075.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int x = -5; 3 | int a[-x]; 4 | } 5 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j076.c: -------------------------------------------------------------------------------- 1 | unsigned a1[5]; 2 | unsigned a1[5]; 3 | 4 | double a2[5]; 5 | double a2[5]; 6 | 7 | int * restrict a3[5]; 8 | int * restrict a3[5]; 9 | 10 | const int a4[5]; 11 | const int a4[5]; 12 | 13 | int (*a5[5])(int, int); 14 | int (*a5[5])(int, int); 15 | 16 | int a6[5 + 2]; 17 | int a6[5 + 2]; 18 | 19 | int a7[]; 20 | int a7[5]; 21 | 22 | int f(int n) { return n; } 23 | 24 | int main(void) { 25 | int n = 3; 26 | int a[n][6]; 27 | int (*p)[6]; 28 | 29 | p = a; 30 | 31 | 1 ? (int(*)[f(3)]) 0 : (int (*)[3]) 0; 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j077.c: -------------------------------------------------------------------------------- 1 | #include 2 | int f(int a[static 5]) { 3 | return 0; 4 | } 5 | 6 | int main(void) { 7 | int a[5]; 8 | int *b = malloc(sizeof(int) * 5); 9 | return f(a) + f(b); 10 | } 11 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j078.c: -------------------------------------------------------------------------------- 1 | int a(void) { 2 | return 0; 3 | } 4 | 5 | int c(void) { 6 | auto int x; 7 | return 0; 8 | } 9 | 10 | int d(void) { 11 | static int x; 12 | return 0; 13 | } 14 | 15 | int e(void) { 16 | const int x = 0; 17 | return 0; 18 | } 19 | 20 | int f(void) { 21 | int* restrict p; 22 | return 0; 23 | } 24 | 25 | int g(void) { 26 | volatile int x; 27 | return 0; 28 | } 29 | 30 | int h(void) { 31 | _Atomic int x; 32 | return 0; 33 | } 34 | 35 | int main(void) { 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j079.c: -------------------------------------------------------------------------------- 1 | float f(void); 2 | float f(void) { return 0.0; } 3 | 4 | void g(void); 5 | void g(void) { } 6 | 7 | void h(int); 8 | void h(int x) { } 9 | 10 | void i(void); 11 | void i(void) { } 12 | 13 | void j(int, int); 14 | void j(int x, int y) { } 15 | 16 | void k(int, int); 17 | void k(a, b) int a; int b; { } 18 | 19 | void l(); 20 | void l(int x) { } 21 | 22 | void m(); 23 | void m(double x) { } 24 | 25 | void n(const int *x); 26 | void n(const int *x) { } 27 | 28 | int main(void) { 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j080.c: -------------------------------------------------------------------------------- 1 | struct s { 2 | unsigned:32; 3 | int x; 4 | } s; 5 | 6 | int main(void) { 7 | struct s t = s; 8 | return s.x; 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j081.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 0; 3 | int y = {0}; 4 | return x + y; 5 | } 6 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j082.c: -------------------------------------------------------------------------------- 1 | struct s { 2 | int x; 3 | int y; 4 | }; 5 | 6 | int main(void) { 7 | struct s s0 = {0}; 8 | struct s s1 = {0, 1}; 9 | struct s s2 = s1; 10 | return s0.x + s1.x + s2.x; 11 | } 12 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j083.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int a[] = {0}; 3 | return a[0]; 4 | } 5 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j084-link1.c: -------------------------------------------------------------------------------- 1 | extern int a; 2 | int a = 0; 3 | 4 | extern int b; 5 | extern int c; 6 | 7 | int main(void) { 8 | return a + c; 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j084-link2.c: -------------------------------------------------------------------------------- 1 | int c; 2 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j085.c: -------------------------------------------------------------------------------- 1 | int f(a) 2 | int a; 3 | { 4 | return a; 5 | } 6 | 7 | int g(a, b) 8 | int a; int b; 9 | { 10 | return a; 11 | } 12 | 13 | int h(a, b, c) 14 | int a; int b; int c; 15 | { 16 | return a; 17 | } 18 | 19 | 20 | int main(void){ 21 | return f(0); 22 | } 23 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j086.c: -------------------------------------------------------------------------------- 1 | struct s { int x; } s; 2 | 3 | int f(struct s s) { 4 | return 0; 5 | } 6 | 7 | union u { int x; } u; 8 | 9 | int g(union u u) { 10 | return 0; 11 | } 12 | 13 | int main(void) { 14 | return f(s) + g(u); 15 | } 16 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j087.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int f(int x, int y, ...) { 4 | va_list ap; 5 | va_start(ap, y); 6 | int z = va_arg(ap, int); 7 | va_end(ap); 8 | return z; 9 | } 10 | int main(void) { 11 | return f(5, 6, 0); 12 | } 13 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j088.c: -------------------------------------------------------------------------------- 1 | int f() { 2 | return 0; 3 | } 4 | 5 | int g() { } 6 | 7 | int main(void) { 8 | f(); 9 | f() + 0; 10 | // g(); // This probably shouldn't count as a use. 11 | return f(); 12 | } 13 | -------------------------------------------------------------------------------- /tests/defined-ellison/unsorted/j089.c: -------------------------------------------------------------------------------- 1 | static int a[2]; 2 | 3 | struct s { int x; }; 4 | 5 | static struct s b; 6 | 7 | int c[]; 8 | 9 | static int d; 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/defined/abort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | 1 ? (void)printf("foo") : abort(); 6 | } 7 | -------------------------------------------------------------------------------- /tests/defined/assignment_plus.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int x = INT_MAX; 6 | x += INT_MAX + 3U; 7 | printf("%d\n", x); 8 | } 9 | -------------------------------------------------------------------------------- /tests/defined/big_array.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[1000]; 3 | for (int i = 0; i < 1000; i++) a[i] = i; 4 | return a[10]; 5 | } 6 | -------------------------------------------------------------------------------- /tests/defined/boring_slow_nondet.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) { 5 | int x = 10, *p = &x; 6 | return *p + *p + *p + *p + *p + *p; 7 | } 8 | -------------------------------------------------------------------------------- /tests/defined/byte_copy.c: -------------------------------------------------------------------------------- 1 | 2 | int main() { 3 | struct { short x, *r; } s1, s2; 4 | s1.x = 10; 5 | s1.r = &s1.x; 6 | for (int i = 0; i < sizeof(s1); i++) 7 | ((unsigned char*)&s2)[i] = ((unsigned char*)&s1)[i]; 8 | return *s2.r; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/defined/duff.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void duffs_device(unsigned char *from, unsigned char *to, int count) { 4 | int n = (count + 7) / 8; 5 | switch(count % 8) { 6 | case 0: do { *to++ = *from++; 7 | case 7: *to++ = *from++; 8 | case 6: *to++ = *from++; 9 | case 5: *to++ = *from++; 10 | case 4: *to++ = *from++; 11 | case 3: *to++ = *from++; 12 | case 2: *to++ = *from++; 13 | case 1: *to++ = *from++; 14 | } while(--n > 0); 15 | } 16 | } 17 | 18 | int main() { 19 | long long a[10], b[10]; 20 | for (int i = 0; i < 10; i++) a[i] = i; 21 | duffs_device((unsigned char*)a, (unsigned char*)b, sizeof(a)); 22 | for (int i = 0; i < 10; i++) printf("%d\n", b[i]); 23 | } 24 | -------------------------------------------------------------------------------- /tests/defined/end_of_array.c: -------------------------------------------------------------------------------- 1 | void inc_array(int *p, int n) { 2 | int *end = p + n; 3 | while (p < end) (*p++)++; 4 | } 5 | 6 | int main() { 7 | int a[4]; 8 | for (int i = 0; i < 4; i++) a[i] = i; 9 | inc_array(a,4); 10 | return a[3]; 11 | } 12 | -------------------------------------------------------------------------------- /tests/defined/fib.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int x; 4 | 5 | 6 | int set_x(int ret_val) 7 | { 8 | x=1; 9 | return ret_val; 10 | } 11 | 12 | 13 | int two_unspec(void) 14 | { 15 | x=0; 16 | return x + set_x(1); 17 | } 18 | 19 | 20 | int add_zero(int val) 21 | { 22 | x=0; 23 | return val - x + set_x(0); 24 | } 25 | 26 | 27 | int fib(int fib_num) 28 | { 29 | if (fib_num > 3) 30 | return fib(fib_num-2) + add_zero(fib(fib_num-1)); 31 | else 32 | if (fib_num == 3) 33 | return two_unspec(); 34 | else 35 | return 1; 36 | } 37 | 38 | int main(void) 39 | { 40 | int n; 41 | 42 | // scanf("%d", &n); 43 | n=5; 44 | printf("Fibonacci %d = %d\n", n, fib(n)); 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /tests/defined/gcd.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void swap(int *p, int *q) { 4 | int z = *p; *p = *q; *q = z; 5 | } 6 | int gcd(int y, int z) { 7 | l: if (z) { 8 | y = y % z; swap(&y, &z); goto l; 9 | } 10 | return y; 11 | } 12 | 13 | int main() { 14 | for (int i = 0; i < 10; i++) { 15 | for (int j = 0; j < 10; j++) { 16 | printf("gcd %d %d = %d\n", i, j, gcd(i,j)); 17 | } 18 | } 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /tests/defined/global_initializer.c: -------------------------------------------------------------------------------- 1 | struct { int x, *p ; } s; 2 | 3 | int main() { return s.x; } 4 | -------------------------------------------------------------------------------- /tests/defined/incomplete_typedef.c: -------------------------------------------------------------------------------- 1 | typedef struct S T; 2 | struct S { int x; }; 3 | 4 | int main() { 5 | T s; s.x = 10; 6 | return s.x; 7 | } 8 | -------------------------------------------------------------------------------- /tests/defined/int_regehr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* From http://www.cs.utah.edu/~regehr/papers/overflow12.pdf */ 5 | int main() { 6 | printf("UINT_MAX+1 = %d\n", UINT_MAX+1); 7 | printf("SHRT_MAX+1 = %d\n", SHRT_MAX+1); 8 | printf("1 << 0 = %d\n", 1 << 0); 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined/malloc_nondet.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | if(malloc(1)) { 6 | printf("foo\n"); 7 | } else { 8 | printf("bar\n"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/defined/memoization.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int expensive_function(int y) { 4 | printf("very expensive identity\n"); 5 | return y; 6 | } 7 | 8 | int f(int y) { 9 | static int map[10]; 10 | if (map[y]) { return map[y]; } 11 | return map[y] = expensive_function(y); 12 | } 13 | 14 | int main() { 15 | return f(2) + f(2); 16 | } 17 | -------------------------------------------------------------------------------- /tests/defined/mutual_recursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int even(int); 4 | 5 | int main() { 6 | for (int i = 0; i < 10; i++) printf("even %d = %d\n", i, even(i)); 7 | } 8 | 9 | int odd(int x) { 10 | if (x == 0) return 0; else return even (x - 1); 11 | } 12 | int even(int x) { 13 | if (x == 0) return 1; else return odd (x - 1); 14 | } 15 | -------------------------------------------------------------------------------- /tests/defined/my_memcpy.c: -------------------------------------------------------------------------------- 1 | void my_memcpy(void *dest, void *src, int n) { 2 | unsigned char *p = dest, *q = src, *end = p + n; 3 | while (p < end) // end may be end-of-array 4 | *p++ = *q++; 5 | } 6 | 7 | int main() { 8 | struct S { short x; short *r; } s, s2; 9 | s.x = 10; 10 | s.r = &s.x; 11 | my_memcpy(&s2, &s, sizeof(struct S)); 12 | return *(s2.r); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /tests/defined/no_return.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int f() { 4 | if(1) return 10; 5 | } 6 | 7 | int main() { 8 | printf("%d\n", f()); 9 | } 10 | -------------------------------------------------------------------------------- /tests/defined/non_det_function_call.c: -------------------------------------------------------------------------------- 1 | int x = 0; 2 | int f(int y) { return (x = y); } 3 | int main() { f(3) + f(4); return x; } 4 | 5 | -------------------------------------------------------------------------------- /tests/defined/non_det_prinfs.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | return printf("a") + (printf("b") + printf("c")); 5 | } 6 | -------------------------------------------------------------------------------- /tests/defined/overflow.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int f(int x) { return x < x + 1; } 5 | 6 | int main() { 7 | printf("SHRT_MAX < SHRT_MAX+1 = %d\n", f(SHRT_MAX)); 8 | } 9 | -------------------------------------------------------------------------------- /tests/defined/pointer_comp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int x, y; 6 | printf("%d\n", &x == &y); 7 | int *p = malloc(sizeof(int)), *q = malloc(sizeof(int)); 8 | printf("%d\n", p == q); 9 | struct S { int a; int b; } s, *r = &s; 10 | printf("%d\n", &s.a + 1 == &(r->b)); 11 | } 12 | -------------------------------------------------------------------------------- /tests/defined/recursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int id(int x) { 4 | if (x == 0) return 0; else return 1 + id(x - 1); 5 | } 6 | 7 | int main() { 8 | for (int i = 0; i < 10; i++) { 9 | int j = i * 30; 10 | printf("id %d = %d\n", j, id(j)); 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /tests/defined/return_pointer.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int x = 314; 4 | 5 | int* f() { return 0; } 6 | int** g() { return 0; } 7 | int* h() { 8 | int x; 9 | { 10 | extern int x; 11 | return &x; 12 | } 13 | } 14 | int main() { 15 | printf("%d\n", *h()); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /tests/defined/shadowing.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int x; 4 | 5 | int main() { 6 | if (x != 10) printf("ERROR 1\n"); 7 | { 8 | int x = 11; 9 | if (x != 11) printf("ERROR 2\n"); 10 | { 11 | extern int x; 12 | if (x != 10) printf("ERROR 3\n"); 13 | } 14 | } 15 | int *p; 16 | { 17 | static int y; 18 | if (y != 0) printf("ERROR 4\n"); 19 | { 20 | int y = 14; 21 | if (y != 14) printf("ERROR 5\n"); 22 | } 23 | p = &y; 24 | y = 16; 25 | } 26 | if (*p != 16) printf("ERROR 6\n"); 27 | return 0; 28 | } 29 | 30 | int x = 10; 31 | int x; 32 | -------------------------------------------------------------------------------- /tests/slow/Y.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef union word word; 5 | union word {int _i; void *_p; word (*_f)(word, word *);}; 6 | 7 | #define return2(x, y) \ 8 | word *c = malloc(2*sizeof(word)); \ 9 | c[0] = x; c[1] = y; return (word){._p = c} 10 | 11 | #define lambda_0free(f, x, t) \ 12 | word _##f(word x, word *z) {return t;} \ 13 | word __##f = {._f = &_##f}; \ 14 | word f = {._p = &__##f}; 15 | 16 | #define lambda_1free(f, y, x, t) \ 17 | word _##f(word x, word *z) {word y = *z; return t;} \ 18 | word f(word y) {return2((word){._f = &_##f}, y);} 19 | 20 | word apply(word f, word x) {word *c = f._p; return (*c->_f)(x, c + 1);} 21 | word lazy_apply(word f, word x) {return2(f, x);} 22 | word force(word e) {word *c = e._p, r = apply(c[0], c[1]); free(c); return r;} 23 | 24 | /* 25 | omega f := \x.f(xx) 26 | fix := \f.(\x.f(xx))(\x.f(xx)) 27 | fact f := \x. [x ? x*f(x - 1) : 1] 28 | fact_ := \f x. [x ? x*f(x - 1) : 1] 29 | */ 30 | 31 | lambda_1free(omega, f, x, apply(f, lazy_apply(x, x))) 32 | lambda_0free(fix, f, apply(omega(f), omega(f))) 33 | lambda_1free(fact, f, x, (word){._i = 34 | x._i ? x._i*apply(force(f), (word){._i = x._i - 1})._i : 1}) 35 | lambda_0free(fact_, f, fact(f)) 36 | 37 | int main() {printf("%d weeks\n", 38 | apply(apply(fix, fact_), (word){._i = 10})._i /60/60/24/7);} 39 | -------------------------------------------------------------------------------- /tests/undefined-ellison/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2009-2011 by Charles M. Ellison III 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j004a.c: -------------------------------------------------------------------------------- 1 | float main(void){ 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j004b.c: -------------------------------------------------------------------------------- 1 | int main(int n){ 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j004c.c: -------------------------------------------------------------------------------- 1 | int _main(void){ 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j004d.c: -------------------------------------------------------------------------------- 1 | void main(void){ 2 | 3 | } 4 | 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j004e.c: -------------------------------------------------------------------------------- 1 | int main(float x, char** y){ 2 | } 3 | 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j004f.c: -------------------------------------------------------------------------------- 1 | int main(int x, float* y){ 2 | 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j004g.c: -------------------------------------------------------------------------------- 1 | int main(int a, char** b, int c){ 2 | 3 | } 4 | 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j004h.c: -------------------------------------------------------------------------------- 1 | int main(int x){ } 2 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j008a.c: -------------------------------------------------------------------------------- 1 | int f(void); 2 | 3 | static int f(void){ 4 | return 0; 5 | } 6 | 7 | int main(void){ 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j008b.c: -------------------------------------------------------------------------------- 1 | int f(void); 2 | 3 | static int f(void){ 4 | return 0; 5 | } 6 | 7 | int main(void){ 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j008c.c: -------------------------------------------------------------------------------- 1 | extern int x; 2 | static int x; 3 | 4 | int main(void){ 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j008d.c: -------------------------------------------------------------------------------- 1 | extern int x; 2 | static int x; 3 | 4 | int main(void){ 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j008e.c: -------------------------------------------------------------------------------- 1 | extern static int x; 2 | 3 | int main(void){ 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j008f.c: -------------------------------------------------------------------------------- 1 | extern static int f(void){ 2 | return 0; 3 | }; 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j009a.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int* p; 3 | { 4 | int x = 5; 5 | p = &x; 6 | } // the memory for x should not be accessible now 7 | int y = *p; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j009b.c: -------------------------------------------------------------------------------- 1 | int* f(void){ 2 | int x = 5; 3 | return &x; 4 | } 5 | int main(void){ 6 | int* p = f(); 7 | int y = *p; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j009c.c: -------------------------------------------------------------------------------- 1 | int* f(){ 2 | { 3 | int x = 5; 4 | return &x; 5 | } 6 | } 7 | int main(void){ 8 | int* p = f(); 9 | int y = *p; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j009d.c: -------------------------------------------------------------------------------- 1 | int* f(){ 2 | int z = 6; 3 | { 4 | int x = 5; 5 | return &z; 6 | } 7 | } 8 | int main(void){ 9 | int* p = f(); 10 | int y = *p; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j009e.c: -------------------------------------------------------------------------------- 1 | int* f(int z){ 2 | { 3 | return &z; 4 | } 5 | } 6 | int main(void){ 7 | int* p = f(5); 8 | int y = *p; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j009f.c: -------------------------------------------------------------------------------- 1 | // this program shouldn't run 2 | int main(void) { 3 | { 4 | int x = 5; 5 | } 6 | x; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j009g.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void){ 4 | int *p = malloc(sizeof(int)); 5 | *p = 5; 6 | free(p); 7 | *p; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j009h.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int* sneaky; 5 | _Thread_local int p = 5; 6 | 7 | int f(void* p){ 8 | sneaky = &p; 9 | return 0; 10 | } 11 | 12 | int main(void){ 13 | int threadId; 14 | int retval; 15 | thrd_create(&threadId, f, NULL); 16 | thrd_join(threadId, &retval); // thread f is now dead 17 | *sneaky; 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j009i.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int* p; 3 | { int x; p = &x; } 4 | *p; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j009j.c: -------------------------------------------------------------------------------- 1 | int* f(int z){ 2 | { 3 | return &z; 4 | } 5 | } 6 | int main(void){ 7 | f(5); 8 | int y = 0; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j010a.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int* p = 0; 3 | { 4 | int x; 5 | p = &x; 6 | } 7 | p; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j010b.c: -------------------------------------------------------------------------------- 1 | int* f(void) { 2 | int x; 3 | return &x; 4 | } 5 | int main(void) { 6 | int* p = f(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j010c.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int i = 0; 3 | int* p; 4 | while (i < 10){ 5 | int x = 2; 6 | i++; 7 | p = &x; 8 | } 9 | *p; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j010d.c: -------------------------------------------------------------------------------- 1 | // this program shouldn't run 2 | 3 | int* f(void){ 4 | int x = 5; 5 | return &x; 6 | } 7 | int main(void){ 8 | f(); 9 | int y = 0; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j010e.c: -------------------------------------------------------------------------------- 1 | int* f(){ 2 | { 3 | int x = 5; 4 | return &x; 5 | } 6 | } 7 | int main(void){ 8 | f(); 9 | int y = 0; 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j010f.c: -------------------------------------------------------------------------------- 1 | // this program shouldn't run 2 | 3 | int* f(){ 4 | int z = 6; 5 | { 6 | int x = 5; 7 | return &z; 8 | } 9 | } 10 | int main(void){ 11 | f(); 12 | int y = 0; 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j011a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x; 3 | x + 1; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j011b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | goto l; 3 | int x = 0; 4 | l: 5 | x + 1; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j012a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x; 3 | x; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j013a.c: -------------------------------------------------------------------------------- 1 | struct { 2 | int x; 3 | int y; 4 | } s; 5 | 6 | int main(void) { 7 | int x; 8 | s.x = x; 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j014a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | ~0; // Negative zero for sign/mag. 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j014b.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | ~INT_MAX; // Negative zero for ones' and two's complement. 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j014c.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | -3 | INT_MAX; // All ones, negative zero for ones' complement. 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j014d.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | (99 ^ ~99); // Negative zero for sign/mag and two's complement. 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j015a.c: -------------------------------------------------------------------------------- 1 | int f(void); 2 | 3 | int f(int); 4 | 5 | int f(void) { 6 | return 0; 7 | } 8 | 9 | int main(void) { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j015b.c: -------------------------------------------------------------------------------- 1 | int f(void); 2 | 3 | float f(void); 4 | 5 | float f(void) { 6 | return 0; 7 | } 8 | 9 | int main(void) { 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j015c.c: -------------------------------------------------------------------------------- 1 | extern int x; 2 | float x = 0; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j015d-link1.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | 3 | int main(void){ 4 | f(5); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j015d-link2.c: -------------------------------------------------------------------------------- 1 | int f(const int x){ 2 | return x; 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j016a.c: -------------------------------------------------------------------------------- 1 | void f(int n, int (*)[n]); 2 | void f(int n, int (*)[n*n]); 3 | 4 | void f(int n, int (*a)[n]) { } 5 | 6 | int main(void) { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j016b.c: -------------------------------------------------------------------------------- 1 | void f(int n, int (*)[n]); 2 | void f(int n, int (*)[n]); 3 | 4 | void f(int n, int (*a)[n]) { } 5 | 6 | int main(void) { 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j017a.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | signed char x; 3 | double y = 300; 4 | x = y; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j017b.c: -------------------------------------------------------------------------------- 1 | #include 2 | int f(int x){ 3 | return x; 4 | } 5 | 6 | int main(void){ 7 | f(INT_MAX * 2.0); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j017c.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | unsigned char x; 3 | double y = 300; 4 | x = y; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j018a.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | float x = pow(10.0, 39.0); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j019a.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | *(char*)10; 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j019b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | char a[5] = {1, 2, 3, 4, 5}; 3 | return *(int*)(&a[4]); 4 | } 5 | 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j020a.c: -------------------------------------------------------------------------------- 1 | struct s s0; 2 | 3 | int main(void){ 4 | struct s s1 = s0; 5 | return 0; 6 | } 7 | 8 | struct s { 9 | int x; 10 | }; 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j020b.c: -------------------------------------------------------------------------------- 1 | union s s0; 2 | 3 | int main(void){ 4 | union s s1 = s0; 5 | return 0; 6 | } 7 | 8 | union s { 9 | int x; 10 | }; 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j021a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x; 3 | x; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j021b.c: -------------------------------------------------------------------------------- 1 | int f(int x) { 2 | return x; 3 | } 4 | 5 | int main(void) { 6 | int x; 7 | f(x); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j021c.c: -------------------------------------------------------------------------------- 1 | int test1(void) { 2 | goto test1a; 3 | int x = 0; // we skip over the init (although the memory is allocated) 4 | test1a: 5 | return x; 6 | } 7 | 8 | int main(void) { 9 | test1(); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j021d.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | float x; 3 | x; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j021e.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int* p; 3 | p; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j022a.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | register int a[5] = {0}; 3 | a[0]; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j022b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | register int a[5] = {0}; 3 | a; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j023a.c: -------------------------------------------------------------------------------- 1 | void f() { } 2 | 3 | int main(void) { 4 | f() + 1; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j023b.c: -------------------------------------------------------------------------------- 1 | void f() { } 2 | 3 | int main(void) { 4 | return f(); 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j023c.c: -------------------------------------------------------------------------------- 1 | void f() { } 2 | int g(int n) { return 0; } 3 | 4 | int main(void) { 5 | return g(f()); 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j023d.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | return (int)((void) 0); 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j023e.c: -------------------------------------------------------------------------------- 1 | void f() { } 2 | 3 | int main(void) { 4 | (int) f(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j023f.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int x; 3 | x = (void)5; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j024a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | short x; 3 | short *p = &x; 4 | 5 | x = (short)p; 6 | 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j025a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | char x; 3 | _Alignas(32) int *p = (int*) &x; 4 | 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j026a.c: -------------------------------------------------------------------------------- 1 | int f(int x){ 2 | return x; 3 | } 4 | 5 | int main(void){ 6 | int (*x)(double) = (int (*)(double))&f; 7 | return x(5); 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j026b.c: -------------------------------------------------------------------------------- 1 | int f(const int * x){ 2 | return 0; 3 | } 4 | 5 | int main(void){ 6 | int x = 5; 7 | int (*g)(int*) = (int (*) (int*))&f; 8 | return g(&x); 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j026c.c: -------------------------------------------------------------------------------- 1 | int f(unsigned x){ 2 | return 0; 3 | } 4 | 5 | int main(void){ 6 | int x = 5; 7 | int (*g)(int) = (int (*) (int))&f; 8 | return g(x); 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j032a.c: -------------------------------------------------------------------------------- 1 | int __func__(void) { 2 | return 0; 3 | } 4 | int main(void) { 5 | return __func__(); 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j032b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int __func__ = 0; 3 | return __func__; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j033a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | "hello"[0] = 'x'; 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j033b.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | char (*s)[6]; 3 | s = &"hello"; 4 | (*s)[0] = 'x'; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j033c.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | "hello\n"; 5 | "hello\n"[0] = 'x'; 6 | printf("hello\n"); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j035a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 0; 3 | return (x = 1) + x; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j035b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 0; 3 | return (x = 1) / (x = 1); 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j035c.c: -------------------------------------------------------------------------------- 1 | int f(int a, int b) { 2 | return 0; 3 | } 4 | 5 | int main(void) { 6 | int x = 0; 7 | return f(x = 0, x); 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j035d.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 0; 3 | return ++x + x; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j035e.c: -------------------------------------------------------------------------------- 1 | int foo (int *p1, int *p2) { 2 | return (*p1)++ + (*p2)++; 3 | } 4 | 5 | int main (void) { 6 | int a = 0; 7 | foo (&a, &a); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j035f.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int x = 0; 3 | "hi0"[0] + x++ + "hi1"[0] + x++ + "hi2"[0]; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j036a.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | INT_MIN % -1; 4 | return 0; 5 | } 6 | 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j036b.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) { 3 | INT_MAX + 1; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j036c.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void){ 4 | (long long) 0 || INT_MAX+1; 5 | return 0; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j037a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 5; 3 | float* p = (float*)&x; 4 | *p; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j037b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 5; 3 | *((int**)&x); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j037c.c: -------------------------------------------------------------------------------- 1 | int x = 10; 2 | int* a; 3 | float* b; 4 | 5 | int main(void) { 6 | a = &x; 7 | b = (float*)a; 8 | *b; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j037d.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 10; 3 | int* a; 4 | float* b; 5 | void* p; 6 | 7 | a = &x; 8 | p = a; 9 | b = p; 10 | *b; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j037e.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 10; 3 | int* a; 4 | long* b; 5 | 6 | a = &x; 7 | b = (long*)a; 8 | *b; 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j037f.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 10; 3 | int* a; 4 | long* b; 5 | void* p; 6 | 7 | a = &x; 8 | p = a; 9 | b = p; 10 | *b; 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j037g.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int (*p)[10] = malloc(sizeof(int) * 10); 5 | 6 | (*p)[1] = 42; 7 | 8 | (*(long(*)[10])p)[1] = 42; 9 | 10 | return (*p)[1]; 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j037h.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int *p = malloc(sizeof(int)); 5 | 6 | *(long*)p = 42; 7 | 8 | return *p; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j038a.c: -------------------------------------------------------------------------------- 1 | int foo(); 2 | 3 | int main(void) { 4 | foo(); 5 | return 0; 6 | } 7 | 8 | int foo(int a, int b) { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j038b.c: -------------------------------------------------------------------------------- 1 | int foo(); 2 | 3 | int main(void) { 4 | foo(5); 5 | return 0; 6 | } 7 | 8 | int foo() { 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j038c.c: -------------------------------------------------------------------------------- 1 | int foo(a) 2 | int a; 3 | { 4 | return 0; 5 | } 6 | 7 | int main(void) { 8 | foo(5, 6); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j039a.c: -------------------------------------------------------------------------------- 1 | int f(int x, ...) { 2 | return x; 3 | } 4 | 5 | int main(void) { 6 | return ((int (*)())f)(0); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j039b.c: -------------------------------------------------------------------------------- 1 | int f(float x) { 2 | return (int) x; 3 | } 4 | 5 | int main(void) { 6 | return ((int (*)())f)(0.0); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j039c-link1.c: -------------------------------------------------------------------------------- 1 | int foo(); 2 | 3 | int main(void) { 4 | foo(5, 7); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j039c-link2.c: -------------------------------------------------------------------------------- 1 | int foo(int a, int b, ...) { 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j039d-link1.c: -------------------------------------------------------------------------------- 1 | int foo(); 2 | 3 | int main(void){ 4 | foo(5); 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j039d-link2.c: -------------------------------------------------------------------------------- 1 | int foo(double a){ 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j039e-link1.c: -------------------------------------------------------------------------------- 1 | int foo(); 2 | 3 | int main(void){ 4 | foo((char)5); 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j039e-link2.c: -------------------------------------------------------------------------------- 1 | int foo(char x){ 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j040a.c: -------------------------------------------------------------------------------- 1 | int f(x) 2 | int x; 3 | { 4 | return x; 5 | } 6 | int main(void){ 7 | return f(5.5); 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j040b.c: -------------------------------------------------------------------------------- 1 | int f(p) 2 | int* p; 3 | { 4 | return *p; 5 | } 6 | int main(void) { 7 | long long int x = 5; 8 | return f(&x); 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j040c.c: -------------------------------------------------------------------------------- 1 | int f(x) 2 | float x; 3 | { 4 | return 0; 5 | } 6 | int main(void){ 7 | return f(32); 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j041a.c: -------------------------------------------------------------------------------- 1 | // based on example by Derek Jones 2 | 3 | #include 4 | #include 5 | 6 | int g(double v) { 7 | return 0; 8 | } 9 | 10 | struct s { 11 | int (*f1)(int); 12 | int (*f2)(double); 13 | } x; 14 | 15 | int (**pf)(int); 16 | 17 | int main(void) { 18 | x.f2 = g; 19 | pf = &x.f1; 20 | pf = (int (**)(int))((char*)&x + offsetof(struct s, f2)); 21 | (**pf)(2); 22 | } 23 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j041b-link1.c: -------------------------------------------------------------------------------- 1 | int f(int); 2 | 3 | int main(void) { 4 | return f(42); 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j041b-link2.c: -------------------------------------------------------------------------------- 1 | int f(void) { return 0; } 2 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j041c-link1.c: -------------------------------------------------------------------------------- 1 | int f(const int*); 2 | 3 | int main(void) { 4 | int p = 42; 5 | return f(&p); 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j041c-link2.c: -------------------------------------------------------------------------------- 1 | int f(int *p) { return 0; } 2 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j041d-link1.c: -------------------------------------------------------------------------------- 1 | int f(int * restrict); 2 | 3 | int main(void) { 4 | int p = 42; 5 | return f(&p); 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j041d-link2.c: -------------------------------------------------------------------------------- 1 | int f(int *p) { return 0; } 2 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j042a.c: -------------------------------------------------------------------------------- 1 | _Atomic struct s { 2 | int x; 3 | } s; 4 | 5 | int main(void) { 6 | return s.x; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j042b.c: -------------------------------------------------------------------------------- 1 | _Atomic union u { 2 | int x; 3 | } u; 4 | 5 | int main(void) { 6 | return u.x; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j043a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[5] = {1, 2, 3, 4, 5}; 3 | *(&a[5]); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j043b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | *((int*)42); 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j044a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 5; 3 | int *p = &x; 4 | (double)p; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j044b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 5; 3 | int *p = &x; 4 | (float)p; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j044c.c: -------------------------------------------------------------------------------- 1 | struct str {int *x;}; 2 | 3 | int main(void) { 4 | int x = 5; 5 | int *p = &x; 6 | (struct str)p; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j044d.c: -------------------------------------------------------------------------------- 1 | union str {int *x;}; 2 | 3 | int main(void) { 4 | int x = 5; 5 | int *p = &x; 6 | (union str)p; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j045a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | return 1/0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j045b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | return 1%0; 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j045c.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 0; 3 | return 1/x; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j045d.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 0; 3 | return 1 % x; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j045e.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 0; 3 | int *p = &x; 4 | 5 / *p; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j045f.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int x = 0; 3 | int *p = &x; 4 | 5 % *p; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j046a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a; 3 | &a+2; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j046b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[2]; 3 | (a + 3); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j046c.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a; 3 | &a - 1; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j047a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a = 5; 3 | *(&a + 1); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j047b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a = 5; 3 | *(&a - (-1)); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j047c.c: -------------------------------------------------------------------------------- 1 | int a[3]; 2 | int main(void) { 3 | a[3]; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j047d.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[3][4]; 3 | *(a + 3); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j048a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[3]; 3 | int b[2]; 4 | &a[2] - &b[1]; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j048b.c: -------------------------------------------------------------------------------- 1 | void f(int a, int b) { 2 | &b - &a; 3 | } 4 | int main(void) { 5 | f(5, 6); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j049a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[4][5] = {0}; 3 | a[1][7]; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j049b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[4][3] = {0}; // theoretically 4 * 3 memory slots 3 | int z = a[0][4]; // but not allowed to go out of bounds in any dimension 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j049c.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[4][5] = {0}; 3 | *(*a + 3 + 4); 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j050a.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(void) { 6 | if (sizeof(ptrdiff_t) == sizeof(int)) { 7 | unsigned char *ptr0 = malloc(((unsigned)INT_MAX) + 1); 8 | 9 | unsigned char *ptr1 = ptr0 + (unsigned)INT_MAX + 1; 10 | 11 | ptr1 - ptr0; 12 | } 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j051a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int s = -1; 3 | 4 | 1 << s; 5 | 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j051b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int s = -1; 3 | 4 | 1 >> s; 5 | 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j051c.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int s = sizeof(unsigned) * CHAR_BIT; 5 | 6 | ((unsigned)1) << s; 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j051d.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | int s = sizeof(int) * CHAR_BIT; 5 | 6 | 1 >> s; 7 | 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j052a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | -1 << 5; 3 | return 0; 4 | } 5 | 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j052b.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | INT_MAX << 2; 5 | return 0; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j053a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a; 3 | int b; 4 | if (&a >= &b) { 5 | return 0; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j053b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | struct {int x; } a; 3 | struct {int x; } b; 4 | 5 | int* p = &a.x; 6 | int* q = &b.x; 7 | 8 | if (&p < &q) { 9 | return 0; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j053c.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[3] = {0}; 3 | int b; 4 | 5 | int *p = &a[0] + 3; 6 | int *q = &b; 7 | 8 | if (&p <= &q) { 9 | return 0; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j054a.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | long long *p = malloc(sizeof(long long)); 5 | 6 | *p = 5; 7 | 8 | *p = *(short*)p; 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j054b.c: -------------------------------------------------------------------------------- 1 | struct big_type { 2 | int arr[32]; 3 | }; 4 | union u { 5 | struct s1 { char c; struct big_type bt1; } sub1; 6 | struct s2 { long long x; struct big_type bt2; } sub2; 7 | } obj; 8 | 9 | int main(void) { 10 | obj.sub2.bt2 = obj.sub1.bt1; 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j054c.c: -------------------------------------------------------------------------------- 1 | // From the frama-c value analysis manual/tutorial, p. 37. 2 | 3 | struct S { int a; int b; int c; }; 4 | struct T { int p; struct S s; }; 5 | union U { struct S s; struct T t; } u; 6 | 7 | void copy(struct S *p, struct S *q) { 8 | *p = *q; 9 | } 10 | 11 | int main(int c, char **v) { 12 | u.s.b = 1; 13 | copy(&u.t.s, &u.s); 14 | return u.t.s.a + u.t.s.b + u.t.s.c; 15 | } 16 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j055a.c: -------------------------------------------------------------------------------- 1 | struct s { 2 | int s : 5.5; 3 | }; 4 | 5 | int main(void){ 6 | 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j055b.c: -------------------------------------------------------------------------------- 1 | enum e {a = 5.5}; 2 | int main(void){ 3 | 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j055c.c: -------------------------------------------------------------------------------- 1 | int x; 2 | enum e {a = &x}; 3 | int main(void){ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j055d.c: -------------------------------------------------------------------------------- 1 | int a[5.5]; 2 | int main(void){ 3 | 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j055e.c: -------------------------------------------------------------------------------- 1 | int x; 2 | enum e {a = 5 + (int)&x}; 3 | int main(void){ 4 | 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j056a.c: -------------------------------------------------------------------------------- 1 | static int f(void) { 2 | return 0; 3 | } 4 | 5 | int x = f(); 6 | 7 | int main(void){ 8 | return x; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j056b.c: -------------------------------------------------------------------------------- 1 | int a = 9; 2 | int x = a; 3 | 4 | int main(void){ 5 | return 0; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j056c.c: -------------------------------------------------------------------------------- 1 | struct { 2 | int f; 3 | } a; 4 | 5 | int x = a.f; 6 | 7 | int main(void){ 8 | return 0; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j057a.c: -------------------------------------------------------------------------------- 1 | int x = 1; 2 | int y = 1 + x; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j057b.c: -------------------------------------------------------------------------------- 1 | int f(void) { return 1; } 2 | 3 | int x = 1 + f(); 4 | 5 | int main(void) { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j058a.c: -------------------------------------------------------------------------------- 1 | int x, y; 2 | int* a[2] = {&x, &y}; 3 | 4 | int *p = a[0]; 5 | int main(void){ 6 | return *p; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j058b.c: -------------------------------------------------------------------------------- 1 | int x, y; 2 | struct { 3 | int* p1; 4 | int* p2; 5 | } a = {&x, &y}; 6 | 7 | int *p = a.p1; 8 | int main(void){ 9 | return *p; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j058c.c: -------------------------------------------------------------------------------- 1 | int x, y; 2 | struct _a { 3 | int* p1; 4 | int* p2; 5 | } a = {&x, &y}; 6 | struct _a *ap = &a; 7 | int *p = ap->p1; 8 | int main(void){ 9 | return *p; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j058d.c: -------------------------------------------------------------------------------- 1 | int x, y; 2 | int* a1 = &x; 3 | int** a = &a1; 4 | int *p = *a; 5 | int main(void){ 6 | return *p; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j058e.c: -------------------------------------------------------------------------------- 1 | double x, y; 2 | double* p0 = &x; 3 | double *p = (double*)p0; 4 | int main(void){ 5 | return *p; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j059a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[]; 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j059b.c: -------------------------------------------------------------------------------- 1 | struct s; 2 | 3 | int main(void) { 4 | struct s a; 5 | return 0; 6 | } 7 | 8 | struct s { int x; }; 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j059c.c: -------------------------------------------------------------------------------- 1 | union s; 2 | 3 | int main(void) { 4 | union s a; 5 | return 0; 6 | } 7 | 8 | union s { int x; int y; }; 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j059d.c: -------------------------------------------------------------------------------- 1 | typedef int t[]; 2 | 3 | int main(void) { 4 | t a = {0}, b; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j059e.c: -------------------------------------------------------------------------------- 1 | typedef struct s s; 2 | 3 | int main(void) { 4 | s a; 5 | return 0; 6 | } 7 | 8 | struct s { int x; }; 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j059f.c: -------------------------------------------------------------------------------- 1 | typedef union u u; 2 | 3 | int main(void) { 4 | u a; 5 | return 0; 6 | } 7 | 8 | union u { int x; int y; }; 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j060a.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int f(); 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j060b.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | static int f(); 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j061a.c: -------------------------------------------------------------------------------- 1 | struct s { 2 | }; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j061b.c: -------------------------------------------------------------------------------- 1 | union s { 2 | }; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j062a.c: -------------------------------------------------------------------------------- 1 | struct _s { 2 | int x; 3 | int a[]; 4 | } s; 5 | 6 | int main(void) { 7 | s.a[0]; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j062b.c: -------------------------------------------------------------------------------- 1 | struct _s { 2 | int x; 3 | int a[]; 4 | } s; 5 | 6 | int main(void) { 7 | &(s.a[1]); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j063a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | struct s s; 3 | struct s { int x; }; 4 | 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j063b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | union u u; 3 | union u { int x; }; 4 | 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j064a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | const int x = 0; 3 | unsigned char* p = (unsigned char*)&x; 4 | *p = 5; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j064b.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | const char p[] = "hello"; 5 | char *q = strchr(p, p[0]); 6 | q[0] = 'x'; 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j065a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | volatile int x = 5; 3 | *(int*)&x; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j065b.c: -------------------------------------------------------------------------------- 1 | int f(int* x) { 2 | return *x; 3 | } 4 | int main(void) { 5 | volatile int x = 5; 6 | f((int*)&x); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j066a.c: -------------------------------------------------------------------------------- 1 | typedef int fun(); 2 | const fun f; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j066b.c: -------------------------------------------------------------------------------- 1 | typedef int fun(); 2 | restrict fun f; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j066c.c: -------------------------------------------------------------------------------- 1 | typedef int fun(); 2 | volatile fun f; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j066d.c: -------------------------------------------------------------------------------- 1 | typedef int fun(); 2 | _Atomic fun f; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j067a.c: -------------------------------------------------------------------------------- 1 | int x; 2 | const int x; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j067b.c: -------------------------------------------------------------------------------- 1 | int *p; 2 | int * restrict p; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j067c.c: -------------------------------------------------------------------------------- 1 | int x; 2 | volatile int x; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j067d.c: -------------------------------------------------------------------------------- 1 | int x; 2 | _Atomic int x; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j068a.c: -------------------------------------------------------------------------------- 1 | int f(int* restrict a, int* restrict b) { 2 | *a = 1; 3 | *b = 1; 4 | return 0; 5 | } 6 | 7 | int main(void) { 8 | int a = 5; 9 | return f(&a, &a); 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j068b.c: -------------------------------------------------------------------------------- 1 | int g(const int* restrict a, int* b) { 2 | *b = 1; 3 | *a; 4 | return 0; 5 | } 6 | 7 | int main(void) { 8 | int a = 5; 9 | return g(&a, &a); 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j068c.c: -------------------------------------------------------------------------------- 1 | // this example is loosely based on an example in sentence 1509 in http://www.knosof.co.uk/cbook/cbook.html 2 | int g(int * p) { 3 | *p = 10; 4 | return 0; 5 | } 6 | 7 | int f(const int * restrict p) { 8 | g((int*)p); 9 | return *p; 10 | } 11 | 12 | int main(void){ 13 | int x = 5; 14 | return f(&x) == 5; 15 | } 16 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j069a.c: -------------------------------------------------------------------------------- 1 | int f(int * restrict p, int * restrict q) { 2 | p = q; 3 | return 0; 4 | } 5 | 6 | int main(void){ 7 | int p = 5; 8 | int q = 6; 9 | return f(&p, &q); 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j069b.c: -------------------------------------------------------------------------------- 1 | int x = 5; 2 | int y = 5; 3 | int * restrict p = &x; 4 | int * restrict q = &y; 5 | 6 | int main(void) { 7 | p = q; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j069c.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 5; 3 | int y = 6; 4 | int * restrict p = &x; 5 | int * restrict q = &x; 6 | 7 | p = q; 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j070a.c: -------------------------------------------------------------------------------- 1 | inline int f(void); 2 | 3 | int main(void) { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j071a.c: -------------------------------------------------------------------------------- 1 | _Noreturn void f(int x){ 2 | if (x) { 3 | return; 4 | } else while (1); 5 | } 6 | 7 | int main(void){ 8 | f(1); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j071b.c: -------------------------------------------------------------------------------- 1 | _Noreturn void f(void) { } 2 | 3 | int main(void) { 4 | f(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j071c.c: -------------------------------------------------------------------------------- 1 | _Noreturn int f(void) { 2 | return 0; 3 | } 4 | 5 | int main(void) { 6 | return f(); 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j072a.c: -------------------------------------------------------------------------------- 1 | _Alignas(1) int x; 2 | _Alignas(4) int x; 3 | 4 | int main(void){ 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j072b.c: -------------------------------------------------------------------------------- 1 | _Alignas(1) int x = 42; 2 | 3 | int main(void) { 4 | extern _Alignas(4) int x; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j073a-link1.c: -------------------------------------------------------------------------------- 1 | extern _Alignas(4) int x; 2 | 3 | int main(void) { 4 | return x; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j073a-link2.c: -------------------------------------------------------------------------------- 1 | _Alignas(1) int x; 2 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j074a.c: -------------------------------------------------------------------------------- 1 | int * x; 2 | int * const x; 3 | 4 | int main(void){ 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j074b.c: -------------------------------------------------------------------------------- 1 | int * restrict x; 2 | int * volatile x; 3 | 4 | int main(void){ 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j074c.c: -------------------------------------------------------------------------------- 1 | int * x; 2 | const int * x; 3 | 4 | int main(void){ 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j074d.c: -------------------------------------------------------------------------------- 1 | int * x; 2 | float * x; 3 | 4 | int main(void){ 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j075a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int x = 5; 3 | int a[-x]; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j075b.c: -------------------------------------------------------------------------------- 1 | int f(int x) { return x - 5; } 2 | 3 | int main(void) { 4 | int x = 5; 5 | int a[f(x)]; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j076a.c: -------------------------------------------------------------------------------- 1 | int a[5]; 2 | unsigned a[5]; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j076b.c: -------------------------------------------------------------------------------- 1 | float a[5]; 2 | double a[5]; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j076c.c: -------------------------------------------------------------------------------- 1 | int * a[5]; 2 | int * restrict a[5]; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j076d.c: -------------------------------------------------------------------------------- 1 | int a[5]; 2 | const int a[5]; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j076e.c: -------------------------------------------------------------------------------- 1 | int (*a[5])(int); 2 | int (*a[5])(int, int); 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j076f.c: -------------------------------------------------------------------------------- 1 | int a[5 * 2]; 2 | int a[5 + 2]; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j076g.c: -------------------------------------------------------------------------------- 1 | int f(int n) { return n; } 2 | 3 | int main(void) { 4 | 1 ? (int(*)[f(5)]) 0 : (int (*)[3]) 0; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j076h.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int n = 3; 3 | int m = 4; 4 | int a[n][6]; 5 | int (*p)[4]; 6 | 7 | p = a; 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j077a.c: -------------------------------------------------------------------------------- 1 | int f(int a[static 5]) { 2 | return 0; 3 | } 4 | 5 | int main(void) { 6 | int a[2]; 7 | return f(a); 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j077b.c: -------------------------------------------------------------------------------- 1 | #include 2 | int f(int a[static 5]) { 3 | return 0; 4 | } 5 | 6 | int main(void) { 7 | int *a = malloc(sizeof(int) * 2); 8 | return f(a); 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j077c.c: -------------------------------------------------------------------------------- 1 | void f(int a[static 10]) { } 2 | 3 | int main(void) { 4 | f((void*) 0); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j078a.c: -------------------------------------------------------------------------------- 1 | int f(register void){ 2 | return 0; 3 | } 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j078b.c: -------------------------------------------------------------------------------- 1 | int f(typedef void){ 2 | return 0; 3 | } 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j078c.c: -------------------------------------------------------------------------------- 1 | int f(extern void){ 2 | return 0; 3 | } 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j078d.c: -------------------------------------------------------------------------------- 1 | int f(_Thread_local void) { 2 | return 0; 3 | } 4 | 5 | int main(void) { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j078e.c: -------------------------------------------------------------------------------- 1 | int f(auto void){ 2 | return 0; 3 | } 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j078f.c: -------------------------------------------------------------------------------- 1 | int f(static void){ 2 | return 0; 3 | } 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j078g.c: -------------------------------------------------------------------------------- 1 | int f(const void){ 2 | return 0; 3 | } 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j078h.c: -------------------------------------------------------------------------------- 1 | int f(restrict void){ 2 | return 0; 3 | } 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j078i.c: -------------------------------------------------------------------------------- 1 | int f(volatile void){ 2 | return 0; 3 | } 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j078j.c: -------------------------------------------------------------------------------- 1 | int f(_Atomic void) { 2 | return 0; 3 | } 4 | 5 | int main(void) { 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j079a.c: -------------------------------------------------------------------------------- 1 | int f(void); 2 | float f(void) { return 0.0; } 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j079b.c: -------------------------------------------------------------------------------- 1 | int f(void); 2 | void f(void) { } 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j079c.c: -------------------------------------------------------------------------------- 1 | void f(int); 2 | void f(float x) { } 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j079d.c: -------------------------------------------------------------------------------- 1 | void f(int); 2 | void f(void) { } 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j079e.c: -------------------------------------------------------------------------------- 1 | void f(int); 2 | void f(int x, int y) { } 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j079f.c: -------------------------------------------------------------------------------- 1 | void f(char); 2 | void f(a, b) int a; int b; { } 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j079g.c: -------------------------------------------------------------------------------- 1 | // 6.7.6.3:15: "If one type has a parameter type list and the other type is 2 | // specified by a function declarator that is not part of a function definition 3 | // and that contains an empty function identifier list, the parameter list 4 | // shall not have an ellipses terminator and the type of each parameter shall 5 | // be compatible with the type that results from the application of the default 6 | // argument promotions." 7 | 8 | void f(); 9 | void f(int x, ...) { } 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j079h.c: -------------------------------------------------------------------------------- 1 | // 6.7.6.3:15: "If one type has a parameter type list and the other type is 2 | // specified by a function declarator that is not part of a function definition 3 | // and that contains an empty function identifier list, the parameter list 4 | // shall not have an ellipses terminator and the type of each parameter shall 5 | // be compatible with the type that results from the application of the default 6 | // argument promotions." 7 | 8 | void f(); 9 | void f(float x) { } 10 | 11 | int main(void) { 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j079i.c: -------------------------------------------------------------------------------- 1 | void f(int *x); 2 | void f(const int *x) { } 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j080a.c: -------------------------------------------------------------------------------- 1 | struct { 2 | unsigned:sizeof(unsigned); 3 | unsigned x; 4 | } s; 5 | 6 | int main(void) { 7 | return *((unsigned*)&s); 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j081a.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int x = {0, 1}; 3 | return x; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j081b.c: -------------------------------------------------------------------------------- 1 | int main(void){ 2 | int x = {{0, 1}}; 3 | return x; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j082a.c: -------------------------------------------------------------------------------- 1 | struct s { 2 | int x; 3 | int y; 4 | }; 5 | 6 | int main(void){ 7 | struct s s0 = 1; 8 | return s0.x; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j082b.c: -------------------------------------------------------------------------------- 1 | struct s { 2 | int x; 3 | int y; 4 | }; 5 | 6 | struct t { 7 | char x; 8 | int y; 9 | }; 10 | 11 | int main(void){ 12 | struct t t0 = {0, 1}; 13 | struct s s0 = t0; 14 | return s0.x; 15 | } 16 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j083a.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | int a[] = 1; 3 | return a[0]; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j083b.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | struct {int x; } s = 0; 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j083c.c: -------------------------------------------------------------------------------- 1 | int main(void) { 2 | union {int x; int y; } s = 0; 3 | return 0; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j084a.c: -------------------------------------------------------------------------------- 1 | extern int a; 2 | 3 | int main(void) { 4 | return a; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j084b.c: -------------------------------------------------------------------------------- 1 | extern int a = 0; 2 | int a = 0; 3 | 4 | int main(void) { 5 | return a; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j084c.c: -------------------------------------------------------------------------------- 1 | extern int a = 0; 2 | int a = 0; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j084d.c: -------------------------------------------------------------------------------- 1 | int a = 1; 2 | int a = 1; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j084e.c: -------------------------------------------------------------------------------- 1 | void f(void) { } 2 | void f(void) { } 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j084f-link1.c: -------------------------------------------------------------------------------- 1 | int x = 1; 2 | int main(void) { 3 | return x; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j084f-link2.c: -------------------------------------------------------------------------------- 1 | int x = 1; 2 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j085a.c: -------------------------------------------------------------------------------- 1 | int f(a){ 2 | return a; 3 | } 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j085b.c: -------------------------------------------------------------------------------- 1 | int f(a, b) int a; { 2 | return a; 3 | } 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j085c.c: -------------------------------------------------------------------------------- 1 | int f(a, b, c) int a; int c; { 2 | return a; 3 | } 4 | 5 | int main(void){ 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j086a.c: -------------------------------------------------------------------------------- 1 | struct s; 2 | 3 | int f(struct s s) { 4 | return 0; 5 | } 6 | 7 | struct s { int x; } s; 8 | 9 | int main(void) { 10 | return f(s); 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j086b.c: -------------------------------------------------------------------------------- 1 | union u; 2 | 3 | int f(union u u) { 4 | return 0; 5 | } 6 | 7 | union u { int x; } u; 8 | 9 | int main(void) { 10 | return f(u); 11 | } 12 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j087a.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int f(int x, int y) { 4 | va_list ap; 5 | va_start(ap, y); 6 | int z = va_arg(ap, int); 7 | va_end(ap); 8 | return z; 9 | } 10 | int main(void) { 11 | return f(5, 6); 12 | } 13 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j088a.c: -------------------------------------------------------------------------------- 1 | int f(int x){ } 2 | 3 | int main(void) { 4 | f(f(1)); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j088b.c: -------------------------------------------------------------------------------- 1 | int f(void) { } 2 | 3 | int main(void) { 4 | f() + 0; 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j089a.c: -------------------------------------------------------------------------------- 1 | static int a[]; 2 | 3 | int main(void) { 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j089b.c: -------------------------------------------------------------------------------- 1 | struct s; 2 | 3 | static struct s a; 4 | 5 | struct s { int x; }; 6 | 7 | int main(void) { 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /tests/undefined-ellison/unsorted/j089c.c: -------------------------------------------------------------------------------- 1 | static int a[2]; 2 | static int a[]; 3 | 4 | int main(void) { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined/abort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | abort(); 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined/alias.c: -------------------------------------------------------------------------------- 1 | int g(int *p, short *q) { int x = *q; *p = 10; return x; } 2 | 3 | int main() { 4 | union INT_SHO { int x; short y; } u; 5 | u.y = 314; 6 | g(&u.x, &u.y); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined/big_constant.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | 1000000000000000000000UL; 3 | } 4 | -------------------------------------------------------------------------------- /tests/undefined/chucky.c: -------------------------------------------------------------------------------- 1 | int x, y, *p = &y; 2 | int f() { if (x) { p = &x; } return 0; } 3 | int main() { 4 | return (x = 1) + (*p = 2) + f(); 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined/compare_after_free.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | int *p = malloc(sizeof(int)); 6 | free(p); 7 | int *q = malloc(sizeof(int)); 8 | printf("%d\n", p == q); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined/end_of_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x, y; 5 | if (&x + 1 == &y) printf("x and y are allocated adjacently\n"); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined/goto_out_of_life.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int *p = NULL; 5 | l: 6 | if (p) { return (*p); } 7 | else { int j = 10; p = &j; goto l; } 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/undefined/incomplete_function.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | 3 | int main() { 4 | return f(); 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined/indet_byte_read.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | struct { short x, *r; } s1; 5 | s1.x = 10; 6 | ((unsigned char*)&s1)[3] = 1; 7 | printf("no undef yet\n"); 8 | s1.x = 11; 9 | printf("still no undef yet\n"); 10 | printf("will never print %d\n", ((unsigned char*)&s1)[3]); 11 | return 10; 12 | } 13 | -------------------------------------------------------------------------------- /tests/undefined/int_regehr1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* From http://www.cs.utah.edu/~regehr/papers/overflow12.pdf */ 4 | int main() { 5 | long x = LONG_MAX + 1; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined/int_regehr2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* From http://www.cs.utah.edu/~regehr/papers/overflow12.pdf */ 4 | int main() { 5 | int x = INT_MAX+1; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined/int_regehr3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* From http://www.cs.utah.edu/~regehr/papers/overflow12.pdf */ 4 | int main() { 5 | char c = CHAR_MAX; c++; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined/int_regehr4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* From http://www.cs.utah.edu/~regehr/papers/overflow12.pdf */ 4 | int main() { 5 | int x = -INT_MIN; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined/int_regehr5.c: -------------------------------------------------------------------------------- 1 | /* From http://www.cs.utah.edu/~regehr/papers/overflow12.pdf */ 2 | int main() { 3 | int x = 1 << -1; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined/int_regehr6.c: -------------------------------------------------------------------------------- 1 | /* From http://www.cs.utah.edu/~regehr/papers/overflow12.pdf */ 2 | int main() { 3 | int x = 1 << 32; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined/int_regehr7.c: -------------------------------------------------------------------------------- 1 | /* From http://www.cs.utah.edu/~regehr/papers/overflow12.pdf */ 2 | int main() { 3 | int x = 1/0; 4 | return 0; 5 | } 6 | -------------------------------------------------------------------------------- /tests/undefined/int_regehr8.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* From http://www.cs.utah.edu/~regehr/papers/overflow12.pdf */ 4 | int main() { 5 | int x = INT_MIN%-1; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined/local_unitialized.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | struct { int x, *p ; } s; 3 | return s.x; 4 | } 5 | -------------------------------------------------------------------------------- /tests/undefined/no_return.c: -------------------------------------------------------------------------------- 1 | int f() { 2 | 3 | } 4 | 5 | int main() { 6 | f(); 7 | } 8 | -------------------------------------------------------------------------------- /tests/undefined/overflow.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int f(int x) { return x < x + 1; } 5 | 6 | int main() { 7 | printf("INT_MAX < INT_MAX + 1 = %d\n", f(INT_MAX)); 8 | } 9 | -------------------------------------------------------------------------------- /tests/undefined/overlapping_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct A { int a [32]; }; 4 | 5 | union U { 6 | struct A a; 7 | struct { char b1; struct A b2; } b; 8 | } u; 9 | 10 | void init(struct A *p) { 11 | for (int i = 0; i < 32; i++) { p->a[i] = i; } 12 | } 13 | 14 | int test(struct A *p) { 15 | int b = 0; 16 | for (int i = 0; i < 32; i++) { 17 | printf("%d=%d\n", i, p->a[i]); 18 | if (p->a[i] != i) b = 1; 19 | } 20 | return b; 21 | } 22 | 23 | struct A g(struct A a) { return a; } 24 | 25 | int main() { 26 | init(&u.a); 27 | u.b.b2 = u.a; 28 | return test(&u.b.b2); 29 | } 30 | -------------------------------------------------------------------------------- /tests/undefined/pointer_comp.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x, y; 5 | printf("%d\n", &x + 1 == &y); 6 | } 7 | -------------------------------------------------------------------------------- /tests/undefined/sequence_point_violation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x; 5 | int y = (x = 3) + (x = 4); 6 | printf("%d %d\n", x, y); 7 | return 0; 8 | } 9 | 10 | -------------------------------------------------------------------------------- /tests/undefined/type_punning.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | union INT_SHO { int x; short y; }; 4 | 5 | int main() { 6 | union INT_SHO u; u.x = 311111111; 7 | short *p = &u.y; 8 | printf("%d", *p); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/undefined/wrong_args_prototypes.c: -------------------------------------------------------------------------------- 1 | int f(int x, int y); 2 | int f(int, int*); 3 | 4 | -------------------------------------------------------------------------------- /tests/undefined/wrong_return_prototypes.c: -------------------------------------------------------------------------------- 1 | int f(); 2 | int *f(); 3 | 4 | --------------------------------------------------------------------------------