├── .git-blame-ignore-revs
├── .github
└── workflows
│ ├── docs.yml
│ └── tests.yml
├── CHANGES.md
├── LICENSE
├── META.goblint-cil.template
├── README.md
├── bin
├── cilly
├── dune
└── realGccConfigure.ml
├── doc
├── cil.tex
├── cilcode.pl
├── comment.sty
├── dune
├── fullpage.sty
├── hevea.sty
├── html
│ └── cil
│ │ ├── dune
│ │ ├── header.html
│ │ └── index.html
├── main.html
├── program.sty
└── proof.sty
├── dune
├── dune-project
├── goblint-cil.opam
├── goblint-cil.opam.template
├── lib
└── perl5
│ ├── .gdbinit
│ ├── App
│ ├── Cilly.pm.in
│ ├── Cilly
│ │ ├── CilCompiler.pm
│ │ ├── KeptFile.pm
│ │ ├── OutputFile.pm
│ │ ├── TempFile.pm
│ │ └── dune
│ └── dune
│ ├── MANIFEST
│ ├── Makefile.PL
│ └── patcher
├── src
├── cfg.ml
├── cfg.mli
├── check.ml
├── check.mli
├── cil.ml
├── cil.mli
├── cilint.ml
├── cilint.mli
├── cillower.ml
├── cillower.mli
├── ciloptions.ml
├── ciloptions.mli
├── ciltools.ml
├── cilutil.ml
├── cilversion.ml
├── dataflow.ml
├── dataflow.mli
├── dominators.ml
├── dominators.mli
├── dune
├── escape.ml
├── escape.mli
├── expcompare.ml
├── ext
│ ├── dataslicing
│ │ ├── META
│ │ ├── dataslicing.ml
│ │ ├── dataslicing.mli
│ │ ├── default
│ │ └── dune
│ ├── dune
│ ├── liveness
│ │ ├── META
│ │ ├── default
│ │ ├── dune
│ │ ├── liveness.ml
│ │ └── usedef.ml
│ ├── makecfg
│ │ ├── META
│ │ ├── default
│ │ ├── dune
│ │ └── makeCFG.ml
│ ├── pta
│ │ ├── META
│ │ ├── default
│ │ ├── dune
│ │ ├── golf.ml
│ │ ├── golf.mli
│ │ ├── olf.ml
│ │ ├── olf.mli
│ │ ├── ptranal.ml
│ │ ├── ptranal.mli
│ │ ├── setp.ml
│ │ ├── setp.mli
│ │ ├── steensgaard.ml
│ │ ├── steensgaard.mli
│ │ ├── uref.ml
│ │ └── uref.mli
│ ├── syntacticsearch
│ │ ├── META
│ │ ├── codeQuery.ml
│ │ ├── dune
│ │ ├── funcDatatype.ml
│ │ ├── funcFunction.ml
│ │ ├── funcVar.ml
│ │ ├── queryMapping.ml
│ │ └── resultPrinter.ml
│ └── zrapp
│ │ ├── META
│ │ ├── availexps.ml
│ │ ├── availexpslv.ml
│ │ ├── deadcodeelim.ml
│ │ ├── dune
│ │ ├── reachingdefs.ml
│ │ ├── rmciltmps.ml
│ │ ├── zrapp.ml
│ │ └── zrapp.mli
├── feature.ml
├── feature.mli
├── formatcil.ml
├── formatcil.mli
├── formatlex.mll
├── formatparse.mly
├── frontc
│ ├── cabs.ml
│ ├── cabs2cil.ml
│ ├── cabs2cil.mli
│ ├── cabshelper.ml
│ ├── cabsvisit.ml
│ ├── cabsvisit.mli
│ ├── clexer.mli
│ ├── clexer.mll
│ ├── cparser.mly
│ ├── cprint.ml
│ ├── dune
│ ├── frontc.ml
│ ├── frontc.mli
│ ├── lexerhack.ml
│ ├── patch.ml
│ ├── patch.mli
│ ├── whitetrack.ml
│ └── whitetrack.mli
├── goblintCil.ml
├── machdep-ml.c
├── machdep.cppo.ml
├── machdepArchConfigure.ml
├── machdepConfigure.ml
├── machdepenv.ml
├── main.ml
├── mainFeature.ml
├── mainFeature.mli
├── mergecil.ml
├── mergecil.mli
├── modelConfigure.ml
├── ocamlutil
│ ├── alpha.ml
│ ├── alpha.mli
│ ├── bitmap.ml
│ ├── bitmap.mli
│ ├── clist.ml
│ ├── clist.mli
│ ├── errormsg.ml
│ ├── errormsg.mli
│ ├── growArray.ml
│ ├── growArray.mli
│ ├── inthash.ml
│ ├── inthash.mli
│ ├── longarray.ml
│ ├── longarray.mli
│ ├── pretty.ml
│ ├── pretty.mli
│ ├── stats.ml
│ ├── stats.mli
│ ├── trace.ml
│ ├── trace.mli
│ ├── util.ml
│ └── util.mli
├── rmUnused.ml
└── rmUnused.mli
└── test
├── Makefile
├── Makefile.gcc
├── RegTest.pm
├── dune
├── runall.pl
├── small1
├── .gdbinit
├── GRT.c
├── Makefile
├── addr-array.c
├── addr-string.c
├── addrof3.c
├── align1.c
├── align2.c
├── align3.c
├── alignas.c
├── alignas_proper.c
├── apachebits.c
├── apachebuf.c
├── apachefptr.c
├── argcast.c
├── array-args.c
├── array-size-trick.c
├── array1.c
├── array2.c
├── array_formal.c
├── array_multi_varsize.c
├── array_varsize.c
├── arrayinitsize.c
├── arrsize.c
├── asm1.c
├── asm2.c
├── asm3.c
├── asm4.c
├── asm5.c
├── asm_emptyclobberallowed.c
├── assign.c
├── attr-assign.c
├── attr-enumerator.c
├── attr-in-decllist.c
├── attr10.c
├── attr11.c
├── attr12.c
├── attr13.c
├── attr2.c
├── attr3.c
├── attr4.c
├── attr5.c
├── attr6.c
├── attr7.c
├── attr8.c
├── attr9.c
├── bf.c
├── bind-formatstring.c
├── bind-used-not-defined.c
├── bitfield.c
├── bitfield0.c
├── bitfield2.c
├── bitfield3.c
├── blockattr.c
├── blockattr2.c
├── bool.c
├── booleanOp.c
├── break1.c
├── builtin.c
├── builtin2.c
├── builtin3.c
├── builtin4.c
├── builtin5.c
├── builtin6.c
├── builtin_choose_expr.c
├── builtin_object_size.c
├── c11-align-of.c
├── c11-atomic-store.c
├── c11-atomic.c
├── c11-caserange.c
├── c11-extendedFloat.c
├── c11-generic.c
├── c11-noreturn.c
├── c11-static-assert.c
├── c99-bool.c
├── c99-complex.c
├── c99-fixed-width-int.c
├── c99-float-pragma.c
├── c99-predefined.c
├── c99-struct.c
├── c99-tgmath.c
├── c99-tgmath2.c
├── c99-universal-character-names.c
├── call2.c
├── case_then_default_in_switch.c
├── caserange.c
├── cast1.c
├── cast2.c
├── cast3.c
├── cast4.c
├── cast8.c
├── castcall.c
├── castincr.c
├── castunion.c
├── clang-c11-generic-1-1.c
├── clang-c11-generic-1-2.c
├── clang-c11-generic-2.c
├── combine-c99-mergeinline1_1.c
├── combine-c99-mergeinline1_2.c
├── combine-c99-mergeinline2_1.c
├── combine-c99-mergeinline2_2.c
├── combine-c99-mergeinline3_1.c
├── combine-c99-mergeinline3_2.c
├── combine-c99-mergeinline4_1.c
├── combine-c99-mergeinline4_2.c
├── combine-c99-mergeinline5_1.c
├── combine-c99-mergeinline5_2.c
├── combine-c99-mergeinline6_1.c
├── combine-c99-mergeinline6_2.c
├── combine-c99-mergeinline7.h
├── combine-c99-mergeinline7_1.c
├── combine-c99-mergeinline7_2.c
├── combine-c99inline1_1.c
├── combine-c99inline1_2.c
├── combine-c99inline2_1.c
├── combine-c99inline2_2.c
├── combine-c99inline3_1.c
├── combine-c99inline3_2.c
├── combine-c99inline4_1.c
├── combine-c99inline4_2.c
├── combine-c99inline5_1.c
├── combine-c99inline5_2.c
├── combine-c99inline6_1.c
├── combine-c99inline6_2.c
├── combine-c99inline7_1.c
├── combine-c99inline7_2.c
├── combine-c99inline7_3.c
├── combine-c99inline8_1.c
├── combine-c99inline8_2.c
├── combine-c99inline8_3.c
├── combine-c99inline9.h
├── combine-c99inline9_1.c
├── combine-c99inline9_2.c
├── combine-c99inline_1.c
├── combine-c99inline_2.c
├── combine10_1.c
├── combine10_2.c
├── combine10_3.c
├── combine11_1.c
├── combine11_2.c
├── combine12_1.c
├── combine12_2.c
├── combine13_1.c
├── combine13_2.c
├── combine14_1.c
├── combine14_2.c
├── combine15_1.c
├── combine15_2.c
├── combine16_1.c
├── combine16_2.c
├── combine17_1.c
├── combine17_2.c
├── combine18_1.c
├── combine18_2.c
├── combine1_1.c
├── combine1_2.c
├── combine1_3.c
├── combine20_1.c
├── combine20_2.c
├── combine21_1.c
├── combine21_2.c
├── combine22_1.c
├── combine22_2.c
├── combine2_1.c
├── combine2_2.c
├── combine2_3.c
├── combine3_1.c
├── combine3_2.c
├── combine3_3.c
├── combine4_1.c
├── combine4_2.c
├── combine5.h
├── combine5_1.c
├── combine5_2.c
├── combine5_3.c
├── combine6_1.c
├── combine6_2.c
├── combine6_3.c
├── combine7_1.c
├── combine7_2.c
├── combine7_3.c
├── combine8_1.c
├── combine8_2.c
├── combine9_1.c
├── combine9_2.c
├── combine_allocate_1.c
├── combine_allocate_2.c
├── combine_copyptrs_1.c
├── combine_copyptrs_2.c
├── combine_init_1.c
├── combine_init_2.c
├── combine_node_alloc_1.c
├── combine_node_alloc_2.c
├── combine_samefn_1.c
├── combine_samefn_2.c
├── combine_sbumpB_1.c
├── combine_sbumpB_2.c
├── combine_sbumpB_3.c
├── combine_sbump_1.c
├── combine_sbump_2.c
├── combine_syserr_1.c
├── combine_syserr_2.c
├── combine_theFunc_1.c
├── combine_theFunc_2.c
├── combine_theFunc_3.c
├── combinealias_1.c
├── combinealias_2.c
├── combineenum1_1.c
├── combineenum1_2.c
├── combineenum2_1.c
├── combineenum2_2.c
├── combineenum3_1.c
├── combineenum3_2.c
├── combinegnuinline_1.c
├── combinegnuinline_2.c
├── combinegnuinline_header.h
├── combineinline1_1.c
├── combineinline1_2.c
├── combineinline2_1.c
├── combineinline2_2.c
├── combineinline3_1.c
├── combineinline3_2.c
├── combineinline4_1.c
├── combineinline4_2.c
├── combineinline6_1.c
├── combineinline6_2.c
├── combinelibrik_1.c
├── combinelibrik_2.c
├── combinemerge1_1.c
├── combinemerge1_2.c
├── combinemerge1_3.c
├── combinestruct1_1.c
├── combinestruct1_2.c
├── combinetaggedfn_1.c
├── combinetaggedfn_2.c
├── comma1.c
├── comparisons.c
├── compound1.c
├── compound2.c
├── cond1.c
├── cond2.c
├── const-array-init.c
├── const-compound-cast.c
├── const-struct-init.c
├── const1.c
├── const10.c
├── const11.c
├── const12.c
├── const13.c
├── const14.c
├── const15.c
├── const16.c
├── const2.c
├── const3.c
├── const4.c
├── const5.c
├── const6.c
├── const7.c
├── const8.c
├── const9.c
├── constfold.c
├── constfold2.c
├── constprop.c
├── constrexpr.c
├── cpp-2.c
├── cpp-3.c
├── decl2.c
├── decl_mix_stmt.c
├── deref.c
├── do_while_cont.c
├── duplicate.c
├── empty.i
├── enum-scope.c
├── enum.c
├── enum2.c
├── enum3.c
├── enum3a.c
├── enum3b.c
├── enum3c.c
├── enum3d.c
├── enum3e.c
├── enum3f.c
├── enum3g.c
├── enum3h.c
├── enum3i.c
├── enum3j.c
├── enum3k.c
├── enum3l.c
├── escapes.c
├── extern1.c
├── extern_init.c
├── extinline2.c
├── extinline3.c
├── fallthrough-label.c
├── flexible-array-member-bad.c
├── flexible-array-member.c
├── float.c
├── float2.c
├── float3.c
├── for1.c
├── formalscope.c
├── func.c
├── func10.c
├── func2.c
├── func3.c
├── func4.c
├── funcarg.c
├── funptr1.c
├── gcc-c11-generic-1.c
├── gcc-c11-generic-2-1.c
├── gcc-c11-generic-2-2.c
├── gcc-c11-generic-2-3.c
├── gcc-c11-generic-2-4.c
├── gcc-c11-generic-2-5.c
├── gcc-c11-generic-2-6.c
├── gcc-c11-generic-2-7.c
├── gcc-c11-generic-3-1.c
├── gcc-c11-generic-3-2.c
├── gcc-c11-generic-3-3.c
├── gcc-c11-generic-3-4.c
├── globals.c
├── globals2.c
├── hello.c
├── huff1.c
├── init.c
├── init1.c
├── init10.c
├── init11.c
├── init12.c
├── init13.c
├── init14.c
├── init15.c
├── init16.c
├── init17.c
├── init18.c
├── init19.c
├── init2.c
├── init20.c
├── init21.c
├── init22.c
├── init3.c
├── init4.c
├── init5.c
├── init6.c
├── init7.c
├── init8.c
├── init9.c
├── initial.c
├── inline1.c
├── inline2.c
├── inline3.c
├── jmp_buf.c
├── knr1.c
├── label1.c
├── label2.c
├── label2b.c
├── label3.c
├── label3b.c
├── label4.c
├── label4b.c
├── label5.c
├── label6.c
├── label7.c
├── label8.c
├── label9.c
├── land_expr.c
├── large_unsigned_long.c
├── li.c
├── lineno.i
├── linux_atomic.c
├── linux_signal.c
├── linuxcombine1_1.c
├── list.c
├── local.c
├── local.h
├── localinit.c
├── logical.c
├── logical1.c
├── logical2.c
├── longBlock.ml
├── lstring.c
├── lval1.c
├── macro_hidden.c
├── math1.c
├── matrix.c
├── memcpy1.c
├── min.c
├── msvc1.c
├── msvc5.c
├── nan-global.c
├── noproto.c
├── noproto1.c
├── noproto2.c
├── noreturn.c
├── offsetof.c
├── offsetof1.c
├── offsetof2.c
├── offsetof3.c
├── oom.c
├── order.c
├── outofmem.c
├── p04.c
├── packed.c
├── packed2.c
├── paper1.c
├── paper2.c
├── percent400.c
├── percentm.c
├── perror.c
├── perror1.c
├── pointers2.c
├── post-assign.c
├── power1.c
├── printf.c
├── printf2.c
├── printf_const.c
├── proto1.c
├── proto2.c
├── pure.c
├── question-fold-float.c
├── question.c
├── question2.c
├── question3.c
├── restrict.c
├── restrict1.c
├── return1.c
├── returnvoid.c
├── returnvoid1.c
├── retval.c
├── rmUnused-attr.c
├── rmUnused1.c
├── rmUnused2.c
├── scope1.c
├── scope10.c
├── scope11.c
├── scope12.c
├── scope2.c
├── scope3.c
├── scope4.c
├── scope5.c
├── scope6.c
├── scope7.c
├── scope8.c
├── scope9.c
├── semicolon.c
├── shell-escape.c
├── signs.c
├── simon6.c
├── sizeof1.c
├── sizeof2.c
├── sizeof3.c
├── ssa-test.c
├── ssa-test2.c
├── ssa2.c
├── ssa3.c
├── ssa4.c
├── ssa5.c
├── stack.c
├── static.c
├── static1.c
├── static2.c
├── strcpy.c
├── string1.c
├── string2.c
├── stringsize.c
├── strloop.c
├── strloop3.c
├── struct1.c
├── struct2.c
├── struct_init.c
├── structassign.c
├── switch_default_parse_bug.c
├── sync-1.c
├── sync-2.c
├── sync-3.c
├── tags.c
├── task.c
├── tempname.c
├── testharness.h
├── typeof1.c
├── typespec1.c
├── unimplemented.c
├── union1.c
├── union2.c
├── union3.c
├── union5.c
├── union6.c
├── unsafe1.c
├── va-arg-1.c
├── va-arg-2.c
├── va-arg-7.c
├── va_arg_pack.c
├── var.c
├── var_named_hidden.c
├── vararg1.c
├── vararg10.c
├── vararg2.c
├── vararg3.c
├── vararg4.c
├── vararg5.c
├── vararg5.h
├── vararg6.c
├── vararg7.c
├── varargauto1.c
├── varied.c
├── version.c
├── void.c
├── voidarg.c
├── voidstar.c
├── voidtypedef.c
├── vsp.c
├── warnings-cast.c
├── warnings-noreturn.c
├── warnings-unused-label.c
├── wchar-bad.c
├── wchar1.c
├── wchar1_freebsd.c
├── wchar2.c
├── wchar3.c
├── wchar4.c
├── wchar5.c
├── wchar6.c
├── wchar7.c
├── wrongnumargs.c
└── zerotags.c
├── small2
├── Makefile
├── align.c
├── alpha.c
├── arrayinit.c
├── asmfndecl.c
├── attrib.c
├── badasm.c
├── baddef1.c
├── baddef2.c
├── bisonerror.c
├── bogus_redef.c
├── brlock.c
├── bzero.c
├── checkinit.c
├── checkret.c
├── checkstore.c
├── checkstore2.c
├── checkstore3.c
├── checksymbol.c
├── cilreturn.c
├── cmpzero.c
├── cof.c
├── comb1.c
├── comb2.c
├── comb3.c
├── comb4.c
├── conset.c
├── constdecl.c
├── constfold.c
├── constfold2.c
├── ctype.c
├── debug_table.c
├── ehstack.c
├── enumattr.c
├── enumerator_sizeof.c
├── enuminit.c
├── enuminit2.c
├── errorinfn.c
├── extinline.c
├── fig1.c
├── fmtstr.c
├── fseq1fail.c
├── funcname.c
├── funcptr.c
├── funcptr2.c
├── funptr1.c
├── gimpdouble.c
├── globalprob.c
├── globinit.c
├── globtable.c
├── handler1.handlers
├── hashtest.c
├── hufftable.c
├── hufftest.c
├── index1.c
├── initedextern.c
├── invalredef.c
├── invalredef2.c
├── jpeg_compress_struct.c
├── kernel1.c
├── kernel2.c
├── lexnum.c
├── litstruct.c
├── main.c
├── malloc1.c
├── memberofptr.c
├── memset_sizeof.c
├── merge-ar.c
├── merge-twice-1.c
├── merge-twice-2.c
├── merge-twice-3.c
├── mergeinit1.c
├── mergeinit1.h
├── mergeinit2.h
├── mergeinit2_1_reftable.c
├── mergeinit2_2_definition.c
├── mergeinit3.c
├── mergeinit3.h
├── mergeinit4.c
├── mergeinline1.c
├── mergeinline2.c
├── mergestruct1.c
├── mergestruct2.c
├── metabug3.c
├── mode_sizes.c
├── multiplestatics.c
├── neg64.c
├── nested.c
├── nonwilderror.c
├── oldstyle.c
├── open.c
├── override.c
├── partialbracket.c
├── pset.c
├── ptrinint.c
├── putc.c
├── rbtest.c
├── regbeforeassign.c
├── regparm0.c
├── regthenprintf.c
├── runall_misc.c
├── rusage.c
├── s59.c
├── scary.c
├── segfault.c
├── seq_align_malloc.c
├── seq_align_malloc2.c
├── seqalign.c
├── sizeofchar.c
├── sockaddr.c
├── stackptr.c
├── stackptrptr.c
├── struct_cs.c
├── structattr.c
├── structattr2.c
├── structattr3.c
├── switch.c
├── tagfile.txt
├── tagfile1.c
├── tagfile2.c
├── testbtree.c
├── thing.c
├── transpunion.c
├── trivial-tb.c
├── try1.c
├── twoprintfs.c
├── typeof.c
├── undef_func.c
├── uninit_tmp.c
├── union2.c
├── union4.c
├── union5.c
├── union6.c
├── union7.c
├── union8.c
├── unionassign.c
├── unionext.c
├── unscomp.c
├── visit_col.c
├── voidstarint.c
├── volatilestruct.c
├── wes-hashtest.c
├── wes-rbtest.c
├── writev.c
└── xcheckers.c
├── teetwo
├── test-bad
├── testcil
├── testcil.bat
├── testcil.h
└── testcil.pl
/.git-blame-ignore-revs:
--------------------------------------------------------------------------------
1 | # git config blame.ignoreRevsFile .git-blame-ignore-revs
2 | # requires git 2.23
3 | # (https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame)
4 |
5 | # Fix Warning 6
6 | 11caf7887851119fa9b553d41c903bce49c302d5
7 |
8 | # Normalize whitespace in cabs2cil.ml
9 | f44b466468869562182d090e3b6453b4a0cd17cf
10 |
--------------------------------------------------------------------------------
/META.goblint-cil.template:
--------------------------------------------------------------------------------
1 | # DUNE_GEN
2 |
3 | package "default-features" (
4 | requires="goblint-cil.dataslicing goblint-cil.liveness goblint-cil.pta goblint-cil.makecfg goblint-cil.syntacticsearch"
5 | version = "2.0.6"
6 | )
7 |
8 | package "all-features" (
9 | requires="goblint-cil.dataslicing goblint-cil.liveness goblint-cil.pta goblint-cil.makecfg goblint-cil.zrapp goblint-cil.syntacticsearch"
10 | version = "2.0.6"
11 | )
12 |
--------------------------------------------------------------------------------
/bin/dune:
--------------------------------------------------------------------------------
1 | (install
2 | (section bin)
3 | (files
4 | cilly
5 | cilly.native))
6 |
7 | (rule
8 | (alias cilly)
9 | (action (copy ../src/main.exe cilly.native)))
10 |
11 | (alias
12 | (name cilly)
13 | (deps cilly))
14 |
15 |
16 | (executable
17 | (name realGccConfigure)
18 | (libraries dune-configurator str))
19 |
20 | (rule
21 | (target real-gcc)
22 | (action (run ./realGccConfigure.exe)))
23 |
--------------------------------------------------------------------------------
/doc/dune:
--------------------------------------------------------------------------------
1 | (rule
2 | (targets cilpp.tex ./__html__cil__examples)
3 | (deps (alias_rec ../cilly) (package goblint-cil))
4 | (action (progn
5 | (system "mkdir -p ./html/cil/examples")
6 | (with-stdout-to cilpp.tex (run %{bin:perl} %{dep:cilcode.pl} %{dep:cil.tex}))
7 | (system "rm -r ./__html__cil__examples || true")
8 | (system "mv ./html/cil/examples ./__html__cil__examples"))))
9 |
--------------------------------------------------------------------------------
/doc/html/cil/dune:
--------------------------------------------------------------------------------
1 | (rule
2 | (deps (alias_rec ../../../doc) (sandbox none))
3 | (targets ./api)
4 | (action (system "cp -rL ../../../_doc/_html ./api")))
5 |
6 | (rule
7 | (deps ../../__html__cil__examples)
8 | (targets ./examples)
9 | (action (system "cp -rL ../../__html__cil__examples ./examples")))
10 |
11 | (rule
12 | (alias heveadoc)
13 | (deps ../../cilpp.tex ./examples ./api index.html header.html)
14 | (action (progn
15 | (run %{bin:hevea} -exec xxdate.exe ../../cilpp)
16 | (run %{bin:hevea} -exec xxdate.exe ../../cilpp)
17 | (system "mv cilpp.html cil.html")
18 | (run %{bin:hacha} -o ciltoc.html cil.html))))
19 |
--------------------------------------------------------------------------------
/doc/html/cil/header.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | Goblint-CIL Documentation (v. %%VERSION_NUM%%)
9 |
10 |
11 |
12 |
13 |
14 | Goblint-CIL - Infrastructure for C Program Analysis and Transformation (v. %%VERSION_NUM%%)
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/dune:
--------------------------------------------------------------------------------
1 | (alias
2 | (name default)
3 | (deps (alias_rec bin/all) (alias_rec lib/all) (alias_rec src/all) (alias_rec test/all))) ; everything but doc
4 |
--------------------------------------------------------------------------------
/goblint-cil.opam.template:
--------------------------------------------------------------------------------
1 | depexts: [
2 | ["perl-ExtUtils-MakeMaker"] {os-distribution = "centos" | os-distribution = "fedora" | os-distribution = "ol"}
3 | ["perl-FindBin"] {os-distribution = "fedora"}
4 | ["build-base"] {os-distribution = "alpine"}
5 | ]
6 | available: arch = "x86_64" | arch = "arm64"
7 | x-ci-accept-failures: [
8 | "freebsd" # installed cilly binary is not found for some reason (https://github.com/ocaml/opam-repository/pull/24812#issuecomment-1819231335)
9 | ]
10 |
--------------------------------------------------------------------------------
/lib/perl5/.gdbinit:
--------------------------------------------------------------------------------
1 | # .gdbinit
2 |
3 | file splay
4 | break main
5 | break initErrorHandlers
6 | run
7 |
--------------------------------------------------------------------------------
/lib/perl5/App/Cilly/dune:
--------------------------------------------------------------------------------
1 | (rule
2 | (target CilConfig.pm)
3 | (action (write-file %{target} "package App::Cilly::CilConfig;\n\n$::cc = \"%{read-lines:../../../../bin/real-gcc}\";\n$::default_mode = \"GNUCC\";\n")))
4 |
--------------------------------------------------------------------------------
/lib/perl5/MANIFEST:
--------------------------------------------------------------------------------
1 | patcher
2 | MANIFEST
3 | Makefile.PL
4 | App/Cilly.pm
5 | App/Cilly/CilConfig.pm
6 | App/Cilly/KeptFile.pm
7 | App/Cilly/OutputFile.pm
8 | App/Cilly/TempFile.pm
9 |
--------------------------------------------------------------------------------
/src/cilversion.ml:
--------------------------------------------------------------------------------
1 | let cilVersion = "%%VERSION_NUM%%"
2 |
--------------------------------------------------------------------------------
/src/ext/dataslicing/META:
--------------------------------------------------------------------------------
1 | description = "data slicing"
2 |
--------------------------------------------------------------------------------
/src/ext/dataslicing/default:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goblint/cil/faeb7be1c0f875e22f77151a0765fdcfe4dad58d/src/ext/dataslicing/default
--------------------------------------------------------------------------------
/src/ext/dataslicing/dune:
--------------------------------------------------------------------------------
1 | (library
2 | (public_name goblint-cil.dataslicing)
3 | (name dataslicing)
4 | (libraries goblint-cil stdlib-shims)
5 | )
6 |
--------------------------------------------------------------------------------
/src/ext/dune:
--------------------------------------------------------------------------------
1 | (include_subdirs no)
2 |
--------------------------------------------------------------------------------
/src/ext/liveness/META:
--------------------------------------------------------------------------------
1 | description = "spit out live variables at a label"
2 |
--------------------------------------------------------------------------------
/src/ext/liveness/default:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goblint/cil/faeb7be1c0f875e22f77151a0765fdcfe4dad58d/src/ext/liveness/default
--------------------------------------------------------------------------------
/src/ext/liveness/dune:
--------------------------------------------------------------------------------
1 | (library
2 | (public_name goblint-cil.liveness)
3 | (name liveness)
4 | (libraries goblint-cil stdlib-shims)
5 | )
6 |
--------------------------------------------------------------------------------
/src/ext/makecfg/META:
--------------------------------------------------------------------------------
1 | description = "make the program look more like a CFG"
2 |
--------------------------------------------------------------------------------
/src/ext/makecfg/default:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goblint/cil/faeb7be1c0f875e22f77151a0765fdcfe4dad58d/src/ext/makecfg/default
--------------------------------------------------------------------------------
/src/ext/makecfg/dune:
--------------------------------------------------------------------------------
1 | (library
2 | (public_name goblint-cil.makecfg)
3 | (name makecfg)
4 | (libraries goblint-cil)
5 | )
6 |
--------------------------------------------------------------------------------
/src/ext/pta/META:
--------------------------------------------------------------------------------
1 | description = "alias analysis"
2 |
--------------------------------------------------------------------------------
/src/ext/pta/default:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goblint/cil/faeb7be1c0f875e22f77151a0765fdcfe4dad58d/src/ext/pta/default
--------------------------------------------------------------------------------
/src/ext/pta/dune:
--------------------------------------------------------------------------------
1 | (library
2 | (public_name goblint-cil.pta)
3 | (name ptranal)
4 | (libraries goblint-cil stdlib-shims)
5 | )
6 |
--------------------------------------------------------------------------------
/src/ext/syntacticsearch/META:
--------------------------------------------------------------------------------
1 | description = "Syntactic Search in CIL programs"
2 |
--------------------------------------------------------------------------------
/src/ext/syntacticsearch/dune:
--------------------------------------------------------------------------------
1 | (library
2 | (public_name goblint-cil.syntacticsearch)
3 | (name syntacticsearch)
4 | (libraries goblint-cil yojson ppx_deriving_yojson.runtime)
5 | (preprocess (pps ppx_deriving_yojson))
6 | )
7 |
--------------------------------------------------------------------------------
/src/ext/zrapp/META:
--------------------------------------------------------------------------------
1 | requires = "goblint-cil.liveness"
2 | description = "pretty printing with checks for name conflicts and temp variable elimination"
3 |
--------------------------------------------------------------------------------
/src/ext/zrapp/dune:
--------------------------------------------------------------------------------
1 | (library
2 | (public_name goblint-cil.zrapp)
3 | (name zrapp)
4 | (libraries goblint-cil goblint-cil.liveness stdlib-shims)
5 | )
6 |
--------------------------------------------------------------------------------
/src/ext/zrapp/zrapp.mli:
--------------------------------------------------------------------------------
1 | open GoblintCil
2 |
3 | val debug : bool ref
4 |
5 | val doElimTemps : bool ref
6 |
7 | val deputyAttrs : bool ref
8 |
9 | class zraCilPrinterClass : Cil.cilPrinter
10 |
11 | val zraCilPrinter : Cil.cilPrinter
12 |
13 | val pp_exp : Cil.fundec -> unit -> Cil.exp -> Pretty.doc
14 |
15 | val feature : Feature.t
16 |
--------------------------------------------------------------------------------
/src/frontc/dune:
--------------------------------------------------------------------------------
1 | (ocamllex clexer)
2 | (ocamlyacc cparser)
3 |
--------------------------------------------------------------------------------
/test/dune:
--------------------------------------------------------------------------------
1 | (rule
2 | (alias runtest)
3 | (deps (alias_rec ../cilly) (package goblint-cil) (source_tree .))
4 | (action (setenv "CC" "\"%{read-lines:../bin/real-gcc}\"" (run ./testcil -r --regrtest --showoutput))))
5 |
--------------------------------------------------------------------------------
/test/small1/.gdbinit:
--------------------------------------------------------------------------------
1 | # .gdbinit
2 |
3 | file vararg1.exe
4 | break main
5 | run
6 |
--------------------------------------------------------------------------------
/test/small1/GRT.c:
--------------------------------------------------------------------------------
1 | int g;
2 |
3 | void F() {
4 | int a;
5 | if (a>5) { g = 3; }
6 | }
7 |
8 | int main() {
9 | g = 4;
10 | F();
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/Makefile:
--------------------------------------------------------------------------------
1 | clean:
2 | rm -f *.o *.obj *.exe *.i *_ppp.c *.origi *~ *.s *.asm
3 | rm -f *cured.c *cil.c *infer.c *_comb.c *cabs.c *cured.optim.c
4 | rm -f *.pdb *.ilk *.stackdump a.out __scalar2pointer.txt
5 | rm -f *.html *.gif *.css
6 | rm -rf *.browser
--------------------------------------------------------------------------------
/test/small1/addr-array.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main() {
4 |
5 | int a[10];
6 |
7 | int (* pa)[10]; // pointer to array
8 |
9 | int m[4][7];
10 |
11 | // (&a) is a pointer to an array of 10 integers,
12 | // a is a pointer to integer
13 | if ((int)((&a)+1) != (int)(a+10)) E(1);
14 |
15 | pa = & a;
16 | if(& (pa[0][5]) != & a[5]) E(2);
17 |
18 | if((char*)(&m + 1) != ((char*)m) + 4 * 7 * sizeof(int)) E(3);
19 |
20 | if((char*)(&(m[2])) != (char*)(m + 2)) E(4);
21 |
22 | SUCCESS;
23 | }
24 |
--------------------------------------------------------------------------------
/test/small1/addr-string.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 | #include
3 |
4 | int main() {
5 |
6 | // String literals are lvalues
7 | char (*p)[4] = &("bar");
8 | wchar_t (*q)[4] = &(L"foO");
9 |
10 | if((*p)[1] != 'a') E(1);
11 | if((*q)[1] != 'o') E(2);
12 |
13 | SUCCESS;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/addrof3.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | struct qstr {
4 | const unsigned char * name;
5 | unsigned int len;
6 | unsigned int hash;
7 | };
8 |
9 | struct qstr *foo(const struct qstr *p) {
10 | return p;
11 | }
12 |
13 | int main() {
14 |
15 | struct qstr *x = foo(&(const struct qstr) { "socket:", 7, 0 });
16 | if(x->name[1] != 'o') E(1);
17 |
18 | if(x->len != 7) E(2);
19 |
20 | SUCCESS;
21 | }
22 |
--------------------------------------------------------------------------------
/test/small1/align1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 |
4 | struct testalign {
5 | int f1;
6 | } __attribute__((__aligned__(16)));
7 |
8 | struct t1 {
9 | int f0;
10 | struct testalign a;
11 | };
12 |
13 | int main() {
14 | int offset;
15 |
16 | offset = &((struct t1*)0)->a.f1;
17 | printf("Offset is: %d\n", offset);
18 |
19 | if ((int)&(( struct t1 *)0)->a.f1 & 15) {
20 | E(1);
21 | }
22 |
23 |
24 | SUCCESS;
25 | }
26 |
--------------------------------------------------------------------------------
/test/small1/alignas.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | struct XXH3_state_s {
4 | _Alignas(int) unsigned char customSecret1[25];
5 | _Alignas(64) unsigned char customSecret2[25];
6 | alignas(64) unsigned char customSecret3[25];
7 | };
8 |
9 | int main() {
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/alignas_proper.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | struct testalign {
4 | int f1;
5 | } __attribute__((__aligned__(16)));
6 |
7 | struct testalign2 {
8 | _Alignas(16) int f1;
9 | };
10 |
11 | struct testalign3 {
12 | _Alignas(long double) int f1;
13 | };
14 |
15 |
16 | int main() {
17 | struct testalign a;
18 | char static_assertion_failure_1[(__alignof__ (a) == 16) ? 1 : -1];
19 |
20 | struct testalign2 b;
21 | char static_assertion_failure_2[(__alignof__ (b) == 16) ? 1 : -1];
22 |
23 | struct testalign3 c;
24 | char static_assertion_failure_3[(__alignof__ (c) == __alignof__ (long double)) ? 1 : -1];
25 | return 0;
26 | }
27 |
--------------------------------------------------------------------------------
/test/small1/apachebuf.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "testharness.h"
3 |
4 | unsigned short window[65536];
5 |
6 | int set(char *buf, int value, int len) {
7 | int i;
8 | for (i=0;i 0; i--)
13 | {
14 | if (chrdevs[i] == ((void *)0))
15 | break;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/test/small1/builtin6.c:
--------------------------------------------------------------------------------
1 |
2 | // Extracted from the git repository.
3 | // CIL used to crash with "Error: Length of array is negative".
4 |
5 | int main() {
6 | const int *a;
7 | int *ret;
8 | sizeof(*(ret)) + (sizeof(char [1 - 2*!(__builtin_types_compatible_p(__typeof__(*((ret))), __typeof__(*((a)))))]) - 1);
9 | return 0;
10 | }
--------------------------------------------------------------------------------
/test/small1/c11-align-of.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 | #include
3 |
4 |
5 | int main() {
6 | int x = _Alignof (int);
7 | SUCCESS;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small1/c11-atomic.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 | #include
3 |
4 | _Atomic const int * p1; // p is a pointer to an atomic const int
5 | const _Atomic(int) * p3; // same
6 | _Atomic(int) const * p3;
7 | // _Atomic(int*) const p4; // unsupported as of now
8 |
9 | typedef _Atomic _Bool atomic_bool;
10 |
11 |
12 | int main() {
13 | SUCCESS;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/c11-caserange.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int pr(const char val)
4 | {
5 | switch (val) {
6 | case '0' ... '7':
7 | case 'd': /* KERN_DEFAULT */
8 | return 5;
9 | default:
10 | return 1;
11 | }
12 |
13 | return 2;
14 | }
15 |
16 | int main() {
17 | pr('a');
18 | SUCCESS;
19 | }
20 |
--------------------------------------------------------------------------------
/test/small1/c11-extendedFloat.c:
--------------------------------------------------------------------------------
1 | // Technically not C11 but ISO/IEC TS 18661-3:2015
2 | #include "testharness.h"
3 |
4 | _Float32 f32;
5 | _Float64 f64;
6 | _Float32x f32x;
7 | #if __HAVE_FLOAT64X
8 | _Float64x f64x;
9 | #endif
10 |
11 |
12 | int main() {
13 | if(sizeof(f32) != 4) {
14 | E(1);
15 | }
16 |
17 | #if __HAVE_FLOAT64X
18 | if(sizeof(f64) != 8) {
19 | E(2);
20 | }
21 | #endif
22 |
23 | SUCCESS;
24 | }
25 |
--------------------------------------------------------------------------------
/test/small1/c11-noreturn.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 | #include
3 |
4 | _Noreturn int fun() {
5 | SUCCESS;
6 | }
7 |
8 | noreturn int blub() {
9 | SUCCESS;
10 | }
11 |
12 | int blabla() __attribute__((noreturn));
13 |
14 | int blabla() {
15 | SUCCESS;
16 | }
17 |
18 | int main() {
19 | fun();
20 | blub();
21 | blabla();
22 |
23 | SUCCESS;
24 | }
25 |
--------------------------------------------------------------------------------
/test/small1/c11-static-assert.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 | #include
3 |
4 | _Static_assert (2 <= 18, "blubb");
5 |
6 |
7 | int main() {
8 | _Static_assert (2 <= 18, "blubb");
9 | SUCCESS;
10 | }
11 |
--------------------------------------------------------------------------------
/test/small1/c99-bool.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include "testharness.h"
4 | int main(void)
5 | {
6 | bool b = 17;
7 | _Bool b1 = 17;
8 |
9 | if(b == 1) {
10 |
11 | } else {
12 | E(1);
13 | }
14 |
15 | if(b1 == 1) {
16 |
17 | } else {
18 | E(2);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/test/small1/c99-predefined.c:
--------------------------------------------------------------------------------
1 | #include
2 | int main(void)
3 | {
4 | printf("%s\n", __FILE__);
5 | printf("%d\n", __LINE__);
6 | printf("%s\n", __func__);
7 | printf("%s\n", __DATE__);
8 | printf("%s\n", __TIME__);
9 | printf("%ld\n", __STDC_VERSION__);
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/c99-tgmath2.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include "testharness.h"
5 |
6 | typedef struct loc_t
7 | {
8 | long nloc;
9 | } loc_t;
10 |
11 |
12 | void fun(const loc_t* loc) {
13 | long l =8;
14 | int n0 =(int)sqrt(l); // works
15 | int n1 =(int)sqrt(loc->nloc); // fails
16 | }
17 |
18 |
19 | int main() {
20 | loc_t loc;
21 | loc.nloc = 5;
22 | loc_t* ptr = &loc;
23 | fun(ptr);
24 | SUCCESS;
25 | }
26 |
--------------------------------------------------------------------------------
/test/small1/c99-universal-character-names.c:
--------------------------------------------------------------------------------
1 | int main() {
2 | int \u03B1 = 5;
3 | char* arr = "\u2019";
4 | }
5 |
--------------------------------------------------------------------------------
/test/small1/call2.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 |
4 | int any_int(void) {
5 | return 3;
6 | }
7 |
8 | void main() {
9 | int tmp = -1;
10 | unsigned int G;
11 | // We had a bug that replaced the next two lines with
12 | // G = any_int ();
13 | tmp = any_int();
14 | G = tmp;
15 | tmp = tmp-3;
16 | if(tmp != 0) E(1);
17 | SUCCESS;
18 | }
19 |
--------------------------------------------------------------------------------
/test/small1/case_then_default_in_switch.c:
--------------------------------------------------------------------------------
1 | // Running this file with --domakeCFG yields an incorrect result in CIL 1.3.7 (revision 12099).
2 | #include "testharness.h"
3 |
4 | int main() {
5 | switch (1) {
6 | case 0:
7 | default:
8 | break;
9 | case 1: ;
10 | SUCCESS;
11 | }
12 | E(0);
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/caserange.c:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | int foo(int x) {
5 | switch(x) {
6 | case 6: x ++;
7 | case 7 ... 10: return foo(x + 2);
8 | case 'A' ... 'E' : return foo (x + 8);
9 | case 'F' ... 'Z' : return x;
10 | default:
11 | return foo (x + 5);
12 | }
13 | }
14 |
15 | int main() {
16 |
17 | return (foo(6) - 74);
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/test/small1/cast1.c:
--------------------------------------------------------------------------------
1 | typedef struct {
2 | int x;
3 | } IntStruct;
4 |
5 | int y;
6 |
7 | int main() {
8 | int * ip = &y;
9 | IntStruct * sp;
10 |
11 | sp = ip;
12 |
13 | return sp->x;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/cast2.c:
--------------------------------------------------------------------------------
1 | void free(void*);
2 |
3 | void foo()
4 | {
5 | (void)free(0);
6 | }
7 |
--------------------------------------------------------------------------------
/test/small1/cast3.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int __finite (double __x)
4 | {
5 | return (__extension__
6 | (((((union { double __d; int __i[2]; }) {__d: __x}).__i[1]
7 | | 0x800fffffu) + 1) >> 31));
8 | }
9 |
10 | int main() {
11 | double inf = 10000000000.0;
12 | double old;
13 |
14 | if(! __finite(2.0)) E(1);
15 |
16 | do { // Create an infinity
17 | old = inf;
18 | inf *= inf;
19 | } while(old != inf);
20 |
21 | if(__finite(inf)) E(2);
22 |
23 | SUCCESS;
24 | }
25 |
--------------------------------------------------------------------------------
/test/small1/cast4.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | typedef union un {
4 | int i;
5 | long long l;
6 | struct str {
7 | int i1, i2;
8 | } s;
9 | } un;
10 |
11 | int f(union un x) {
12 | return x.s.i1;
13 | }
14 |
15 | un glob = (un)6;
16 |
17 | int main() {
18 | un x = (un)5LL;
19 | if(x.l != 5LL) E(1);
20 | if(x.i != 5) E(2);
21 |
22 | {
23 | struct str s = { 1, 2 };
24 | un y = (union un) s;
25 | if(y.s.i1 != 1 || y.s.i2 != 2) E(3);
26 |
27 | if(f((un)s) != 1) E(4);
28 | }
29 |
30 | if(glob.i != 6) E(5);
31 |
32 | SUCCESS;
33 | }
34 |
--------------------------------------------------------------------------------
/test/small1/cast8.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | /* A very surprising bug that has surfaced after 3 years */
4 |
5 | int main() {
6 | int base = 5;
7 | unsigned long max_over_base =
8 | (unsigned long) -1 / base;
9 |
10 | unsigned long correct =
11 | ((unsigned long) -1) / base;
12 |
13 | printf("Result is %ld. Correct=%ld\n", max_over_base, correct);
14 | if(max_over_base != correct) E(1);
15 |
16 | SUCCESS;
17 | }
18 |
--------------------------------------------------------------------------------
/test/small1/castcall.c:
--------------------------------------------------------------------------------
1 | short S;
2 |
3 | int f(int x, int y)
4 | {
5 | return x+y;
6 | }
7 |
8 | int main (void) {
9 | return f(1, S++);
10 | }
11 |
--------------------------------------------------------------------------------
/test/small1/castincr.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void) {
5 | char *p;
6 | int i;
7 |
8 | p = malloc(2*sizeof(int));
9 | *(int *)p = 1;
10 | *((int *)p + 1) = 2;
11 |
12 | i = *((int *)p)++;
13 | printf("%d\n", i);
14 | i = *((int *)p)++;
15 | printf("%d\n", i);
16 |
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/test/small1/castunion.c:
--------------------------------------------------------------------------------
1 | union X {
2 | int a;
3 | short b;
4 | };
5 |
6 | int main()
7 | {
8 | union X u,v;
9 | v = (union X) u;
10 | return 0;
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/test/small1/clang-c11-generic-1-1.c:
--------------------------------------------------------------------------------
1 | // https://github.com/llvm/llvm-project/blob/d480f968ad8b56d3ee4a6b6df5532d485b0ad01e/clang/test/Sema/generic-selection.c
2 |
3 | int main() {
4 | (void) _Generic((void (*)()) 0,
5 | void (*)(int): 0,
6 | void (*)(void): 0);
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small1/clang-c11-generic-1-2.c:
--------------------------------------------------------------------------------
1 | // https://github.com/llvm/llvm-project/blob/d480f968ad8b56d3ee4a6b6df5532d485b0ad01e/clang/test/Sema/generic-selection.c
2 |
3 | int main() {
4 | (void) _Generic(0,
5 | char: 0, short: 0, long: 0);
6 | return 0;
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline1_1.c:
--------------------------------------------------------------------------------
1 | int add(int i, int j) {
2 | return i + j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline1_2.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(-3, 3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline2_1.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline2_2.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(-3, 3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline3_1.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline3_2.c:
--------------------------------------------------------------------------------
1 | int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(-3, 3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline4_1.c:
--------------------------------------------------------------------------------
1 | int add(int i, int j) {
2 | return i - j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline4_2.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(-3, 3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline5_1.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i - j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline5_2.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(-3, 3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline6_1.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i - j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline6_2.c:
--------------------------------------------------------------------------------
1 | int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(-3, 3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline7.h:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline7_1.c:
--------------------------------------------------------------------------------
1 | #include "combine-c99-mergeinline7.h"
2 |
--------------------------------------------------------------------------------
/test/small1/combine-c99-mergeinline7_2.c:
--------------------------------------------------------------------------------
1 | #include "combine-c99-mergeinline7.h"
2 |
3 | int main() {
4 | return add(-3, 3);
5 | }
6 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline1_1.c:
--------------------------------------------------------------------------------
1 | int add(int i, int j) {
2 | return i + j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline1_2.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(3, -3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline2_1.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline2_2.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(3, -3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline3_1.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline3_2.c:
--------------------------------------------------------------------------------
1 | int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(-3, 3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline4_1.c:
--------------------------------------------------------------------------------
1 | int add(int i, int j) {
2 | return i - j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline4_2.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(-3, 3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline5_1.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i - j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline5_2.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(-3, 3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline6_1.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i - j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline6_2.c:
--------------------------------------------------------------------------------
1 | int add(int i, int j) {
2 | return i + j;
3 | }
4 |
5 | int main() {
6 | return add(-3, 3);
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline7_1.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i - j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline7_2.c:
--------------------------------------------------------------------------------
1 | extern inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline7_3.c:
--------------------------------------------------------------------------------
1 | int add();
2 |
3 | int main() {
4 | return add(-3, 3);
5 | }
6 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline8_1.c:
--------------------------------------------------------------------------------
1 | int add();
2 |
3 | int main() {
4 | return add(-3, 3);
5 | }
6 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline8_2.c:
--------------------------------------------------------------------------------
1 | extern inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline8_3.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i - j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline9.h:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline9_1.c:
--------------------------------------------------------------------------------
1 | #include "combine-c99inline9.h"
2 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline9_2.c:
--------------------------------------------------------------------------------
1 | #include "combine-c99inline9.h"
2 |
3 | int main() {
4 | return add(-3, 3);
5 | }
6 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline_1.c:
--------------------------------------------------------------------------------
1 | #include "stdio.h"
2 | void add(int x, int y) {
3 | printf("Called non-inline\n");
4 | }
5 |
--------------------------------------------------------------------------------
/test/small1/combine-c99inline_2.c:
--------------------------------------------------------------------------------
1 | #include "stdio.h"
2 | inline void add(int i, int j) {
3 | printf("Called inline\n");
4 | }
5 |
6 | int main() {
7 | add(4, 5);
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/combine10_1.c:
--------------------------------------------------------------------------------
1 | /* We have 3 files. First defines g1, second g2, and third refers to both g1
2 | * and g2. */
3 |
4 | struct foo {
5 | struct foo * left, * right;
6 | int x;
7 | } g1;
8 |
--------------------------------------------------------------------------------
/test/small1/combine10_2.c:
--------------------------------------------------------------------------------
1 | typedef struct foo PSFOO;
2 | struct foo {
3 | struct foo * left;
4 | PSFOO * right;
5 | int x;
6 | } g2;
7 |
--------------------------------------------------------------------------------
/test/small1/combine10_3.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | extern struct foo {
4 | struct foo * left, * right;
5 | int x;
6 | } g1, g2;
7 |
8 |
9 | int main() {
10 | g1 = g2;
11 | SUCCESS;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/combine11_1.c:
--------------------------------------------------------------------------------
1 | /* We have two files, each with part of a structure undefined */
2 | struct list {
3 | struct list *next;
4 | struct foo *f;
5 | struct bar *b;
6 | } g;
7 |
8 | struct foo {
9 | double d;
10 | };
11 |
12 | extern void* f2();
13 | void* f1() {
14 | return (void*) & g.f->d;
15 | }
16 |
--------------------------------------------------------------------------------
/test/small1/combine11_2.c:
--------------------------------------------------------------------------------
1 | extern struct list {
2 | struct list *next;
3 | struct foo *f;
4 | struct bar *b;
5 | } g;
6 |
7 | struct bar {
8 | enum { A, B, C } e;
9 | };
10 |
11 | void* f2() {
12 | return (void*) & g.b->e;
13 | }
14 |
15 |
16 | int main() {
17 | void *v1 = f1(); /* Without prototype */
18 | void *v2 = f2();
19 | }
20 |
--------------------------------------------------------------------------------
/test/small1/combine12_1.c:
--------------------------------------------------------------------------------
1 | /* We test isomorphism between structs with different names and anonymous
2 | * structs */
3 | struct bar {
4 | int x;
5 | struct foo *next;
6 | };
7 |
8 | struct foo {
9 | struct bar b;
10 | } g;
11 |
12 | int main() {
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/combine12_2.c:
--------------------------------------------------------------------------------
1 | struct bar {
2 | struct {
3 | int x;
4 | struct foo *next;
5 | } c;
6 | };
7 |
8 | struct baz {
9 | struct {
10 | int x;
11 | struct bar *next;
12 | } b;
13 | } g;
14 |
--------------------------------------------------------------------------------
/test/small1/combine13_1.c:
--------------------------------------------------------------------------------
1 | /* Two identical structures but one uses typedef */
2 | struct foo {
3 | struct foo * left, * right;
4 | int x;
5 | } g;
6 |
7 |
--------------------------------------------------------------------------------
/test/small1/combine13_2.c:
--------------------------------------------------------------------------------
1 | typedef struct foo PSFOO;
2 | extern struct foo {
3 | struct foo * left;
4 | PSFOO * right;
5 | int x;
6 | } g;
7 |
8 | #include "testharness.h"
9 |
10 | int main() {
11 | printf("Address is %x\n", &g); /* Make sure we use g */
12 | SUCCESS;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/combine14_1.c:
--------------------------------------------------------------------------------
1 | /* A tests with function prototypes. We do not want to change the names of
2 | * the format arguments of a function to those specified by the prototype.
3 | * First the prototype. */
4 | #include "testharness.h"
5 |
6 | int protoname1 = 5;
7 | extern int protoname2;
8 |
9 | void foo(int protoname1);
10 |
11 | void bar(int myname) {
12 | protoname2 = myname;
13 | }
14 |
15 | int main() {
16 | foo(0); /* Should set protoname1 and protoname2 to 0 */
17 | if(protoname1 != 0) E(1);
18 | if(protoname2 != 0) E(2);
19 |
20 | SUCCESS;
21 | }
22 |
--------------------------------------------------------------------------------
/test/small1/combine14_2.c:
--------------------------------------------------------------------------------
1 | extern int protoname1;
2 |
3 | int protoname2 = 5;
4 |
5 | void bar(int protoname2);
6 |
7 | void foo(int myname) {
8 | protoname1 = myname;
9 |
10 | bar(0); /* Should set protoname2 */
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/combine15_2.c:
--------------------------------------------------------------------------------
1 | struct s2 {
2 | int x;
3 | } x1, x2; /* Constrain both s11 and s1 to be isomorphic */
4 |
5 | struct d2 {
6 | double x;
7 | } y2, y1; /* Constrain both d11 and d1 to be isomorphic */
8 |
9 |
--------------------------------------------------------------------------------
/test/small1/combine16_1.c:
--------------------------------------------------------------------------------
1 | /* A test the tries to produce double renaming */
2 | extern struct foo1 {
3 | int x;
4 | } x1;
5 |
6 | extern struct bar {
7 | double d;
8 | } x2;
9 |
10 | extern double test();
11 |
12 |
13 | int main() {
14 | if(x1.x + x2.d != test()) return 1;
15 |
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/test/small1/combine16_2.c:
--------------------------------------------------------------------------------
1 | struct foo2;
2 |
3 | struct foo2 {
4 | int x;
5 | } x1; /* This will be isomorphic with struct foo1 in file 1 */
6 |
7 |
8 | struct foo1 { /* This will be isomorphic with struct bar in file 1 */
9 | double d;
10 | } x2;
11 |
12 |
13 | double test() {
14 | return x1.x + x2.d;
15 | }
16 |
--------------------------------------------------------------------------------
/test/small1/combine17_1.c:
--------------------------------------------------------------------------------
1 | /* We test that the merger does not borrow the top-level const attribute for
2 | * a global declared extern to the definition. Because if the definition is
3 | * const then we might not be able to write it to it at all */
4 | extern const struct { int f; } x;
5 |
6 |
7 | int read() {
8 | return x.f;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/combine17_2.c:
--------------------------------------------------------------------------------
1 | struct { int f; } x; // Read-write
2 |
3 | #include "testharness.h"
4 |
5 | int main() {
6 | x.f = 5; // Now write to it
7 | if(read() != 5) E(1);
8 |
9 | SUCCESS;
10 | }
11 |
--------------------------------------------------------------------------------
/test/small1/combine18_1.c:
--------------------------------------------------------------------------------
1 | /* We test that we rename properly the name of enumeration items */
2 | enum e1 {
3 | ITEM1 = 0,
4 | ITEM2 = 1,
5 | } x1;
6 |
7 | extern int getitem5();
8 |
9 | #include "testharness.h"
10 |
11 | int main() {
12 | x1 = ITEM1;
13 | if(x1 != 0) E(1);
14 | if(getitem5() != 5) E(2);
15 | SUCCESS;
16 | }
17 |
--------------------------------------------------------------------------------
/test/small1/combine18_2.c:
--------------------------------------------------------------------------------
1 | enum e2 {
2 | ITEM1 = 5,
3 | ITEM2 = 6,
4 | } x2;
5 |
6 | int getitem5() {
7 | return ITEM1;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small1/combine1_1.c:
--------------------------------------------------------------------------------
1 | typedef int INT;
2 |
3 | struct str1 {
4 | INT x1;
5 | int x2;
6 | } array;
7 |
8 | int var = 7;
9 |
10 | extern void printf(char *, ...);
11 | #define E(n) { printf("Error %d\n", n); return (n); }
12 |
13 | extern int c2(void), c3(void);
14 | int main() {
15 | int c1res = sizeof(array);
16 | int c2res = c2();
17 | int c3res = c3();
18 |
19 | if(c1res != c3res) E(1);
20 |
21 | if(c2res != sizeof(int [10]) + sizeof(int)) E(2);
22 |
23 | if(var != 7) E(3);
24 |
25 | printf("Success\n");
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/test/small1/combine1_2.c:
--------------------------------------------------------------------------------
1 |
2 | typedef struct str1 {
3 | int random;
4 | } FOO;
5 |
6 | static int array[10];
7 |
8 | int c2(void) {
9 | return sizeof(array) + sizeof(struct str1);
10 | }
11 |
--------------------------------------------------------------------------------
/test/small1/combine1_3.c:
--------------------------------------------------------------------------------
1 | typedef int INT, *PINT;
2 |
3 | struct str1 {
4 | INT x1;
5 | int x2;
6 | } array2;
7 |
8 | int c3(void) {
9 | int var;
10 |
11 | var = 9; /* Hopefully we do not overwrite the global one */
12 | return sizeof(array2);
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/combine20_1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | static int tmp ;
4 |
5 | int usetmp() {
6 | return tmp;
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine20_2.c:
--------------------------------------------------------------------------------
1 |
2 | struct stralloc {
3 | char *s ;
4 | unsigned int len ;
5 | unsigned int a ;
6 | };
7 |
8 | static struct stralloc tmp; // This will turn into tmp___0 (merger)
9 |
10 |
11 | int main() {
12 | int tmp___0 = 5; // This will stay as it is, thus conflicting with the
13 | // new global
14 | char *path = tmp.s; // This will be changed to tmp___0.s !!!
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/test/small1/combine21_1.c:
--------------------------------------------------------------------------------
1 | static int gflag;
2 |
3 | // This is not considered correct code in GNU11, but is ok in GNU90.
4 | // -std=gnu90 used to be the default, but since GCC 5.1.0 it is -std=gnu11
5 | // To account for this, -std=gnu90 was added to the regressions tests
6 | // To make it GNU11, add extern
7 | __inline void testit ( int flag )
8 | {
9 | gflag = flag;
10 | }
11 |
12 | extern void otest(int flag);
13 |
14 | int
15 | main(int argc, char **argv)
16 | {
17 | testit(0);
18 | otest(2);
19 | testit(1);
20 | return 0;
21 | }
22 |
--------------------------------------------------------------------------------
/test/small1/combine21_2.c:
--------------------------------------------------------------------------------
1 | // __inline__ void testit ( int flag )
2 | // {
3 | // ;
4 | // }
5 |
6 | extern void testit ( int flag );
7 |
8 | void otest(int flag)
9 | {
10 | testit(flag);
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/combine22_1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | // Define an empty struct for now
4 | struct empty *ptr_empty;
5 |
6 | int other() {
7 | return (sizeof(struct empty));
8 | }
9 |
--------------------------------------------------------------------------------
/test/small1/combine22_2.c:
--------------------------------------------------------------------------------
1 | // Fill in the old empty struct
2 |
3 |
4 | typedef int MYINT;
5 |
6 | struct empty {
7 | MYINT i;
8 | } glob;
9 |
10 | struct empty *ptr_empty;
11 |
12 | int main() {
13 | return glob.i;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/combine2_1.c:
--------------------------------------------------------------------------------
1 | /* Declare it as an array but without length */
2 | extern char* foo[];
3 |
4 | /* Now it has a length but is global */
5 | char *foo[2] = {"first string", "second string"};
6 |
7 | extern int bar;
8 |
9 | int f1() {
10 | return bar;
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/combine2_2.c:
--------------------------------------------------------------------------------
1 | /* Declare it as an array but without length */
2 | extern char* foo[];
3 |
4 | /* Now it has a length but is static */
5 | static char *foo[2] = {"first string", "second string"};
6 |
7 | static int bar = 0;
8 |
9 | static char *foo_static = "My static string";
10 |
11 | int f2() {
12 | return bar;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/combine2_3.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int bar;
4 |
5 | int main() {
6 | f1();
7 | f2();
8 |
9 | SUCCESS;
10 | }
11 |
--------------------------------------------------------------------------------
/test/small1/combine3_1.c:
--------------------------------------------------------------------------------
1 | typedef struct foo *PFOO;
2 |
3 | typedef struct foo {
4 | int x;
5 | PFOO y;
6 | } *PTR;
7 |
8 | PTR g1;
9 |
--------------------------------------------------------------------------------
/test/small1/combine3_2.c:
--------------------------------------------------------------------------------
1 |
2 | typedef struct foo *PFOO;
3 |
4 | typedef struct foo {
5 | int x;
6 | int z; /* This is a new field */
7 | PFOO y;
8 | } *PTR;
9 |
10 | PTR g2;
11 |
12 | int main2() {
13 | int *d = & g2->z; /* Make sure we can refer to it */
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/test/small1/combine3_3.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | typedef struct foo *PFOO;
4 |
5 | typedef struct foo {
6 | int x;
7 | PFOO y;
8 | } *PTR;
9 |
10 | PTR g3;
11 |
12 | int main() {
13 | main2();
14 | /* Make sure that the offset is right */
15 | if(& g3->y != & ((struct { int x; PFOO y;} *)g3)->y) E(1);
16 |
17 | SUCCESS;
18 | }
19 |
--------------------------------------------------------------------------------
/test/small1/combine4_1.c:
--------------------------------------------------------------------------------
1 | /* A simple test with two files, no structs. The second file refers to the
2 | * same exact types and to foo */
3 | typedef int __intptr_t;
4 | typedef __intptr_t intptr_t;
5 |
6 | intptr_t foo(void) { return 0; }
7 |
--------------------------------------------------------------------------------
/test/small1/combine4_2.c:
--------------------------------------------------------------------------------
1 | typedef int __intptr_t;
2 | typedef int intptr_t;
3 |
4 | extern intptr_t foo(void);
5 |
6 | int main() {
7 | intptr_t x = foo();
8 | return x;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/combine5_1.c:
--------------------------------------------------------------------------------
1 | /* A test with 3 files. In the first two files we include the same .h and in
2 | * the third file we copy the contents of the include */
3 | #include "combine5.h"
4 | #include "testharness.h"
5 |
6 | int main() {
7 | printf("Address of TimeOuts=%x\n", &TimeOuts);
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/combine5_2.c:
--------------------------------------------------------------------------------
1 | #include "combine5.h"
2 |
--------------------------------------------------------------------------------
/test/small1/combine6_1.c:
--------------------------------------------------------------------------------
1 | typedef void *PVOID;
2 |
3 |
4 | typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
5 |
6 |
7 | typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
8 |
9 |
10 | __declspec(dllimport)
11 | int
12 | ExCreateCallback (
13 | PCALLBACK_OBJECT *CallbackObject,
14 | int ObjectAttributes,
15 | int Create,
16 | int AllowMultipleCallbacks
17 | );
18 |
19 |
20 | int main() {
21 | return 0;
22 | }
23 |
--------------------------------------------------------------------------------
/test/small1/combine6_2.c:
--------------------------------------------------------------------------------
1 | typedef void *PVOID;
2 |
3 | typedef struct _CALLBACK_OBJECT *PCALLBACK_OBJECT;
4 |
5 |
6 | __declspec(dllimport)
7 | int
8 | ExCreateCallback (
9 | PCALLBACK_OBJECT *CallbackObject,
10 | int ObjectAttributes,
11 | int Create,
12 | int AllowMultipleCallbacks
13 | );
14 |
15 |
--------------------------------------------------------------------------------
/test/small1/combine6_3.c:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/test/small1/combine7_1.c:
--------------------------------------------------------------------------------
1 | struct list1 {
2 | struct list2 *realnext;
3 | struct list1 *next;
4 | };
5 |
6 |
7 | struct list2 {
8 | double d;
9 | struct list2 *data;
10 | };
11 |
--------------------------------------------------------------------------------
/test/small1/combine7_2.c:
--------------------------------------------------------------------------------
1 | struct list12 {
2 | struct list22 *realnext;
3 | struct list12 *next;
4 | };
5 |
6 | struct list22 {
7 | double d;
8 | struct list22 *data;
9 | };
10 |
11 |
12 | int main() {
13 | struct list12 l;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/combine7_3.c:
--------------------------------------------------------------------------------
1 | /* struct list2 is not defined */
2 | struct list13 {
3 | struct list2 *realnext;
4 | struct list13 *next;
5 | };
6 |
--------------------------------------------------------------------------------
/test/small1/combine8_1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | struct foo {
4 | int x;
5 | struct googoo * next;
6 | } * g1;
7 |
8 |
9 | struct googoo {
10 | double d;
11 | };
12 |
13 |
14 | int main() {
15 | SUCCESS;
16 | }
17 |
--------------------------------------------------------------------------------
/test/small1/combine8_2.c:
--------------------------------------------------------------------------------
1 | typedef struct {
2 | int x;
3 | struct bar * next;
4 | } STR;
5 |
6 | STR * g1;
7 |
8 | struct bar {
9 | double d;
10 | };
11 |
--------------------------------------------------------------------------------
/test/small1/combine9_1.c:
--------------------------------------------------------------------------------
1 | /* We have two incompatible definitions of g
2 | * The struct looks the same if you do not unroll the typedef */
3 | #include "testharness.h"
4 |
5 | typedef int INT;
6 |
7 | struct {
8 | INT i;
9 | int x;
10 | } g;
11 |
12 |
13 | int main() {
14 | E(1); /* Should not compile */
15 | }
16 |
--------------------------------------------------------------------------------
/test/small1/combine9_2.c:
--------------------------------------------------------------------------------
1 | typedef short INT; /* This was declared int before */
2 |
3 | struct {
4 | INT i;
5 | int x;
6 | } g;
7 |
--------------------------------------------------------------------------------
/test/small1/combine_allocate_1.c:
--------------------------------------------------------------------------------
1 | __inline static void *allocate(unsigned int __8318_34___n ) ;
2 |
--------------------------------------------------------------------------------
/test/small1/combine_allocate_2.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | __inline static void *allocate (unsigned int __10884_34___n);
4 |
5 | __inline static void * allocate (unsigned int __10884_34___n)
6 | {
7 | return 0;
8 | }
9 |
10 |
11 | __inline static void *allocate___0 (unsigned int __11367_34___n);
12 |
13 |
14 | __inline static void * allocate___0 (unsigned int __11367_34___n)
15 | {
16 | return 0;
17 | }
18 |
19 |
20 |
21 | int main () {
22 | allocate___0(0);
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/test/small1/combine_copyptrs_1.c:
--------------------------------------------------------------------------------
1 | typedef char otherChar;
2 | __inline static otherChar *
3 | copyptrs (char *first, char *last,
4 | otherChar * result, struct true_type const *_4)
5 | {
6 | }
7 |
--------------------------------------------------------------------------------
/test/small1/combine_init_1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | //This was a bug in cabs2cil. Compiling complicated initializers in
4 | //multiple files generated overlapping global names __constr_expr*
5 |
6 | struct logger {
7 | char* s;
8 | int i;
9 | };
10 |
11 | struct logger *event_list_CHASSIS[]= {
12 | &(struct logger){"redSecondaryCPMStatusChange", 2013},
13 | &(struct logger){"redRestoreSuccess", 2014},
14 | &(struct logger){"redRestoreFail", 2015},
15 | 0
16 | };
17 |
18 | extern int c2(void), c3(void);
19 | int main() {
20 | return 0;
21 | }
22 |
--------------------------------------------------------------------------------
/test/small1/combine_init_2.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | struct logger {
4 | char* s;
5 | int i;
6 | };
7 |
8 | struct logger *event_list_CHASSIS_2[]= {
9 | &(struct logger){"redRestoreSuccess", 2014},
10 | &(struct logger){"redRestoreFail", 2015},
11 | 0
12 | };
13 |
--------------------------------------------------------------------------------
/test/small1/combine_node_alloc_1.c:
--------------------------------------------------------------------------------
1 | // combine_node_alloc_1.c
2 | // "Out of memory" problem
3 |
4 | struct node {
5 | struct node *link;
6 | };
7 | struct node *list[1] = {
8 | ((struct node *) 0)
9 | };
10 |
--------------------------------------------------------------------------------
/test/small1/combine_node_alloc_2.c:
--------------------------------------------------------------------------------
1 | // combine_node_alloc_1.c
2 | // "Out of memory" problem
3 |
4 | struct node {
5 | struct node *link;
6 | };
7 | struct node *list[1] = {
8 | ((struct node *) 0)
9 | };
10 |
11 | int main()
12 | {
13 | return (int)( list[0] );
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/combine_samefn_2.c:
--------------------------------------------------------------------------------
1 | // combine_samefn_2.c
2 |
3 | // repeated function
4 | int foo(int x)
5 | {
6 | int y = x + 3; // 8
7 | int z = y + x; // 13
8 | return z + x; // 18
9 | }
10 |
11 |
12 | // same thing for globals
13 | int myglobal = 3;
14 |
15 |
16 | // another inline func to collide with those in other file
17 | __inline static int func();
18 |
19 | __inline static int func()
20 | {
21 | return 3;
22 | }
23 |
24 | int otherFunc()
25 | {
26 | return func();
27 | }
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/test/small1/combine_sbumpB_1.c:
--------------------------------------------------------------------------------
1 | typedef int int_type;
2 |
3 | typedef int_type int_type1;
4 |
5 | static __inline__ int_type1 sbump(struct str1 *const);
6 |
--------------------------------------------------------------------------------
/test/small1/combine_sbumpB_2.c:
--------------------------------------------------------------------------------
1 | typedef int int_type;
2 |
3 | typedef int_type int_type1;
4 |
5 | __inline static int_type1 sbump(struct str1 *this ) ;
6 |
--------------------------------------------------------------------------------
/test/small1/combine_sbump_1.c:
--------------------------------------------------------------------------------
1 | struct f;
2 | static __inline__ int sbump(struct f *const);
3 |
4 |
--------------------------------------------------------------------------------
/test/small1/combine_sbump_2.c:
--------------------------------------------------------------------------------
1 | struct someStruct;
2 |
3 | __inline static int sbump (struct someStruct *this) // --> sbump___0
4 | {
5 | return (3);
6 | }
7 |
8 |
9 | __inline static int sbump___0 (struct someStruct *this); // --> sbump___1
10 | __inline static int sbump___0 (struct someStruct *this)
11 | {
12 | return (3);
13 | };
14 |
15 | foo ()
16 | {
17 | sbump___0 (0);
18 | }
19 |
20 | int main()
21 | {
22 | foo();
23 | }
24 |
--------------------------------------------------------------------------------
/test/small1/combine_syserr_1.c:
--------------------------------------------------------------------------------
1 | static __inline__ void
2 | __dt__8mystringFv (struct mystring *const this, int x)
3 | {
4 | if (this != 0)
5 | {
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/combine_syserr_2.c:
--------------------------------------------------------------------------------
1 |
2 | struct mystring
3 | {
4 | };
5 |
6 |
7 | static __inline__ void __dt__8mystringFv (struct mystring *const, int);
8 |
9 | extern int __T_9xSysError;
10 |
11 | int * glob = &__T_9xSysError;
12 |
13 | int __T_9xSysError = 0;
14 |
15 | static void* pdt = __dt__8mystringFv;
16 |
17 | static __inline__ void
18 | __dt__8mystringFv (struct mystring *const this, int x)
19 | {
20 | if (this != 0)
21 | {
22 | }
23 | }
24 |
25 | int main()
26 | {
27 | return 0;
28 | }
29 |
--------------------------------------------------------------------------------
/test/small1/combine_theFunc_1.c:
--------------------------------------------------------------------------------
1 | typedef int ptrdiff_t;
2 | typedef int FILE;
3 | static __inline__ ptrdiff_t theFunc (const FILE * __18137_44___f) { }
4 |
--------------------------------------------------------------------------------
/test/small1/combine_theFunc_2.c:
--------------------------------------------------------------------------------
1 | typedef int ptrdiff_t;
2 | typedef int FILE;
3 | __inline static ptrdiff_t theFunc (FILE const *__18137_44___f) { }
4 |
5 |
--------------------------------------------------------------------------------
/test/small1/combinealias_1.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void __foo(int x) {
4 | printf("Hello, world! %d\n", x);
5 | }
6 |
7 | void foo(int x) __attribute__((__alias__("__foo")));;
8 |
--------------------------------------------------------------------------------
/test/small1/combinealias_2.c:
--------------------------------------------------------------------------------
1 |
2 | // For linking with combinealias_1.c
3 | int main() {
4 | foo(42);
5 | return 0;
6 | }
7 |
--------------------------------------------------------------------------------
/test/small1/combineenum1_1.c:
--------------------------------------------------------------------------------
1 | /* Make sure that enumeration isomorphism is lax enough */
2 | enum {
3 | INT = 0,
4 | FLOAT,
5 | } x1;
6 |
7 |
8 | void foo() {
9 | x1 = FLOAT;
10 | }
11 |
--------------------------------------------------------------------------------
/test/small1/combineenum1_2.c:
--------------------------------------------------------------------------------
1 | extern enum {
2 | INT = 0,
3 | FLOAT = 3,
4 | } x1;
5 |
6 | #include "testharness.h"
7 |
8 | int main() {
9 | foo(); /* Set x1 */
10 | if(FLOAT != 3 || x1 != 1) E(1);
11 |
12 | SUCCESS;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/combineenum2_1.c:
--------------------------------------------------------------------------------
1 | /* Make sure that enumeration items get renamed */
2 | enum e1 {
3 | FIRST,
4 | SECOND,
5 | } x1;
6 |
7 |
8 | int main() {
9 | return x1;
10 | }
11 |
--------------------------------------------------------------------------------
/test/small1/combineenum2_2.c:
--------------------------------------------------------------------------------
1 | enum {
2 | SECOND,
3 | FIRST,
4 | } x2;
5 |
6 | int foo() {
7 | return x2;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small1/combineenum3_1.c:
--------------------------------------------------------------------------------
1 | /* Try to reuse the enum types with the same name */
2 | enum e1 {
3 | FIRST,
4 | SECOND,
5 | } x1;
6 |
7 | int main() {
8 | return x1;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/combineenum3_2.c:
--------------------------------------------------------------------------------
1 | enum e1 {
2 | FIRST = 0,
3 | SECOND,
4 | } x2;
5 |
--------------------------------------------------------------------------------
/test/small1/combinegnuinline_1.c:
--------------------------------------------------------------------------------
1 | // https://github.com/goblint/cil/pull/85
2 | #include
3 | #include "combinegnuinline_header.h"
4 | int main() {
5 | int x = goo();
6 | assert(x == 2);
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small1/combinegnuinline_2.c:
--------------------------------------------------------------------------------
1 | #include "combinegnuinline_header.h"
2 | int goo() {
3 | return 2;
4 | }
5 |
--------------------------------------------------------------------------------
/test/small1/combinegnuinline_header.h:
--------------------------------------------------------------------------------
1 | extern inline __attribute__((__gnu_inline__)) int foo()
2 | { return 5; }
3 |
--------------------------------------------------------------------------------
/test/small1/combineinline1_1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | /* Test that we remove duplicate inline functions */
4 | inline int foo(int x) {
5 | return x;
6 | }
7 |
8 | extern int getfoo2();
9 |
10 | int main() {
11 | if(getfoo2() != (int)foo) E(1);
12 |
13 | SUCCESS;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/combineinline1_2.c:
--------------------------------------------------------------------------------
1 | inline int foo(int x) {
2 | return x;
3 | }
4 |
5 |
6 | int getfoo2() {
7 | return (int)foo;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small1/combineinline2_1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | /* Test that we do not share too many inlines */
4 | static int g;
5 | static inline int foo(int x) { return g; }
6 |
7 | extern int getfoo2();
8 |
9 |
10 | int main() {
11 | if(getfoo2() == (int)foo) E(1);
12 | SUCCESS;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/combineinline2_2.c:
--------------------------------------------------------------------------------
1 | static int g;
2 | inline int foo(int x) { return g; }
3 |
4 |
5 | int getfoo2() { return (int)foo; }
6 |
--------------------------------------------------------------------------------
/test/small1/combineinline3_1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | /* Test that we rename properly includes even if they have prototypes */
4 | int foo(int x); /* Declare it here. */
5 |
6 | inline int foo(int x) { return x; }
7 |
8 | extern getfoo2();
9 |
10 | int main() {
11 | if(getfoo2() != (int)foo) E(1);
12 |
13 | SUCCESS;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/combineinline3_2.c:
--------------------------------------------------------------------------------
1 |
2 | int bar(int x); /* Declare it here. Name does not matter. */
3 |
4 | inline int bar(int x) { return x; }
5 |
6 |
7 | int getfoo2() {
8 | return (int)bar;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/combineinline4_1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | /* Test that we rename properly inlines even if they have prototypes and
4 | if they are used before they are defined */
5 | int foo(int x); /* Declare it here. */
6 |
7 | inline int foo(int x) { return x; }
8 |
9 | extern getfoo2();
10 |
11 | int main() {
12 | if(getfoo2() != (int)foo) {
13 | printf("Merging of inlines did not work\n");
14 | E(1);
15 | }
16 |
17 | SUCCESS;
18 | }
19 |
--------------------------------------------------------------------------------
/test/small1/combineinline4_2.c:
--------------------------------------------------------------------------------
1 |
2 | int bar(int x); /* Declare it here. Name does not matter. */
3 |
4 |
5 | int getfoo2() { /* Use bar before definition */
6 | return (int)bar;
7 | }
8 |
9 |
10 | inline int bar(int x) { return x; }
11 |
12 |
--------------------------------------------------------------------------------
/test/small1/combineinline6_1.c:
--------------------------------------------------------------------------------
1 | // Just one file
2 |
3 | // This declaration cannot be dropped even though foo2 will be dropped
4 | static __inline__ int foo2(int x);
5 |
6 |
7 | int main() {
8 | void *p = foo2;
9 | return foo2(5);
10 | }
11 |
12 | // This definition will be kept since it is the first
13 | static __inline__ int foo1(int x) {
14 | return x - 5;
15 | }
16 |
17 | // This will be dropped
18 | static __inline__ int foo2(int x) {
19 | return x - 5;
20 | }
21 |
--------------------------------------------------------------------------------
/test/small1/combineinline6_2.c:
--------------------------------------------------------------------------------
1 | // Just an empty file to make sure the merger runs
2 |
--------------------------------------------------------------------------------
/test/small1/combinelibrik_2.c:
--------------------------------------------------------------------------------
1 | /*
2 | chunk2.c - show that the CIL merger fails to rename a symbol when it must.
3 |
4 | In this file, we declare chunk to be a static variable.
5 | In another file we declare it to be a typedef.
6 | One of these two must get renamed but neither is.
7 |
8 | Test on Cygwin under Windows XP using CIL 1.2.4.
9 |
10 | See chunk1.c comments for step-by-step reproduction of bug.
11 | */
12 |
13 | extern int chunk1(char*);
14 |
15 | static char fake[1] ;
16 | static char *chunk = fake;
17 |
18 | int main(void)
19 | {
20 | return chunk1(chunk) - fake[0];
21 | }
22 |
23 |
24 |
--------------------------------------------------------------------------------
/test/small1/combinemerge1_1.c:
--------------------------------------------------------------------------------
1 | inline int add(int i, int j) {
2 | return i + j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combinemerge1_2.c:
--------------------------------------------------------------------------------
1 | extern inline int add(int i, int j) {
2 | return i - j;
3 | }
4 |
--------------------------------------------------------------------------------
/test/small1/combinemerge1_3.c:
--------------------------------------------------------------------------------
1 | int add();
2 |
3 | int main() {
4 | return add(-3, 3);
5 | }
6 |
--------------------------------------------------------------------------------
/test/small1/combinestruct1_1.c:
--------------------------------------------------------------------------------
1 | /* test merging of structures whose field names differ */
2 |
3 | struct A {
4 | int x;
5 | };
6 |
7 | /* make A's type part of the interface */
8 | extern struct A *connection;
9 |
10 | /* refer to A::x */
11 | int foo()
12 | {
13 | return connection->x;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/combinestruct1_2.c:
--------------------------------------------------------------------------------
1 | /* other half of combinestruct1 */
2 |
3 | struct B {
4 | int y;
5 | } x;
6 |
7 | /* connect A and B */
8 | struct B *connection = &x;
9 |
10 | /*refer to B::y */
11 | int main()
12 | {
13 | int whatever;
14 |
15 | whatever = connection->y;
16 | whatever += foo(); /* for the heck of it */
17 |
18 | return whatever - whatever;
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/test/small1/combinetaggedfn_1.c:
--------------------------------------------------------------------------------
1 | // combinetaggedfn_1.c
2 | // test problem that arises with --separate when one module
3 | // infers a function must be tagged, but another inferrs
4 | // it should not be tagged
5 |
6 | // in this module, foo will be untagged
7 | int foo(int x)
8 | {
9 | return x+1;
10 | }
11 |
--------------------------------------------------------------------------------
/test/small1/combinetaggedfn_2.c:
--------------------------------------------------------------------------------
1 | // combinetaggedfn_2.c
2 |
3 | // foo will be tagged
4 | int foo(int x);
5 |
6 | // wrong type; originally used 'void' but our polymorphism defeats hat
7 | typedef int* (*Func)(int*);
8 |
9 | int main()
10 | {
11 | Func f;
12 | int x;
13 |
14 | f = (Func)&foo; // make foo tagged
15 |
16 | // cast to correct type and invoke
17 | x = ((int (*)(int))f)(3);
18 |
19 | return x-4;
20 | }
21 |
22 |
23 |
--------------------------------------------------------------------------------
/test/small1/comma1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 |
4 | int to_hex(int x) { return x; }
5 |
6 | int main() {
7 |
8 | if(6 != to_hex((5, 6))) E(1);
9 |
10 | SUCCESS;
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/test/small1/compound1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main() {
4 | unsigned long a;
5 | unsigned long *p;
6 | p = (unsigned long *)&p;
7 | a = ++(*p);
8 | if (a-1 != (unsigned long)&p)
9 | E(1);
10 | SUCCESS;
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/compound2.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main() {
4 | struct l {
5 | struct l** next;
6 | } s[4];
7 | struct l* a;
8 | struct l* p[4];
9 | struct l* old;
10 | p[0] = s;
11 | p[0]->next = &p[0];
12 | old = (*p[0]->next);
13 | a = ((*p[0]->next) += 1);
14 | if (old + 1 != a)
15 | E(1);
16 | SUCCESS;
17 | }
18 |
--------------------------------------------------------------------------------
/test/small1/cond1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int foo() {
4 | return 5;
5 | }
6 |
7 | int main() {
8 |
9 | int x1 = ({goto L1; 0;}) && ({L1: 5;});
10 |
11 | printf("x1 = %d\n", x1);
12 |
13 | if(x1 != 1) E(1);
14 |
15 | {
16 | int x2 = 0 && ({L2: 5;});
17 | if(x2 != 0) E(2);
18 | }
19 |
20 | {
21 | int x3 = 0 || 5;
22 | printf("x3 = %d\n", x3);
23 | if(x3 != 1) E(3);
24 | }
25 |
26 | {
27 | int x4 = 0 || foo();
28 | printf("x4 = %d\n", x4);
29 | if(x4 != 1) E(4);
30 | }
31 |
32 | SUCCESS;
33 | }
34 |
--------------------------------------------------------------------------------
/test/small1/cond2.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int calls_to_foo = 0;
4 | int foo() {
5 | calls_to_foo ++;
6 | return calls_to_foo;
7 | }
8 |
9 | enum
10 | {
11 | _ISupper = (( 0 ) < 8 ? ((1 << ( 0 )) << 8) : ((1 << ( 0 )) >> 8)) ,
12 | _IScntrl = (( 9 ) < 8 ? ((1 << ( 9 )) << 8) : ((1 << ( 9 )) >> 8)) ,
13 | };
14 |
15 | int main() {
16 | static int x = (sizeof(int) == 4) ? (5 && 4) : &main;
17 |
18 | if(x != 1) E(1);
19 |
20 | {
21 | int *x2 = &main ? : 0;
22 | if(x2 != &main) E(2);
23 | }
24 |
25 | {
26 | int x3 = foo() ? : 0;
27 | if(x3 != 1 || calls_to_foo != 1) E(3);
28 | }
29 | SUCCESS;
30 | }
31 |
--------------------------------------------------------------------------------
/test/small1/const-array-init.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | /* We must strip all of the "const" qualifiers in structs that are used for
4 | * locals */
5 | struct foo {
6 | const int f1;
7 | struct bar {
8 | const int f2;
9 | const int a[8];
10 | } b;
11 | };
12 |
13 | int main()
14 | {
15 | const int values[] = { 0 };
16 | struct foo f = { 1, 2, 3, 4, 5, 6 };
17 | int x;
18 | x = values[0];
19 | exit(x + f.f1 + f.b.f2 - f.b.a[0]);
20 | }
21 |
--------------------------------------------------------------------------------
/test/small1/const-compound-cast.c:
--------------------------------------------------------------------------------
1 | const struct Structure {
2 | int field;
3 | } structure;
4 |
5 |
6 | typedef int Array[10];
7 | const Array array;
8 |
9 |
10 | void override()
11 | {
12 | *((int *) array[0]) = 2;
13 | *((int *) &structure.field) = 1;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/const-struct-init.c:
--------------------------------------------------------------------------------
1 | struct inner {
2 | int field;
3 | };
4 |
5 |
6 | struct outer {
7 | const struct inner inner;
8 | };
9 |
10 |
11 | int main()
12 | {
13 | struct outer outer = { { 0 } };
14 | return outer.inner.field;
15 | }
16 |
--------------------------------------------------------------------------------
/test/small1/const10.c:
--------------------------------------------------------------------------------
1 | typedef int some_type[1];
2 | const some_type mine = {1};
3 |
4 |
5 | int main() {
6 | return mine[0] - 1;
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/const12.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main()
4 | {
5 | int x = -(unsigned char)1;
6 |
7 | printf("%d\n", x);
8 | if (x != -1) E(1);
9 |
10 | SUCCESS;
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/const13.c:
--------------------------------------------------------------------------------
1 | /* Sourceforge bug #1850745 */
2 |
3 | #include "string.h"
4 |
5 | typedef struct
6 | {
7 | char p[5];
8 | } t2;
9 |
10 | void consttst1(const char *p);
11 |
12 | void consttst2(const t2 * p2)
13 | {
14 | consttst1(p2->p[0]?p2->p:NULL);
15 | }
16 |
--------------------------------------------------------------------------------
/test/small1/const14.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | long z;
4 | int zz;
5 |
6 | int main()
7 | {
8 | long x1 = 2L * (z * 0);
9 | long x2 = 2L * (z & 0);
10 | long x3 = 2L * (0 << zz);
11 | long x4 = 2L * (0 >> zz);
12 |
13 | printf("%ld\n", x1);
14 | printf("%ld\n", x2);
15 | printf("%ld\n", x3);
16 | printf("%ld\n", x4);
17 | if (x1 != 0) E(1);
18 | if (x2 != 0) E(2);
19 | if (x3 != 0) E(3);
20 | if (x4 != 0) E(4);
21 |
22 | SUCCESS;
23 | }
24 |
--------------------------------------------------------------------------------
/test/small1/const15.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | unsigned long x = 0xfffffffffffffffeUL;
4 |
5 | int main(){
6 | /* CIL used to truncate unsigned long constants to 32-bits, even on
7 | * 64-bits machines */
8 | if(sizeof(unsigned long) == 8 &&
9 | x == 0xfffffffeUL)
10 | E(1);
11 |
12 | SUCCESS;
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/const16.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | struct F { int x; int y; };
4 |
5 | int main()
6 | {
7 | int timeout = 0;
8 | int x = 0;
9 | while (1)
10 | {
11 | const struct F i = { x++, };
12 | if (i.x > 0)
13 | break;
14 | if (++timeout > 5)
15 | goto die;
16 | }
17 | return 0;
18 | die:
19 | E(1);
20 | }
21 |
--------------------------------------------------------------------------------
/test/small1/const2.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main() {
4 | unsigned int x = (unsigned)0 - 1;
5 |
6 | if((x >= 0) == 0) E(1);
7 |
8 | if (((unsigned)0 - 1 >= 0) == 0)
9 | E(2);
10 |
11 | SUCCESS;
12 |
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/const3.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main() {
4 | long long x = 8LL;
5 |
6 | if(x != 8) E(1);
7 |
8 | SUCCESS;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/const5.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 | #include
3 |
4 | int main() {
5 |
6 | int slen = strlen(".nfs") + 5;
7 | char silly[slen+1];
8 |
9 | slen += 20;
10 |
11 | if(sizeof(silly) != 10) E(1)
12 |
13 | SUCCESS;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/const6.c:
--------------------------------------------------------------------------------
1 | // From c-torture
2 | extern struct foo bar;
3 | struct foo {
4 | int a;
5 | };
6 |
7 | int tst[__alignof__ (bar) >= __alignof__ (int) ? 1 : -1];
8 |
9 |
10 | int main() {
11 | if(sizeof(tst) != 4)
12 | abort();
13 |
14 | exit(0);
15 | }
16 |
--------------------------------------------------------------------------------
/test/small1/const7.c:
--------------------------------------------------------------------------------
1 | /* There was a parsing error here */
2 | static const int pi = 3, s0 = 7;
3 |
--------------------------------------------------------------------------------
/test/small1/const8.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main() {
4 | unsigned base = 5;
5 | unsigned long max = (unsigned long) -1 / base;
6 |
7 | unsigned long max1 = (unsigned long) -1;
8 | printf("max = %ld, max1 = %ld\n", max, max1 / base);
9 |
10 | if(max != max1 / base) E(1);
11 |
12 | SUCCESS;
13 | }
14 |
15 |
16 |
--------------------------------------------------------------------------------
/test/small1/const9.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int glob;
4 | int globarray[(sizeof(void *) == sizeof(void *)) ? 4 : (int)&glob];
5 |
6 | struct foo {
7 | int f1, f2, f3;
8 | };
9 |
10 | int arr1[9 * (int)(&((struct foo*)0)->f3)];
11 |
12 | int main() {
13 | int x=5,y;
14 |
15 | int array[(sizeof(void *) == sizeof(void *)) ? 4 : y];
16 |
17 | switch (x) {
18 |
19 | case ((sizeof(void *) == sizeof(void *)) ? 4 : y ):
20 | break;
21 | }
22 | SUCCESS;
23 | }
24 |
--------------------------------------------------------------------------------
/test/small1/constfold.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int global;
4 |
5 | void init()
6 | {
7 | global = 1;
8 | }
9 |
10 |
11 | int main()
12 | {
13 | global = 0;
14 | init();
15 |
16 | if (global) {
17 | global = 2;
18 | } else {
19 | E(1);
20 | }
21 | return 0;
22 | }
23 |
--------------------------------------------------------------------------------
/test/small1/constfold2.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 | int main()
3 | {
4 | /* We check that with warnings as errors this fails also after CIL */
5 | int displayMask = 1 << 31;
6 | displayMask = 0;
7 |
8 | return displayMask;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/constprop.c:
--------------------------------------------------------------------------------
1 |
2 | #define X 5
3 | int foo(int x) {
4 | int y = ((1UL << 12) / (6 * 64) * 64 * 8 > 1024 * 1024
5 | ? 1024 * 1024
6 | : (1UL << 12) / (6 * 64) * 64 * 8)
7 | / (8 * sizeof(unsigned long int));
8 | if(5 > 7 ? 1 + sizeof(char) : 5 << 2) {
9 | x ++;
10 | } else {
11 | x --;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/cpp-2.c:
--------------------------------------------------------------------------------
1 | // Fron c-torture
2 | /* Copyright (C) 2000 Free Software Foundation.
3 |
4 | by Alexandre Oliva */
5 |
6 | #pragma /* the token after #pragma is optional. */
7 |
--------------------------------------------------------------------------------
/test/small1/cpp-3.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 | extern int strlen(const char *);
3 | /* GCC allows a bunch of escapes in strings */
4 |
5 |
6 | char *str = "\( \{ \[ \% \x20 \e \E \a \b \f \n \r \t \v \? \\ \' ";
7 |
8 | int main() {
9 | if(strlen(str) != 34) E(1);
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/decl_mix_stmt.c:
--------------------------------------------------------------------------------
1 | // decl_mix_stmt.c
2 | // declarations mixed with statements, a-la C99
3 |
4 | // NOTE: gcc-2.x does not support this syntax (but 3.x does)
5 |
6 | int main()
7 | {
8 | int x;
9 | x = 3;
10 |
11 | int y;
12 | y = 6;
13 |
14 | return x+y - 9;
15 | }
16 |
--------------------------------------------------------------------------------
/test/small1/do_while_cont.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main(int argc, char **argv)
4 | {
5 | int i = 0;
6 | int k = 0;
7 |
8 | do {
9 | i++;
10 | if(i == 1) { continue; }
11 | k = 8;
12 | } while ( i < 1);
13 |
14 | printf("i is: %i\n", i);
15 | if(i != 1) E(1);
16 | if(k != 0) E(2);
17 | SUCCESS;
18 | }
19 |
--------------------------------------------------------------------------------
/test/small1/duplicate.c:
--------------------------------------------------------------------------------
1 | typedef int agp_setup;
2 |
3 |
4 | static int test___0;
5 |
6 | static __inline__ unsigned long
7 | jiffies_to_timespec(unsigned long jiffies, struct timespec *value)
8 | {
9 | return (jiffies % 100 ) * (1000000000L / 100 );
10 | }
11 |
12 |
13 | int foo(int jiffies) {
14 | return test___0 + jiffies;
15 | }
16 |
17 |
18 | float test;
19 |
20 | float bar() {
21 | agp_setup x = 5;
22 | return x;
23 | }
24 |
25 | extern float jiffies;
26 |
27 | int agp_setup(void) {
28 | return 5 + jiffies;
29 | }
30 |
--------------------------------------------------------------------------------
/test/small1/empty.i:
--------------------------------------------------------------------------------
1 | int main() {
2 | return 0;
3 | }
4 | //Lexer test: comment with no trailing newline.
5 | //This only happens in .i files, since the preprocessor will add the newline
--------------------------------------------------------------------------------
/test/small1/enum-scope.c:
--------------------------------------------------------------------------------
1 | enum {A, B, C} foo() {
2 | return A;
3 | }
4 |
5 | void bar() {
6 | if (foo() == A) {
7 | }
8 | }
9 |
10 | int main() {
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/enum.c:
--------------------------------------------------------------------------------
1 |
2 | typedef enum foo {
3 | F1 = 0,
4 | F2 = (long int)(~0UL >> 1),
5 | F3,
6 | F4
7 | } ENUM;
8 |
9 |
10 |
11 | void foo(void) {
12 | int x = F2;
13 | int y = F1;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/enum2.c:
--------------------------------------------------------------------------------
1 | extern void exit(int);
2 | extern void abort(void);
3 |
4 |
5 | // Fron ctorture
6 | typedef enum foo E;
7 | enum foo { e0,
8 | e1 = e0 + 2 };
9 |
10 | enum bar { b0 = e1 };
11 |
12 | struct {
13 | E eval;
14 | enum bar b;
15 | } s;
16 |
17 | void p() {
18 | abort();
19 | }
20 |
21 | void f() {
22 | switch (s.eval) {
23 | case e0:
24 | case e1 + 2:
25 | p();
26 | }
27 | }
28 |
29 | int main() {
30 | s.eval = e1;
31 | f();
32 | exit(0);
33 | }
34 |
--------------------------------------------------------------------------------
/test/small1/enum3a.c:
--------------------------------------------------------------------------------
1 | /* test support for large constants in enums (gcc-specific)
2 | if you ask me, gcc's behaviour is a bit weird, but... */
3 | enum fun {
4 | SMALL = 33,
5 | STRANGE = 44LL,
6 | LARGE = 22LL << 34
7 | };
8 |
9 | long long magic1 = 22LL << 34;
10 | enum fun magic2 = LARGE;
11 |
12 | int main()
13 | {
14 | int ok = 1;
15 |
16 | ok = ok && sizeof SMALL == sizeof(int);
17 |
18 | return ok ? 0 : 2;
19 | }
20 |
--------------------------------------------------------------------------------
/test/small1/enum3b.c:
--------------------------------------------------------------------------------
1 | /* test support for large constants in enums (gcc-specific)
2 | if you ask me, gcc's behaviour is a bit weird, but... */
3 | enum fun {
4 | SMALL = 33,
5 | STRANGE = 44LL,
6 | LARGE = 22LL << 34
7 | };
8 |
9 | long long magic1 = 22LL << 34;
10 | enum fun magic2 = LARGE;
11 |
12 | int main()
13 | {
14 | int ok = 1;
15 |
16 | ok = ok && sizeof STRANGE == sizeof(int);
17 |
18 | return ok ? 0 : 2;
19 | }
20 |
--------------------------------------------------------------------------------
/test/small1/enum3c.c:
--------------------------------------------------------------------------------
1 | /* test support for large constants in enums (gcc-specific)
2 | if you ask me, gcc's behaviour is a bit weird, but... */
3 | enum fun {
4 | SMALL = 33,
5 | STRANGE = 44LL,
6 | TINY = 22 << 34,
7 | LARGE = 22LL << 34
8 | };
9 |
10 | long long magic1 = 22LL << 34;
11 | enum fun magic2 = LARGE;
12 |
13 | int main()
14 | {
15 | int ok = 1;
16 |
17 | ok = ok && TINY == 0;
18 |
19 | return ok ? 0 : 2;
20 | }
21 |
--------------------------------------------------------------------------------
/test/small1/enum3d.c:
--------------------------------------------------------------------------------
1 | /* test support for large constants in enums (gcc-specific)
2 | if you ask me, gcc's behaviour is a bit weird, but... */
3 | enum fun {
4 | SMALL = 33,
5 | STRANGE = 44LL,
6 | LARGE = 22LL << 34
7 | };
8 |
9 | long long magic1 = 22LL << 34;
10 | enum fun magic2 = LARGE;
11 |
12 | int main()
13 | {
14 | int ok = 1;
15 |
16 | ok = ok && sizeof LARGE == sizeof(long long);
17 |
18 | return ok ? 0 : 2;
19 | }
20 |
--------------------------------------------------------------------------------
/test/small1/enum3e.c:
--------------------------------------------------------------------------------
1 | /* test support for large constants in enums (gcc-specific)
2 | if you ask me, gcc's behaviour is a bit weird, but... */
3 | enum fun {
4 | SMALL = 33,
5 | STRANGE = 44LL,
6 | LARGE = 22LL << 34
7 | };
8 |
9 | long long magic1 = 22LL << 34;
10 | enum fun magic2 = LARGE;
11 |
12 | int main()
13 | {
14 | int ok = 1;
15 |
16 | ok = ok && sizeof magic2 == sizeof(long long);
17 |
18 | return ok ? 0 : 2;
19 | }
20 |
--------------------------------------------------------------------------------
/test/small1/enum3f.c:
--------------------------------------------------------------------------------
1 | /* test support for large constants in enums (gcc-specific)
2 | if you ask me, gcc's behaviour is a bit weird, but... */
3 | enum fun {
4 | SMALL = 33,
5 | STRANGE = 44LL,
6 | LARGE = 22LL << 34
7 | };
8 |
9 | long long magic1 = 22LL << 34;
10 | enum fun magic2 = LARGE;
11 |
12 | int main()
13 | {
14 | int ok = 1;
15 |
16 | ok = ok && (LARGE + 1 == magic1 + 1);
17 |
18 | return ok ? 0 : 2;
19 | }
20 |
--------------------------------------------------------------------------------
/test/small1/enum3g.c:
--------------------------------------------------------------------------------
1 | /* test support for large constants in enums (gcc-specific)
2 | if you ask me, gcc's behaviour is a bit weird, but... */
3 | enum fun {
4 | SMALL = 33,
5 | STRANGE = 44LL,
6 | LARGE = 22LL << 34
7 | };
8 |
9 | long long magic1 = 22LL << 34;
10 | enum fun magic2 = LARGE;
11 |
12 | int main()
13 | {
14 | int ok = 1;
15 |
16 | ok = ok && (magic2 + 1 == magic1 + 1);
17 |
18 | return ok ? 0 : 2;
19 | }
20 |
--------------------------------------------------------------------------------
/test/small1/enum3h.c:
--------------------------------------------------------------------------------
1 | /* test support for large constants in enums (gcc-specific)
2 | if you ask me, gcc's behaviour is a bit weird, but... */
3 | enum fun {
4 | NEG = -1,
5 | SMALL = 33,
6 | STRANGE = 44LL,
7 | LARGE = 22LL << 34
8 | };
9 |
10 | long long magic1 = 22LL << 34;
11 | enum fun magic2 = LARGE;
12 |
13 | int main()
14 | {
15 | int ok = 1;
16 |
17 | ok = ok && (enum fun)-1 < 0;
18 |
19 | return ok ? 0 : 2;
20 | }
21 |
--------------------------------------------------------------------------------
/test/small1/enum3i.c:
--------------------------------------------------------------------------------
1 | /* test support for large constants in enums (gcc-specific)
2 | if you ask me, gcc's behaviour is a bit weird, but... */
3 | enum fun {
4 | SMALL = 33,
5 | STRANGE = 44LL,
6 | LARGE = 22LL << 34
7 | };
8 |
9 | long long magic1 = 22LL << 34;
10 | enum fun magic2 = LARGE;
11 |
12 | int main()
13 | {
14 | int ok = 1;
15 |
16 | ok = ok && (enum fun)-1 > 0;
17 |
18 | return ok ? 0 : 2;
19 | }
20 |
--------------------------------------------------------------------------------
/test/small1/enum3j.c:
--------------------------------------------------------------------------------
1 | /* test support for large constants in enums (gcc-specific)
2 | if you ask me, gcc's behaviour is a bit weird, but... */
3 | enum fun {
4 | SMALL = 33,
5 | };
6 |
7 | int main()
8 | {
9 | int ok = 1;
10 |
11 | ok = ok && (enum fun)-1 > 0;
12 |
13 | return ok ? 0 : 2;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/enum3k.c:
--------------------------------------------------------------------------------
1 | /* test support for large constants in enums (gcc-specific)
2 | if you ask me, gcc's behaviour is a bit weird, but... */
3 | enum fun {
4 | SMALL = 33,
5 | STRANGE = 44LL,
6 | LARGE = 22LL << 34
7 | };
8 |
9 | int main()
10 | {
11 | int ok = 1;
12 |
13 | ok = ok && (typeof(SMALL))-1 < 0;
14 |
15 | return ok ? 0 : 2;
16 | }
17 |
--------------------------------------------------------------------------------
/test/small1/enum3l.c:
--------------------------------------------------------------------------------
1 | enum fun {
2 | HMM = (1ULL << 32)
3 | };
4 |
5 | int main()
6 | {
7 | int ok = 1;
8 |
9 | /* HMM is signed - types are based on value, not the defining expression */
10 | ok = ok && (typeof(HMM))-1 < 0;
11 |
12 | return ok ? 0 : 2;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/extern1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | // CIL seems to drop this on the floor!!!
4 | extern int main(int argc) {
5 | return 0;
6 | }
7 |
--------------------------------------------------------------------------------
/test/small1/extinline2.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | extern inline int f(void) { return 1; }
4 |
5 | int g(void)
6 | {
7 | return f();
8 | }
9 |
10 | int f(void) { return 2; }
11 |
12 | int h(void)
13 | {
14 | return f();
15 | }
16 |
17 |
18 | int main(void)
19 | {
20 | if (g() != 2) E(1);
21 | if (h() != 2) E(1);
22 | SUCCESS;
23 | }
24 |
--------------------------------------------------------------------------------
/test/small1/extinline3.c:
--------------------------------------------------------------------------------
1 | extern inline int f(void) { return 1; }
2 |
3 | int g(void)
4 | {
5 | return f();
6 | }
7 |
8 |
--------------------------------------------------------------------------------
/test/small1/fallthrough-label.c:
--------------------------------------------------------------------------------
1 | int main() {
2 | int a =5;
3 |
4 | switch(a) {
5 | case 5:
6 | a = 8;
7 | __attribute__((__fallthrough__));
8 | case 10:
9 | __attribute__((__fallthrough__));
10 | default:
11 | a = 8;
12 | }
13 |
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/test/small1/flexible-array-member-bad.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | //NUMERRORS 1
4 |
5 | struct s { unsigned long x; int y; char t[]; };
6 | int main(){
7 | struct s b = { .x = sizeof(b), .y = 2, .t = {1,2,3} } ; // ERROR(1): non-static initialization of a flexible array member
8 | SUCCESS;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/float.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main()
4 | {
5 | double f1 = 5.e-1 ; // KAI CC emits code like this
6 | double f2 = 5.00000e-1 ; // this is normal
7 |
8 | if (f1 != f2) {
9 | E(1);
10 | }
11 | SUCCESS;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/float2.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | int main() {
4 | double a[2][2];
5 | memcpy(a, (double[2][2]) { { 1.0, 2.0 } , { 3.0, 4.0 } }, sizeof a);
6 | printf("%f %f %f %f\n", a[0][0], a[0][1], a[1][0], a[1][1]);
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small1/float3.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | int main() {
4 | _Float128 f = 0.0q;
5 | _Float128 g = 0.0F128;
6 | _Float128 h = 0.0f128;
7 | _Float128 i = 0.0Q;
8 |
9 | _Complex _Float128 f1 = 0.0qi;
10 | _Complex _Float128 g1 = 0.0iF128;
11 | _Complex _Float128 h1 = 0.0f128i;
12 | _Complex _Float128 i1 = 0.0iQ;
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/for1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main() {
4 | int z;
5 | for(int i = 0, j = 5; i <= 3 && j >= 3; i ++, j --, z = i) {
6 | i += j - 3;
7 | }
8 | if(z != 5) E(1);
9 |
10 | SUCCESS;
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/formalscope.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 |
4 | //
5 | //Test scoping of formal names
6 | //
7 |
8 | double renamed;
9 |
10 | void bar(typeof(renamed) x, //"renamed" refers to the global, with type double
11 | int renamed,
12 | typeof(renamed) z) //"renamed" refers to the second formal
13 | {
14 | if (sizeof(x) != sizeof(double)) E(2);
15 | if (sizeof(z) != sizeof(int)) E(3);
16 | if (x + renamed != z) E(4);
17 | }
18 |
19 | int main(void)
20 | {
21 | bar(1.0, 2, 3);
22 | SUCCESS;
23 | }
24 |
--------------------------------------------------------------------------------
/test/small1/func.c:
--------------------------------------------------------------------------------
1 | int (*pfun1)(int (*)(int), int);
2 | int (*pfun2)(int (*)(int), int);
3 |
4 | typedef int (*intfun)(int);
5 | intfun arrfun[5];
6 |
7 | int testf(int k) {
8 | return k;
9 | }
10 |
11 | int foo(int (*bar)(int), int n) {
12 |
13 | pfun1 = foo;
14 | pfun1 = & foo;
15 | pfun1 = * * * pfun2;
16 |
17 | pfun1 = arrfun[4];
18 |
19 | pfun2(* * testf, 5);
20 |
21 | return 1;
22 | }
23 |
24 |
25 |
--------------------------------------------------------------------------------
/test/small1/func10.c:
--------------------------------------------------------------------------------
1 | // gcc and Elsa handle this but Cil can't handle this:
2 | void
3 | (*posix_signal(sig_num, action))()
4 | int sig_num;
5 | void (*action)();
6 | {
7 | }
8 |
9 | // These are ok in all three tools. The fun thing is that I guessed // these two would go through Cil before I tried them. :-)
10 | void posix_signal2(sig_num, action)
11 | int sig_num;
12 | void (*action)();
13 | {
14 | }
15 |
16 | void
17 | (*posix_signal3(int sig_num, void (*action)() ))() {
18 | return 0;
19 | }
20 |
21 | int main() {
22 | return 0;
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/test/small1/func2.c:
--------------------------------------------------------------------------------
1 | extern void exit(int);
2 |
3 |
4 | // A test with function pointers
5 | typedef int (* FUN1)();
6 |
7 |
8 | // Fun1 will be a wild function
9 | int fun1(int i1, int* p2, int* p3, int i4) {
10 | return i1 + *p2 + *p3 + i4;
11 | }
12 |
13 | // Now make fun1 a WILD function pointer
14 | FUN1 g = fun1;
15 |
16 |
17 | int main() {
18 | int loc1 = 7, loc2 = 9, loc3 = 11;
19 |
20 | // Call fun1 through g
21 | if(g(5, &loc1, &loc2, 13) != 34)
22 | exit(1);
23 |
24 | // Call fun1 directly
25 | if(fun1(1, &loc1, &loc3, 7) != 26)
26 | exit(2);
27 |
28 |
29 | exit(0);
30 | }
31 |
--------------------------------------------------------------------------------
/test/small1/func3.c:
--------------------------------------------------------------------------------
1 |
2 | typedef int (*func)(); // Declare this without arguments
3 |
4 | int foo(int *x, int z, int *y) {
5 | return *x + z + *y;
6 | }
7 |
8 | int main() {
9 | int x = 5, y = 7, z = 13;
10 |
11 | func f = foo;
12 |
13 | x = f(&x, &z, &y) - 12 - (int)&z; // Should be 0
14 |
15 | return x + foo(&x, z, &y) - 20;
16 |
17 |
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/test/small1/func4.c:
--------------------------------------------------------------------------------
1 | typedef struct {
2 | int (*f)(int);
3 | } FOO;
4 |
5 | int highorder(int a(int), int arg) {
6 | return a(arg);
7 | }
8 |
9 | int incr(int x) {
10 | return x + 1;
11 | }
12 | #include "testharness.h"
13 |
14 | int main() {
15 | if(highorder(incr, 5) != 6) E(1);
16 |
17 | {
18 | FOO x = { incr };
19 | if(x.f(6) != 7) E(2);
20 | }
21 |
22 | SUCCESS;
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/test/small1/funcarg.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | /* An argument whose type is a function should be turned into a function
4 | * pointer */
5 |
6 | int foo(int x()) {
7 | return x();
8 | }
9 |
10 | // A prototype. This should work but right now it does not because of the
11 | // way abs_direct_decl is defined in cparser.mly. If we use the definition
12 | // from the book we get conflicts
13 | int bar(int ());
14 |
15 |
--------------------------------------------------------------------------------
/test/small1/funptr1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | typedef int (ide_dmaproc_t)(int, int *);
4 |
5 |
6 |
7 | int test(int x, int *y) {
8 | return x + *y;
9 | }
10 |
11 | struct foo {
12 | ide_dmaproc_t *dmaproc;
13 | } x = { test };
14 |
15 |
16 |
17 | int main() {
18 | int y = 7;
19 |
20 | if(x.dmaproc(5, &y) != 12) E(1);
21 |
22 | SUCCESS;
23 | }
24 |
--------------------------------------------------------------------------------
/test/small1/gcc-c11-generic-2-1.c:
--------------------------------------------------------------------------------
1 | // https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/testsuite/gcc.dg/c11-generic-2.c
2 |
3 | void
4 | f (int n)
5 | {
6 | /* Multiple 'default's. */
7 | _Generic (n, default: 1, default: 2);
8 | }
9 |
10 | int main() {
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/gcc-c11-generic-2-2.c:
--------------------------------------------------------------------------------
1 | // https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/testsuite/gcc.dg/c11-generic-2.c
2 |
3 | void
4 | f (int n)
5 | {
6 | /* Variably-modified type not ok. */
7 | _Generic (n, int[n]: 0, default: 1);
8 | }
9 |
10 | int main() {
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/gcc-c11-generic-2-3.c:
--------------------------------------------------------------------------------
1 | // https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/testsuite/gcc.dg/c11-generic-2.c
2 |
3 | struct incomplete;
4 |
5 | void
6 | f (int n)
7 | {
8 | /* Type must be complete. */
9 | _Generic (n, struct incomplete: 0, default: 1);
10 | }
11 |
12 | int main() {
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/gcc-c11-generic-2-4.c:
--------------------------------------------------------------------------------
1 | // https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/testsuite/gcc.dg/c11-generic-2.c
2 |
3 | void
4 | f (int n)
5 | {
6 | /* Type must be complete. */
7 | _Generic (n, void: 0, default: 1);
8 | }
9 |
10 | int main() {
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/gcc-c11-generic-2-5.c:
--------------------------------------------------------------------------------
1 | // https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/testsuite/gcc.dg/c11-generic-2.c
2 |
3 | void
4 | f (int n)
5 | {
6 | /* Type must be object type. */
7 | _Generic (n, void (void): 0, default: 1);
8 | }
9 |
10 | int main() {
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/gcc-c11-generic-2-6.c:
--------------------------------------------------------------------------------
1 | // https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/testsuite/gcc.dg/c11-generic-2.c
2 |
3 | void
4 | f (int n)
5 | {
6 | /* Two compatible types in association list. */
7 | _Generic (&n, int: 5, signed int: 7, default: 23);
8 | }
9 |
10 | int main() {
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/gcc-c11-generic-2-7.c:
--------------------------------------------------------------------------------
1 | // https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/testsuite/gcc.dg/c11-generic-2.c
2 |
3 | void
4 | f (int n)
5 | {
6 | /* No matching association. */
7 | _Generic (n, void *: 5);
8 | }
9 |
10 | int main() {
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/gcc-c11-generic-3-1.c:
--------------------------------------------------------------------------------
1 | // https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/testsuite/gcc.dg/c11-generic-3.c
2 |
3 | char const *a = _Generic ("bla", char *: "");
4 | char const *c = _Generic ((int const) { 0 }, int: "");
5 | char const *e = _Generic (+(int const) { 0 }, int: "");
6 |
7 | int main() {
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/gcc-c11-generic-3-2.c:
--------------------------------------------------------------------------------
1 | // https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/testsuite/gcc.dg/c11-generic-3.c
2 |
3 | char const *b = _Generic ("bla", char[4]: "");
4 |
5 | int main() {
6 | return 0;
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/gcc-c11-generic-3-3.c:
--------------------------------------------------------------------------------
1 | // https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/testsuite/gcc.dg/c11-generic-3.c
2 |
3 | char const *d = _Generic ((int const) { 0 }, int const: "");
4 |
5 | int main() {
6 | return 0;
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/gcc-c11-generic-3-4.c:
--------------------------------------------------------------------------------
1 | // https://github.com/gcc-mirror/gcc/blob/16e2427f50c208dfe07d07f18009969502c25dc8/gcc/testsuite/gcc.dg/c11-generic-3.c
2 |
3 | char const *f = _Generic (+(int const) { 0 }, int const: "");
4 |
5 | int main() {
6 | return 0;
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/globals.c:
--------------------------------------------------------------------------------
1 |
2 | static int *glob2;
3 |
4 | int *glob1 = (int*) & glob2;
5 |
6 | static int *glob2 = (int*) & glob1;
7 |
8 | int arr2[10];
9 | int arr2[10];
10 | int arr2[10];
11 |
12 |
--------------------------------------------------------------------------------
/test/small1/globals2.c:
--------------------------------------------------------------------------------
1 |
2 | extern int base_files[];
3 | const char *const lang_dir_names[] = { "c",
4 | ((void *)0)};
5 |
6 | int base_files[((sizeof (lang_dir_names) / sizeof ((lang_dir_names)[0])) - 1)]
7 | = { sizeof(lang_dir_names[1]) }
8 | ;
9 |
--------------------------------------------------------------------------------
/test/small1/hello.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 |
4 |
5 | int main() {
6 | printf("Hello world\n");
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small1/huff1.c:
--------------------------------------------------------------------------------
1 | unsigned short read2Target(unsigned char * ptr )
2 | {
3 | if (1 /* targetNotLikeHost */) {
4 | return ((unsigned short )(((int )(*ptr) << 8) + (int )(*(ptr + 1))));
5 | } else {
6 | return ((*((unsigned short *)ptr)));
7 | }
8 | }
9 |
10 | int readStructTarget(unsigned char * filePtr ,
11 | unsigned char * fileEnd , ...) {
12 | int x = read2Target(fileEnd);
13 | return x;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/init1.c:
--------------------------------------------------------------------------------
1 | extern void exit(int);
2 |
3 | struct {
4 | struct {
5 | int *f1;
6 | int *f2;
7 | } s1;
8 | struct {
9 | int *f3;
10 | } s2;
11 | } memory[10] = { 1 };
12 |
13 | int main() {
14 | if(memory[0].s1.f1 != (int*)1)
15 | exit(1);
16 | exit(0);
17 | }
18 |
--------------------------------------------------------------------------------
/test/small1/init10.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | typedef int tint;
4 |
5 |
6 | struct foo {
7 | int other;
8 | int tint; // Reuse the typedef name
9 | } x = { tint : 5 };
10 |
11 |
12 | int main() {
13 | if(x.tint != 5) E(1);
14 | if(x.other != 0) E(2);
15 |
16 | SUCCESS;
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/test/small1/init11.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 |
4 | void foo(int invok) {
5 | static const int honour_longs = (4 > 4) || (4 > 4);
6 | static int bar = 0;
7 |
8 | if(invok == 0) {
9 | if(honour_longs != 0) E(1);
10 | if(bar != 0) E(2);
11 | bar = 1;
12 | return;
13 | }
14 | if(bar != 1) E(3);
15 | return;
16 | }
17 |
18 |
19 | int main() {
20 |
21 | static int bar = 3;
22 | foo(0);
23 | if(bar != 3) E(4);
24 | foo(1);
25 | if(bar != 3) E(5);
26 |
27 | SUCCESS;
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/test/small1/init12.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | // From c-torture
4 | struct empty { };
5 | struct something {
6 | int spacer;
7 | struct empty foo;
8 | int bar;
9 | };
10 |
11 | struct something X = {
12 | foo: (struct empty) { },
13 | bar: 1,
14 | };
15 |
16 |
17 | int main() {
18 | if(X.bar != 1) E(1);
19 | if(X.spacer != 0) E(2);
20 |
21 | SUCCESS;
22 | }
23 |
--------------------------------------------------------------------------------
/test/small1/init13.c:
--------------------------------------------------------------------------------
1 | // From c-torture
2 | #include "testharness.h"
3 |
4 | typedef struct
5 | {
6 | char *key;
7 | char *value;
8 | } T1;
9 |
10 | typedef struct
11 | {
12 | long type;
13 | char *value;
14 | } T3;
15 |
16 | T1 a[] =
17 | {
18 | {
19 | "",
20 | ((char *)&((T3) {1, (char *) 1}))
21 | }
22 | };
23 |
24 |
25 | int main() {
26 | T3 *t3;
27 |
28 | if(sizeof(a) != sizeof(T1)) E(1);
29 |
30 | if(a[0].key[0]) E(2);
31 |
32 | t3 = a[0].value;
33 | if(t3->type != 1) E(3);
34 | if(t3->value != 1) E(4);
35 |
36 |
37 | SUCCESS;
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/test/small1/init14.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 |
4 |
5 |
6 | int main() {
7 | if(((int []){1, 2, 3, 4})[1] != 2) E(1);
8 |
9 | ((int []){1, 2, 3, 4})[1] = 15;
10 |
11 | SUCCESS;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/init16.c:
--------------------------------------------------------------------------------
1 | //The Gnome calendar application uses initializers with arithmetic expressions:
2 | #include "testharness.h"
3 |
4 |
5 | int x = ! (3 && ! 3);
6 |
7 | int array[(3 && !3) ? 6 : 8];
8 |
9 | int main() {
10 | return x - 1;
11 | }
12 |
13 |
--------------------------------------------------------------------------------
/test/small1/init17.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | static int f()
4 | {
5 | return 0x101;
6 | }
7 |
8 | int c0 = (char)257;
9 |
10 | int main(int argc, char **argv)
11 | {
12 | int c1 = (char)f();
13 | int c2;
14 | int c3 = (char)257;
15 | c2 = (char)f();
16 | printf("Should be 1: c0=%d, c1=%d, c2=%d, c3=%d\n", c0, c1, c2, c3);
17 | if(c0 != 1) E(1);
18 | if(c1 != 1) E(2);
19 | if(c2 != 1) E(3);
20 | if(c3 != 1) E(4);
21 | SUCCESS;
22 | }
23 |
--------------------------------------------------------------------------------
/test/small1/init18.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | struct foo {
4 | int a,b;
5 | };
6 |
7 | //The length should be 5, not 3.
8 | static struct foo foos[]={
9 | {1},
10 | {},
11 | {3,4},
12 | {},
13 | {}
14 | };
15 |
16 | int main() {
17 | printf("sizeof foos = %d.\n", sizeof(foos));
18 |
19 | if (sizeof(foos) != 5*sizeof(struct foo)) E(1);
20 | if (foos[2].b != 4) E(2);
21 | if (foos[4].b != 0) E(3);
22 |
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/test/small1/init19.c:
--------------------------------------------------------------------------------
1 | typedef struct tTimNetAddr {
2 | int isIPv4;
3 | union
4 | {
5 | int addr;
6 | struct {double d; int x; } addr6;
7 | } u;
8 | } tTimNetAddr;
9 |
10 | tTimNetAddr isisPolChangePrefixV6 = {
11 | .isIPv4 = 0,
12 | .u = {
13 | .addr6 = {.d = 0.0, .x = 5},
14 | },
15 | };
16 |
17 |
18 | int main() {
19 | return isisPolChangePrefixV6.u.addr6.x != 5;
20 | }
21 |
--------------------------------------------------------------------------------
/test/small1/init2.c:
--------------------------------------------------------------------------------
1 | extern void printf(char *, ...);
2 | #define E(n) { printf("Error %d\n", n); return n; }
3 |
4 | // from linux sources
5 | int tickadj1 = 500/ 100 ? : 1;
6 | int tickadj2 = 0 / 100 ? : 1;
7 |
8 | int main() {
9 | if(tickadj1 != 5) E(1);
10 | if(tickadj2 != 1) E(2);
11 |
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/init22.c:
--------------------------------------------------------------------------------
1 | //Test for a compound initializer bug. The if statement for t?2:3 was being
2 | //added twice.
3 |
4 | //Bug report from Peter Hawkins, based on
5 | //linux-2.6.17.1/net/ipv4/route.c:ip_route_output_slow
6 |
7 | //Patch by Benjamin Monate
8 |
9 | struct bar {
10 | int x;
11 | };
12 | struct foo {
13 | struct bar b;
14 | int y;
15 | };
16 |
17 | int rand(void);
18 |
19 | int main() {
20 | int t = rand();
21 | struct foo f = {
22 | .b = {
23 | .x = (t?2:3),
24 | },
25 | .y = 42
26 | };
27 | return 0;
28 | }
29 |
--------------------------------------------------------------------------------
/test/small1/init8.c:
--------------------------------------------------------------------------------
1 | struct pci_device_info {
2 | unsigned short device;
3 | unsigned short seen;
4 | const char *name;
5 | };
6 |
7 | struct pci_device_info __devices_0000 []
8 | __attribute__ ((__section__ (".data.init"))) = { };
9 |
10 |
--------------------------------------------------------------------------------
/test/small1/inline2.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main(void) {
4 | int x = 1, y = 5, z = 0;
5 | #if defined(i386) || defined(__x86_64__)
6 | asm("movl %[in1], %[out] \n addl %[in2], %[out]"
7 | : [out] "=r" (z) : [in1] "m" (x), [in2] "m" (y) );
8 |
9 | if(z != 6) E(1);
10 | #endif
11 | return 0;
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/test/small1/inline3.c:
--------------------------------------------------------------------------------
1 | //MSVC considers _inline a keyword, but gcc doesn't.
2 |
3 | //From linux-2.6.17.1/fs/jfs/jfs_incore.h:
4 | struct {
5 | char _unused[16]; /* 16: */
6 | int _dxd[4]; /* 16: */
7 | char _inline[128]; /* 128: inline symlink */
8 | /* _inline_ea may overlay the last part of
9 | * file._xtroot if maxentry = XTROOTINITSLOT
10 | */
11 | char _inline_ea[128]; /* 128: inline extended attr */
12 | } link;
13 |
--------------------------------------------------------------------------------
/test/small1/knr1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | int old_function(a, b, c)
5 | int a, * c;
6 | int *b;
7 | {
8 | return a + *b;
9 | }
10 |
11 |
12 | norettype(int x) {
13 | return x;
14 | }
15 |
16 | norettype_old(x)
17 | int x;
18 | {
19 | return x;
20 | }
21 |
22 | norettype_old2()
23 | {
24 | return ;
25 | }
26 |
27 | static norettype_old3(a)
28 | int **a;
29 | {
30 | return **a;
31 | }
32 |
33 |
34 | noretnoarg(x) {
35 | return x;
36 | }
37 |
--------------------------------------------------------------------------------
/test/small1/label2.c:
--------------------------------------------------------------------------------
1 | // Example with computed labels
2 | #include "testharness.h"
3 |
4 | int main() {
5 |
6 | void *nextstate = && Loop;
7 | int x = 0;
8 | int acc = 0;
9 | int count = 5;
10 |
11 | Loop:
12 | if(x == 10) nextstate = && Done;
13 | acc += x; x ++;
14 | goto *nextstate;
15 | Done:
16 |
17 | if(acc != 11 * 10 / 2) {
18 | printf("Bad result: %d\n", acc);
19 | return 1;
20 | }
21 |
22 | if(count <= 0) return 0;
23 |
24 | acc = 0; x = 0;
25 | nextstate = && Loop;
26 | count --;
27 |
28 | goto *nextstate;
29 | }
30 |
--------------------------------------------------------------------------------
/test/small1/label2b.c:
--------------------------------------------------------------------------------
1 | // Example with computed labels
2 | #include "testharness.h"
3 |
4 | int main() {
5 |
6 | void *nextstate = && Loop;
7 | int x = 0;
8 | int acc = 0;
9 | int count = 5;
10 |
11 | Loop:
12 | if(x == 10) nextstate = && Done;
13 | acc += x; x ++;
14 | goto *nextstate;
15 | Done:
16 |
17 | if(acc != 11 * 10 / 2) {
18 | printf("Bad result: %d\n", acc);
19 | return 1;
20 | }
21 |
22 | if(count <= 0) return 0;
23 |
24 | acc = 0; x = 0;
25 | nextstate = && Loop;
26 | count --;
27 |
28 | goto *nextstate;
29 | }
30 |
--------------------------------------------------------------------------------
/test/small1/label3.c:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | int main() {
5 | static void* array[] = { && L1, && L2, && L3 };
6 | int acc = 0;
7 |
8 | L1: acc += 1; goto * array[1];
9 | L2: acc += 2; goto * array[2];
10 | L3: acc += 3;
11 |
12 | return acc - 6;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/label3b.c:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | int main() {
5 | static void* array[] = { && L1, && L2, && L3 };
6 | int acc = 0;
7 |
8 | L1: acc += 1; goto * array[1];
9 | L2: acc += 2; goto * array[2];
10 | L3: acc += 3;
11 |
12 | return acc - 6;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/label5.c:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | int main(void){
5 | return 0;
6 |
7 | this_label_is_not_used: __attribute__ ((unused))
8 | return 1;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/label6.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h";
2 |
3 | /* The error is triggered because CIL 1.3.7 introduces
4 | a loop back to _L. */
5 |
6 | int main() {
7 | int x = 1, y = 0;
8 | _L:
9 | if (x && ++y > 1) E(1) else lbl:;
10 | SUCCESS;
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/label7.c:
--------------------------------------------------------------------------------
1 | int main() {
2 | int x;
3 | _L:
4 | if (x || ++x) { x++; x++; x++; x++; x++; x++; }
5 | return 0;
6 | }
7 |
--------------------------------------------------------------------------------
/test/small1/label8.c:
--------------------------------------------------------------------------------
1 | int main() {
2 | goto __Cont;
3 | for ( ; ; ) continue;
4 | __Cont:
5 | return 0;
6 | }
7 |
--------------------------------------------------------------------------------
/test/small1/label9.c:
--------------------------------------------------------------------------------
1 | /* Running with --domakeCFG, the input file:
2 |
3 | int main() {
4 | while (0);
5 | return 0;
6 | }
7 |
8 | gets transformed into this file. Running this file with --domakeCFG
9 | triggers an error in CIL 1.3.7.
10 | */
11 |
12 | /* Generated by CIL v. 1.3.7 */
13 | /* print_CIL_Input is true */
14 |
15 | #line 1
16 | int main(void)
17 | {
18 |
19 | {
20 | {
21 | #line 2
22 | while (1) {
23 | while_0_continue: /* CIL Label */ ;
24 | goto while_0_break;
25 | }
26 | while_0_break: /* CIL Label */ ;
27 | }
28 | #line 3
29 | return (0);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/test/small1/land_expr.c:
--------------------------------------------------------------------------------
1 | int main (int argc, char* argv[])
2 | {
3 | signed char a = 7;
4 | signed char b = 1;
5 | b = (1 && a) ;
6 | return 0;
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/large_unsigned_long.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | int main(){
4 | // Previously, CIL assigned "-3" here.
5 | // This previously erroneous behavior cannot be really tested for, so it has to be manually inspected.
6 | unsigned long long x = 18446744073709551613ul;
7 | x = 18446744073709551613ul;
8 | if (x <= 18446744073709551612ull){
9 | assert(0);
10 | }
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/li.c:
--------------------------------------------------------------------------------
1 | typedef struct foo {
2 | int x;
3 | int *y;
4 | } Foo;
5 |
6 | Foo * xlarg(Foo **pargs) {
7 | void * make_me_wild = pargs;
8 | return *pargs;
9 | }
10 |
11 | Foo * xeval(Foo *args) {
12 | Foo * expr = xlarg(& args);
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/lineno.i:
--------------------------------------------------------------------------------
1 | //There's a gcc bug on Cygwin where filenames referring to
2 | //non-existent files can result in large line numbers appearing in the
3 | //preprocessed source.
4 |
5 | # 4294967150 "cpp_heap.c"
6 | int main() { return 0; }
7 |
--------------------------------------------------------------------------------
/test/small1/linux_atomic.c:
--------------------------------------------------------------------------------
1 | typedef struct { int counter; } atomic_t;
2 |
3 | #define TYPE0 volatile struct { int a[100]; }
4 | #define TYPE1 volatile int
5 |
6 | static __inline__ void atomic_add(int i, volatile atomic_t *v)
7 | {
8 | __asm__ __volatile__(
9 | "" "addl %1,%0"
10 | :"=m" ((*(TYPE0 *) v ) )
11 | :"ir" (i), "m" ((*(TYPE0 *) v ) ));
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/local.c:
--------------------------------------------------------------------------------
1 |
2 | typedef struct node {
3 | struct node *xl_cdr; /* the cdr pointer */
4 | } NODE;
5 |
6 |
7 | NODE *** xlstack;
8 |
9 | #define rplacd(x,y) ((x)->xl_cdr = (y))
10 |
11 |
12 | /* bquote1 - back quote helper function */
13 | NODE *bquote1(NODE *expr)
14 | {
15 | NODE ***oldstk;
16 | expr->xl_cdr = bquote1(expr->xl_cdr);
17 | xlstack = oldstk;
18 | return (expr);
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/test/small1/localinit.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main () {
4 | int x = 5;
5 | x = 42; //CIL is moving this below the definition of i
6 | int i = x;
7 | if (i != 42) E(99);
8 |
9 | SUCCESS;
10 | }
11 |
--------------------------------------------------------------------------------
/test/small1/logical.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main() {
4 | int x;
5 | int *p = 0;
6 | x = 1;
7 | if(x || *p) { // Do not check p if x = 1
8 | x = 0;
9 | }
10 | if(x && *p) { // Do not check p if x = 0
11 | E(1);
12 | }
13 | SUCCESS;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/logical1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main() {
4 | long long x = 0x100000000LL;
5 | int i = 1;
6 | if (i && x) SUCCESS;
7 | E(1);
8 | }
9 |
--------------------------------------------------------------------------------
/test/small1/logical2.c:
--------------------------------------------------------------------------------
1 | int main() {
2 | int x = 0;
3 | int keep1 = x && x;
4 | int keep2 = x || x;
5 | int keep3 = x++ && x;
6 | int keep4 = x++ || x;
7 | int unfold1 = x && x++;
8 | int unfold2 = x || ++x;
9 | return 0;
10 | }
11 |
--------------------------------------------------------------------------------
/test/small1/longBlock.ml:
--------------------------------------------------------------------------------
1 | open GoblintCil
2 |
3 | ;;
4 |
5 | initCIL ();
6 |
7 | let variable = makeGlobalVar "value" intType in
8 |
9 | let instructions = ref [] in
10 | for loop = 1 to 25000 do
11 | let instruction = Set(var variable, integer loop, locUnknown, locUnknown) in
12 | instructions := instruction :: !instructions
13 | done;
14 |
15 | let statement = mkStmt (Instr !instructions) in
16 | let sink = open_out "/dev/null" in
17 | dumpStmt defaultCilPrinter sink 0 statement
18 |
--------------------------------------------------------------------------------
/test/small1/lstring.c:
--------------------------------------------------------------------------------
1 | typedef unsigned short wchar_t;
2 | typedef wchar_t WCHAR;
3 | typedef wchar_t *WCHARP;
4 |
5 | int fun_accepting_wchar(WCHARP arg) {
6 | int i;
7 | char * ptr = (char *)arg;
8 | for (i=0;i<10;i++)
9 | printf("byte %d = '%c'\n",i,ptr[i]);
10 | return 0;
11 | }
12 |
13 | int main() {
14 | fun_accepting_wchar(L"Hello, world.\n");
15 | return 0;
16 | }
17 | /* Correct Output (microsoft command line compiler):
18 | byte 0 = 'H'
19 | byte 1 = ''
20 | byte 2 = 'e'
21 | byte 3 = ''
22 | byte 4 = 'l'
23 | byte 5 = ''
24 | byte 6 = 'l'
25 | byte 7 = ''
26 | byte 8 = 'o'
27 | byte 9 = ''
28 | */
29 |
--------------------------------------------------------------------------------
/test/small1/macro_hidden.c:
--------------------------------------------------------------------------------
1 | #define hidden __attribute__((__visibility__("hidden")))
2 | hidden int x;
3 | int main()
4 | {
5 | x = 17;
6 |
7 | return 0;
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/math1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | #include
4 |
5 | int main() {
6 | double d = HUGE_VAL;
7 |
8 | #ifdef __USE_ISOC99
9 | double df = HUGE_VALF;
10 | double dl = HUGE_VALL;
11 | #endif
12 |
13 | SUCCESS;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/matrix.c:
--------------------------------------------------------------------------------
1 | typedef double real;
2 |
3 | #define DIM 3
4 | typedef real vector[3], matrix[DIM][DIM];
5 |
6 |
7 | void multiply(matrix a, matrix b) {
8 | int i, j;
9 | matrix c;
10 |
11 | for(i=0;i
2 | #include "testharness.h"
3 | double e = __builtin_nanf("")+1.0;
4 | double d = NAN;
5 |
6 | int main(void) {
7 | if (e == e) { E(1); }
8 | if (d == d) { E(2); }
9 |
10 | SUCCESS;
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/noproto.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | // Test the handling of no-prototype functions
4 |
5 | int main() {
6 | int *x, *y;
7 |
8 | int *res = &x; // Make res like x
9 |
10 | res = noprotofun(&x + 1, &y);
11 | // Try to read from x and y
12 | if(res != &x + 1) { E(1); }
13 |
14 | SUCCESS;
15 | }
16 |
--------------------------------------------------------------------------------
/test/small1/noproto1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | // Test the handling of no-prototype functions
4 |
5 | int main() {
6 | int *x, *y;
7 |
8 | int *res = &x; // Make res like x
9 |
10 | // Call with the wrong number of arguments
11 | res = noprotofun(&x);
12 |
13 | SUCCESS;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/noproto2.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | // Test the handling of no-prototype functions
4 |
5 | int main() {
6 | int *x, *y;
7 |
8 | int *res = &x; // Make res like x
9 |
10 | // Call with integers instead of pointers
11 | res = noprotofun(5, 6);
12 |
13 | SUCCESS;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/noreturn.c:
--------------------------------------------------------------------------------
1 | void direct() __attribute__((noreturn));
2 |
3 | // Pointer to function
4 | void (*indirect)() __attribute__((noreturn)) = direct;
5 |
6 | // An array of pointers to functions
7 | void (* afun[2])() __attribute__((noreturn)) = { direct, direct };
8 |
9 | void caller()
10 | {
11 | direct();
12 | indirect();
13 | }
14 |
15 |
16 | int main() {
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/test/small1/offsetof.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "testharness.h"
3 |
4 | typedef struct mystruct {
5 | int a;
6 | int b;
7 | } Mystruct;
8 |
9 | Mystruct Foo;
10 |
11 | int main() {
12 | long addr_b;
13 |
14 | addr_b = (long)&Foo;
15 |
16 | addr_b += (long)offsetof(Mystruct, b);
17 |
18 | if (addr_b != (long)&Foo.b) E(1);
19 |
20 | SUCCESS;
21 | }
22 |
--------------------------------------------------------------------------------
/test/small1/offsetof1.c:
--------------------------------------------------------------------------------
1 |
2 | struct align_short {
3 | char c;
4 | short a;
5 | };
6 |
7 |
8 |
9 | int main()
10 | {
11 | int align_of_short;
12 |
13 | align_of_short =
14 | (((char*)&(((struct align_short *)0)->a)) - ((char*)0)) ;
15 |
16 | return 0 ;
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/test/small1/outofmem.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | struct elim_table
4 | {
5 | int foo;
6 | };
7 |
8 | struct elim_table reg_eliminate[5];
9 |
10 | #define NUM_ELIMINABLE_REGS (sizeof reg_eliminate / sizeof reg_eliminate[0])
11 | static int (*offsets_at)[NUM_ELIMINABLE_REGS];
12 |
13 | void reload2 (void)
14 | {
15 | offsets_at =
16 | (int (*)[NUM_ELIMINABLE_REGS]) alloca (NUM_ELIMINABLE_REGS);
17 | }
18 |
19 |
--------------------------------------------------------------------------------
/test/small1/p04.c:
--------------------------------------------------------------------------------
1 |
2 | void P();
3 | int x1,x2,x3;
4 |
5 | void P() {
6 | if (x1>5) {
7 | x1=x1+x2+1;
8 | x3=x3+1;
9 | P();
10 | x1=x1-x2;
11 | }
12 | }
13 |
14 | void main() {
15 | x2 = x1;
16 | x3=0;
17 | P();
18 | x1=x1-x2-x3;
19 | }
20 |
--------------------------------------------------------------------------------
/test/small1/paper1.c:
--------------------------------------------------------------------------------
1 |
2 | union indir {
3 | int data; // always odd
4 | union indir *next; // always even
5 | };
6 |
7 | union indir *a; // an array
8 |
9 |
10 | int foo() {
11 | int i, acc = 0;
12 | for(i=0;i<100;i++) {
13 | union indir e = a[i];
14 | while(e.data % 2 == 0) e = * e.next;
15 | acc += (e.data >> 1);
16 | }
17 | return acc;
18 | }
19 |
--------------------------------------------------------------------------------
/test/small1/paper2.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int * * a; // an array
4 |
5 |
6 | int foo() {
7 | int i, acc = 0;
8 | for(i=0;i<100; i++) {
9 | int * e = a[i];
10 | while((int)e % 2 == 0) e = * (int * *) e;
11 | acc += ((int)e >> 1);
12 | }
13 | return acc;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/percent400.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main (void) {
4 | char buf[10] = "abc", *str;
5 | sscanf(buf, "%400", str);
6 | return 0;
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/percentm.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | int main(void) {
5 | syslog(LOG_ERR, "%m");
6 | return 0;
7 | }
8 |
--------------------------------------------------------------------------------
/test/small1/perror.c:
--------------------------------------------------------------------------------
1 | void perror_1();
2 |
3 | #include
4 |
5 | void perror_1 (string)
6 | char * string;
7 | {
8 | char *copy = "hello";
9 | perror (copy);
10 | }
11 |
12 | int main(int argc, char ** argv) {
13 | return 0;
14 | }
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/test/small1/perror1.c:
--------------------------------------------------------------------------------
1 | #if defined (HAVE_SOCKETS)
2 | #include
3 | int main() {
4 | printf("how did i get here?");
5 | }
6 |
7 | #else
8 |
9 | void perror_1();
10 |
11 | #include
12 |
13 | void perror_1 (string)
14 | char * string;
15 | {
16 | char *copy = "hello";
17 | perror (copy);
18 | }
19 |
20 | int main(int argc, char ** argv) {
21 | return 0;
22 | }
23 |
24 | #endif
25 |
26 |
27 |
--------------------------------------------------------------------------------
/test/small1/pointers2.c:
--------------------------------------------------------------------------------
1 | int * z1[6] __SIZED;
2 | void foo1(void *y) {
3 | int * * p = & z1[3] ;
4 |
5 | int * * a = p + z1[2][2];
6 | }
7 |
8 | extern void* malloc(unsigned int);
9 |
10 | void foo2() {
11 | int * * p = (int * *)malloc(20);
12 | p ++;
13 | {
14 | int ***q = (int***)p;
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/test/small1/printf2.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | #include
4 |
5 |
6 | int main() {
7 | char buffer[16]; // Plenty of space
8 | double d = 7.75;
9 |
10 | sprintf(buffer, "%5.2f", d); // Make sure we print this as a double
11 |
12 | printf("The buffer is: %s\n", buffer);
13 |
14 | if(buffer[0] != ' ' || buffer[1] != '7' || buffer[2] != '.') E(1);
15 |
16 | SUCCESS;
17 | }
18 |
--------------------------------------------------------------------------------
/test/small1/printf_const.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main() {
4 | char const * p1 = "first string";
5 | const char * p2 = "second string";
6 | const int x = 5;
7 | const int y = 6;
8 | int const * p3 = &x;
9 | const int * p4 = &y;
10 | const double d = 5.5;
11 |
12 | printf("p1 = %s\n",p1);
13 | fprintf(stdout,"p2 = %s\n",p2);
14 | printf("p3 = %p\n",(long)p3);
15 | fprintf(stdout,"p4 = %s\n",(long)p4);
16 | printf("x = %d\n",x);
17 | printf("d = %g\n",d);
18 |
19 | return 0;
20 | }
21 |
--------------------------------------------------------------------------------
/test/small1/proto1.c:
--------------------------------------------------------------------------------
1 |
2 | int foo(); // Forward declaration
3 |
4 | struct bar {
5 | int x, y;
6 | };
7 |
8 | int (*pfoo)() = (int (*)())foo;
9 |
10 | // Now the real declaration
11 | int foo(struct bar *a) {
12 | return a->x + a->y;
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/test/small1/proto2.c:
--------------------------------------------------------------------------------
1 | // From c-torture
2 |
3 | g (); // This line cannot be parsed
4 | // add "int" in front and everythign is Ok
5 |
6 | f ()
7 | {
8 | long ldata[2];
9 | int seed;
10 |
11 | seed = (ldata[0]) + (ldata[1] << 16);
12 | g (seed);
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/pure.c:
--------------------------------------------------------------------------------
1 | int pure[700000 / sizeof (int)] = {0,} ;
2 |
3 | int main() {
4 | char *blah = (char *)pure;
5 | return 0;
6 | }
7 |
8 |
9 |
--------------------------------------------------------------------------------
/test/small1/question.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main() {
4 | const char *string = "hello"; // works if you remove const!
5 | const char *p;
6 | p = string ? string : "NULL";
7 | SUCCESS;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small1/question3.c:
--------------------------------------------------------------------------------
1 | int main() {
2 | int x, y, z;
3 | int keep1 = x ? y : z;
4 | int unfold1 = x ? y : z++;
5 | int unfold2 = x ? y++ : z;
6 | int unfold3 = x ? y++ : z++;
7 | int keep2 = x++ ? y : z;
8 | int unfold4 = x++ ? y : z++;
9 | int unfold5 = x++ ? y++ : z;
10 | int unfold6 = x++ ? y++ : z++;
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/restrict.c:
--------------------------------------------------------------------------------
1 | void vadd (const double * restrict a,
2 | const double * restrict b,
3 | double * restrict c,
4 | int n)
5 | {
6 | int i;
7 | for(i=0;idata[0]);
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/rmUnused-attr.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main()
4 | {
5 | int a;
6 | int b __attribute__((myattribute(a == a)));
7 | b = 5;
8 | // our remove-temps code will remove "a", even though GCC thinks it is
9 | // necessary
10 |
11 | // GN: This is because the "a" in the attribute is not a reference to the
12 | // variable, but just an indentifier !
13 | SUCCESS;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/rmUnused1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int system_utsname;
4 |
5 | struct nlm_rqst {
6 | unsigned int a_flags;
7 | char a_owner[(sizeof(system_utsname)+10) ];
8 | };
9 |
10 |
11 | int main() {
12 |
13 | struct nlm_rqst s;
14 | if(sizeof(s) != sizeof(struct nlm_rqst)) E(1);
15 |
16 | SUCCESS;
17 | }
18 |
--------------------------------------------------------------------------------
/test/small1/scope10.c:
--------------------------------------------------------------------------------
1 | int blah()
2 | {
3 | static float test = 0;
4 | test++;
5 | }
6 |
7 | static int test = 0;
8 |
9 | int main(int argc, char **argv)
10 | {
11 | blah();
12 | test = 1;
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/scope11.c:
--------------------------------------------------------------------------------
1 | int blah()
2 | {
3 | static float test = 0;
4 | test++;
5 | }
6 |
7 | int test = 0;
8 |
9 | int main(int argc, char **argv)
10 | {
11 | blah();
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/scope12.c:
--------------------------------------------------------------------------------
1 | #define WORD int
2 |
3 | static inline char f()
4 | {
5 | typedef int unused_word_type;
6 |
7 | unused_word_type ok;
8 | return 1;
9 | }
10 |
11 | static WORD unused_word_type[1000];
12 |
13 | int main() {
14 | WORD* x = unused_word_type;
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/test/small1/scope2.c:
--------------------------------------------------------------------------------
1 |
2 | // Verify the coping for enum, struct union
3 |
4 | typedef struct str {
5 | int x;
6 | } STR;
7 |
8 | int f1(STR *s1) {
9 | struct str {
10 | int y;
11 | } x;
12 | s1->x = x.y;
13 | }
14 |
15 | typedef struct { int g; } Z;
16 |
17 | struct str glob1;
18 |
19 | int f2() {
20 | struct str {
21 | int a;
22 | };
23 | while(1) {
24 | typedef struct str {
25 | int z;
26 | } Z;
27 |
28 | struct str a;
29 | glob1.x = ((Z*)&glob1)->z;
30 | }
31 | }
32 |
33 |
34 | Z globz;
35 | int * globza = & globz.g;
36 |
--------------------------------------------------------------------------------
/test/small1/scope3.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | struct def *bar(); // Forward declaration
4 |
5 |
6 | typedef int INT;
7 | enum lateenum {
8 | FOO, BAR
9 | };
10 |
11 | typedef struct def {
12 | int f1;
13 | } *defnamed;
14 |
15 | void foo() {
16 | bar(BAR, 5);
17 | }
18 |
19 | defnamed bar(enum lateenum x1, INT x2);
20 |
--------------------------------------------------------------------------------
/test/small1/scope4.c:
--------------------------------------------------------------------------------
1 | /* Generated by Frontc */
2 | #include // malloc
3 |
4 | char * * pm_allocarray(int cols , int rows , int size )
5 | {
6 | char * * its ;
7 | int i ;
8 | its = (char * * )malloc(rows * sizeof(char * ));
9 | its[0] = (char * )malloc(rows * cols * size);
10 | return its;
11 | }
12 |
13 |
14 |
15 | int ppm_parsecolor(char * colorname , int maxval )
16 | {
17 | int hexit[256] , i ;
18 | int p ;
19 | return p;
20 | }
21 |
22 | static char colorname[200] ;
23 |
--------------------------------------------------------------------------------
/test/small1/scope5.c:
--------------------------------------------------------------------------------
1 |
2 | int * external(int *);
3 |
4 |
5 | int foo(int *y) {
6 | int *external(int *z); // We must pull this out
7 | int (* local1)() = 0; // We must leave this here
8 | int (* local2[4])(); // And this one as well
9 |
10 | local2[0] = local1; // Use them somehow
11 |
12 | return * external(y);
13 | }
14 |
15 | int *external(int *x) {
16 | // Do something to prevent this on from being inlined. If it is inlined
17 | // then the STACKPOINTER check will fail
18 | return x + 1;
19 | }
20 |
21 |
22 |
23 | int main(void) {
24 | int x[2];
25 | x[0] = 1;
26 | x[1] = 7;
27 | return !(foo(x) == 7);
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/test/small1/scope6.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | struct foo {
4 | int x;
5 | int y;
6 | } foo;
7 |
8 | int main() {
9 |
10 | typedef struct foo *PFOO;
11 |
12 | PFOO pfoo = &foo;
13 |
14 | struct foo {
15 | int a;
16 | int b;
17 | } anotherfoo;
18 |
19 | int z = pfoo->x + anotherfoo.a; // This means that PFOO refers to the outer type
20 |
21 | SUCCESS;
22 | }
23 |
--------------------------------------------------------------------------------
/test/small1/scope7.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | struct packet {
4 | int (*pfun)(int, char **);
5 | int *p;
6 | };
7 |
8 |
9 | int main(int argc, char **argv) {
10 | struct packet loc = { main, 0 };
11 |
12 | static struct packet glob = { main, 0 };
13 |
14 | if(loc.pfun != glob.pfun) E(1);
15 |
16 | SUCCESS;
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/test/small1/scope8.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 | extern void abort();
3 |
4 | // from c-torture
5 | static inline
6 | p (int *p)
7 | {
8 | return !((long) p & 1);
9 | }
10 |
11 | int
12 | f (int *q)
13 | {
14 | if (p (q) && *q)
15 | return 1;
16 | return 0;
17 | }
18 |
19 | main ()
20 | {
21 | if (f ((int*) 0xffffffff) != 0)
22 | abort ();
23 | exit (0);
24 | }
25 |
--------------------------------------------------------------------------------
/test/small1/scope9.c:
--------------------------------------------------------------------------------
1 | // From c-torture
2 | int v = 3;
3 |
4 | f ()
5 | {
6 | int v = 4;
7 | {
8 | extern int v;
9 | if (v != 3)
10 | abort ();
11 | }
12 | }
13 |
14 | main ()
15 | {
16 | f ();
17 | exit (0);
18 | }
19 |
--------------------------------------------------------------------------------
/test/small1/semicolon.c:
--------------------------------------------------------------------------------
1 |
2 | struct foo {
3 | int g;;;
4 | char *d;
5 | } x;
6 |
7 |
8 | int main() {
9 | x.g = 1;
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/shell-escape.c:
--------------------------------------------------------------------------------
1 | /* STDIO is defined with -D="testharness.h" on command line */
2 | #include TEST
3 | /* STDIO is defined with -D= on command line */
4 | #include STDIO
5 |
6 | int main(void)
7 | {
8 | SUCCESS;
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/simon6.c:
--------------------------------------------------------------------------------
1 |
2 | #define ASZ 10
3 |
4 | extern void printf(char *fmt, ...);
5 | #pragma ccuredvararg("printf", printf(1))
6 | extern void exit(int);
7 |
8 | int argc;
9 |
10 | void main()
11 | {
12 | int n = argc;
13 | int i;
14 | int a[ASZ];
15 | int *p = argc%2 ? 0 : a;
16 |
17 | a[0] = 10;
18 | printf("%d\n", p[0]);
19 | //printf("%d %d\n", p[0], p[1]);
20 |
21 |
22 | for(i=0; i
2 | #include
3 |
4 | int main () {
5 | int i;
6 | char a[]="CCu";
7 | char b[3];
8 |
9 | strcpy (b,a);
10 |
11 | for (i=0; i<4; i++)
12 | printf ("b[%d] = %c (%d)\n", i, b[i], b[i]);
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/strloop.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 | #include
3 |
4 | void BuildWord(char * pchWord) {
5 | int i;
6 | char * pch = pchWord;
7 |
8 | /* original code:
9 | * while ((i = *pch++) != '\0') { }
10 | */
11 |
12 | do {
13 | i = *pch;
14 | // printf("i = '%c'\n",i);
15 | pch++;
16 | } while (i != '\0');
17 |
18 | printf("%s\n",pchWord);
19 | }
20 |
21 | int main() {
22 | char *test = "foo";
23 |
24 | test++;
25 | test--;
26 |
27 | BuildWord(test);
28 |
29 | SUCCESS;
30 | }
31 |
--------------------------------------------------------------------------------
/test/small1/struct1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | typedef struct { unsigned long pte_low; } pte_t;
4 |
5 |
6 | typedef struct { unsigned long pgprot; } pgprot_t;
7 |
8 |
9 | int main() {
10 |
11 | pte_t one, *pte = &one;
12 |
13 | *pte = ((pte_t) { ( (( ( 0 ) >> 12 ) << 12 )
14 | | ((((pgprot_t) { ( 0x001 | 0x004
15 | | 0x020 ) } )).pgprot)) } );
16 | if(pte->pte_low != 0x25) E(1);
17 |
18 | SUCCESS;
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/test/small1/struct_init.c:
--------------------------------------------------------------------------------
1 | #ifndef __FSEQN
2 | #define __FSEQN
3 | #endif
4 |
5 | typedef struct {
6 | char * name;
7 | int data;
8 | } cmd;
9 |
10 | cmd our_cmds[] = {
11 | { "command 1", 1 },
12 | { "command 2", 2 },
13 | { "command 3", 3 },
14 | { 0, 0} };
15 |
16 | struct {
17 | int x;
18 | cmd * cmds;
19 | int y;
20 | } main_struct = {
21 | 100,
22 | our_cmds,
23 | 200
24 | };
25 |
26 | int main() {
27 | char * __FSEQN p = "HELLO";
28 | return 0;
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/test/small1/structassign.c:
--------------------------------------------------------------------------------
1 |
2 | typedef struct {
3 | int *a[20];
4 | int b;
5 | } STR;
6 |
7 | STR glob;
8 |
9 |
10 | int main(STR *s) {
11 | STR loc = glob;
12 |
13 | *s = glob;
14 |
15 | return 0;
16 | }
17 |
18 |
--------------------------------------------------------------------------------
/test/small1/switch_default_parse_bug.c:
--------------------------------------------------------------------------------
1 | void f(int x){
2 | /* This is illegal C syntax (missing ;) */
3 | switch(x){default:};
4 | }
5 |
--------------------------------------------------------------------------------
/test/small1/tags.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | // A few test cases for tags
4 |
5 | typedef struct {
6 | int x;
7 | char *p;
8 | int a[20];
9 | } S1;
10 |
11 | typedef struct {
12 | S1 s1test;
13 | double f1, f2;
14 | } S2;
15 |
16 |
17 | int extint = 5;
18 | S1 exts1 = { 7, 0 };
19 | S2 exts2;
20 |
21 | int *fooptr = 5;
22 |
23 | extern extarr[];
24 | extern struct {
25 | int i1, i2;
26 | int a[4]; // sm: this was a[], but that's an error right??
27 | } extstruct;
28 |
29 |
30 | int foo(int k) {
31 | int t = extint + extarr[5];
32 | S2 locs2;
33 |
34 | * ((int*)& locs2) = 0; // The & counts here
35 |
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/test/small1/tempname.c:
--------------------------------------------------------------------------------
1 | //Test that the variable __cil_tmp7 (which may have come from an earlier pass
2 | //through cil) doesn't conflict with any new vars added by CIL.
3 |
4 | int** foo() { return (int**)0;}
5 |
6 | int main() {
7 | char* __cil_tmp7 = 0;
8 | return (int)foo() + (int)foo() + **foo();
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/testharness.h:
--------------------------------------------------------------------------------
1 | #ifndef printf
2 | /* sm: this works with gcc-2.95 */
3 | extern int printf(const char * format, ...);
4 | # ifdef CCURED
5 | #pragma ccuredvararg("printf", printf(1))
6 | # endif
7 | #else
8 | /* but in gcc-3 headers it's a macro.. */
9 | #include /* printf */
10 | #endif
11 |
12 | extern void exit(int);
13 |
14 | /* Always call E with a non-zero number */
15 | #define E(n) { printf("Error %d\n", (int)n); exit(n); }
16 | #define SUCCESS { printf("Success\n"); exit(0); }
17 |
18 |
--------------------------------------------------------------------------------
/test/small1/unimplemented.c:
--------------------------------------------------------------------------------
1 | #include
2 | struct dirent {
3 | char d_name[256];
4 | };
5 |
6 |
7 | typedef struct isc_direntry {
8 | char name[256 ];
9 | } isc_direntry_t;
10 |
11 | typedef struct isc_dir {
12 | isc_direntry_t entry;
13 | } isc_dir_t;
14 |
15 |
16 | void
17 | isc_dir_init(isc_dir_t *dir) {
18 |
19 | dir->entry.name[0] = '\0';
20 |
21 | }
22 |
23 | unsigned int
24 | isc_dir_read(isc_dir_t *dir) {
25 | struct dirent *entry;
26 |
27 | strcpy(dir->entry.name, entry->d_name);
28 |
29 | return (0);
30 | }
31 |
--------------------------------------------------------------------------------
/test/small1/union1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | typedef struct {
4 | int tag;
5 | union {
6 | char *foo;
7 | struct {
8 | int a1;
9 | int *bar;
10 | } ptr;
11 | } u SAFEUNION ;
12 | } U;
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/test/small1/union6.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | union U
4 | {
5 | int i, j[4];
6 | };
7 |
8 | int main ()
9 | {
10 | union U t = {};
11 | int i;
12 |
13 | for (i = 0; i < 4; ++i)
14 | if (t.j[i] != 0)
15 | E(1);
16 |
17 | SUCCESS;
18 | }
19 |
--------------------------------------------------------------------------------
/test/small1/unsafe1.c:
--------------------------------------------------------------------------------
1 |
2 | #include "testharness.h"
3 |
4 |
5 | typedef struct foo {
6 | struct foo *next;
7 | int *data;
8 | } S;
9 |
10 | typedef struct not_compatible_with_foo {
11 | int xxx;
12 | double *yyy;
13 | } NOT_S;
14 |
15 | S array[2];
16 |
17 | S *fseq;
18 |
19 | int main() {
20 | NOT_S * data;
21 | //fseq = array;
22 | //array[1].next = & array[0];
23 | //fseq ++;
24 |
25 | { __NOCUREBLOCK
26 | data = (NOT_S *) fseq; // We don't want this cast to polute fseq
27 | }
28 |
29 | SUCCESS;
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/test/small1/va_arg_pack.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | extern int myprintf(const char *format, ...);
4 | extern inline int myprintf (const char *format, ...)
5 | {
6 | int r = printf ("myprintf: ");
7 | if (r < 0)
8 | return r;
9 | int s = printf (format, __builtin_va_arg_pack ());
10 | if (s < 0)
11 | return s;
12 | return r + s;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/var.c:
--------------------------------------------------------------------------------
1 | int v2;
2 |
3 | F1()
4 | {
5 | int v1,v2;
6 | F2(v1);
7 | F2(v2);
8 | }
9 |
10 | int v1;
11 |
12 | F2(int a) {
13 | v1=0;
14 | v2=0;
15 | }
16 |
--------------------------------------------------------------------------------
/test/small1/var_named_hidden.c:
--------------------------------------------------------------------------------
1 | __attribute__((visibility("hidden"))) int x;
2 | int main()
3 | {
4 | int hidden;
5 | hidden = 0;
6 |
7 | return 0;
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/test/small1/vararg5.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/goblint/cil/faeb7be1c0f875e22f77151a0765fdcfe4dad58d/test/small1/vararg5.h
--------------------------------------------------------------------------------
/test/small1/void.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | void f(int x, int y) {
5 | printf("wow\n");
6 | }
7 |
8 | void g(int x, int y) {
9 | printf("yippie!\n");
10 | }
11 |
12 | #define FUNC(x, y) ({ f((x), (y)); g((x), (y)); })
13 |
14 | #define NUMBER 1
15 |
16 | int k(int a) {
17 |
18 | int x, y, z;
19 | z = 0;
20 | FUNC(NUMBER, z);
21 | return 1;
22 | }
23 |
24 | int main(int argc, char** argv) {
25 | k(5);
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/test/small1/voidarg.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int main(int argc, char** argv) {
4 |
5 | int (* badfunc) ();
6 |
7 | badfunc = puts;
8 |
9 | (*badfunc)("hello, nice to meet you.");
10 |
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small1/voidstar.c:
--------------------------------------------------------------------------------
1 | extern void* malloc(unsigned int);
2 |
3 | typedef struct list {
4 | void* data;
5 | struct list * next;
6 | } LIST;
7 |
8 |
9 | extern void* listfind(LIST *l, int nth);
10 | extern void* listinsert(LIST **, int nth, void *elem);
11 |
12 | int listadd(LIST * * pl, void* elem) {
13 | LIST *n = (LIST*)malloc(sizeof(LIST));
14 | n->data = elem;
15 | n->next = *pl;
16 | return pl;
17 | }
18 |
19 | LIST * glob = 0;
20 |
21 | int add5(LIST *cell) {
22 | cell->data = (void*)cell;
23 | listadd(& glob, (void*)add5);
24 |
25 | }
26 |
27 |
28 | int get1(void) {
29 | LIST *l = (LIST*)listfind(glob, 5);
30 | }
31 |
--------------------------------------------------------------------------------
/test/small1/voidtypedef.c:
--------------------------------------------------------------------------------
1 | //test for using a typedef as void.
2 | typedef void tVoid;
3 |
4 | void pimInit(void);
5 |
6 | tVoid pimInit(tVoid)
7 | {
8 | return;
9 | }
10 |
11 | int main() {
12 | pimInit();
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small1/warnings-cast.c:
--------------------------------------------------------------------------------
1 | const int a = 3;
2 |
3 | const int *f() {
4 | return &a;
5 | }
6 |
7 | int main() {
8 | // Make sure we keep the cast from "const int*" to "int*"
9 | // If it's dropped, gcc emits a warning.
10 | int *p = (int*) f();
11 | *p = 4;
12 | return *p;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small1/warnings-noreturn.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 |
4 | void croak() __attribute__((noreturn));
5 | void die() __attribute__((noreturn));
6 |
7 |
8 | void terminate(int) __attribute__((noreturn));
9 |
10 | void terminate(int frog)
11 | {
12 | if (frog)
13 | croak();
14 | else
15 | die();
16 | }
17 |
18 |
19 | int main()
20 | {
21 | SUCCESS;
22 | }
23 |
--------------------------------------------------------------------------------
/test/small1/warnings-unused-label.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 |
4 | /* What's going wrong here? CIL's printing routines try to eliminate
5 | some trivial gotos. In this test program, the "goto successor"
6 | statement is useless and therefore doesn't get printed out.
7 | However, the "successor:" label is left behind. This yields a
8 | warning about a label being defined but not used. */
9 |
10 |
11 | int branch(int selector)
12 | {
13 | if (selector)
14 | return 1;
15 | else
16 | goto successor;
17 |
18 | successor:
19 | return 0;
20 | }
21 |
22 |
23 | int main()
24 | {
25 | branch(0);
26 | SUCCESS;
27 | }
28 |
--------------------------------------------------------------------------------
/test/small1/wchar1.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 | #include
3 |
4 | int main() {
5 | wchar_t *wbase = L"Hello" L", world";
6 | char * w = (char *)wbase;
7 | char * s = "Hello" ", world";
8 | int i;
9 |
10 | // See if this is little or big endian
11 | short foo = 0x0011;
12 | char little_endian = (int) * (char*)&foo;
13 |
14 | for (i=0; i < 10; i++) {
15 | if (w[i * sizeof(wchar_t)] != (little_endian ? s[i] : 0)) {
16 | E(1);
17 | }
18 | if (w[i * sizeof(wchar_t) + (sizeof(wchar_t)-1)]
19 | != (little_endian ? 0 : s[i])) {
20 | E(2);
21 | }
22 | }
23 | SUCCESS;
24 | }
25 |
--------------------------------------------------------------------------------
/test/small1/wchar2.c:
--------------------------------------------------------------------------------
1 | #include "testharness.h"
2 |
3 | int main() {
4 | long w = L'W'; // wide character constant
5 | char * s = "W";
6 | int i;
7 |
8 | if (w != s[0]) { E(1); }
9 | SUCCESS;
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/test/small1/wchar5.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "testharness.h"
3 |
4 | //matth: some lexer bugs that I haven't had time to fix
5 |
6 |
7 | int main(){
8 | //BUG: the "i\xabcd" has no L in front, so we treat it like a normal string,
9 | // and can't handle the big value.
10 |
11 | wchar_t a[] = L"H" "i\xabcd";
12 | // should be the same as:
13 | wchar_t b[] = L"Hi\xabcd";
14 |
15 |
16 | int i;
17 | for (i = 0; i < 4; i++){
18 | if (a[i] != b[i]) E(i);
19 | }
20 |
21 | SUCCESS;
22 | }
23 |
--------------------------------------------------------------------------------
/test/small1/wchar7.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include "testharness.h"
3 |
4 | int main()
5 | {
6 | wchar_t aa[] = L"\""; // 1 wide char
7 | wchar_t *ap = L"\"";
8 | char *p1, *p2;
9 | int i;
10 |
11 | if (wcslen(aa) != wcslen(ap)) { E(1); }
12 | p1 = aa;
13 | p2 = ap;
14 | for (i=0; i<2 * sizeof(wchar_t); i++) {
15 | if (p1[i] != p2[i]) { E(2); }
16 | }
17 | if (wcscmp(aa,ap) != 0) { E(3); }
18 |
19 | SUCCESS;
20 | }
21 |
--------------------------------------------------------------------------------
/test/small1/wrongnumargs.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | void f(s1, s2) char *s1, *s2;
4 | {
5 | printf(s1, s2);
6 | }
7 |
8 | int main(int argc, char** argv) {
9 | f("hello %S!\n", "wow");
10 | f("hello there: %s!\n", "wow");
11 | f("hello again!\n");
12 | return 0;
13 | }
14 |
15 |
--------------------------------------------------------------------------------
/test/small1/zerotags.c:
--------------------------------------------------------------------------------
1 | typedef struct {
2 | int *foo;
3 | int bar;
4 | } wildstruct;
5 |
6 | int makewild(void *x) {
7 | return *((int *)x);
8 | }
9 |
10 | int main() {
11 | wildstruct w;
12 | int p = 55, q;
13 | int *ptr;
14 |
15 | makewild(&w);
16 |
17 | w.foo = &p;
18 | w.foo = 0;
19 |
20 | ptr = w.foo;
21 |
22 | q = *ptr;
23 |
24 | return q;
25 | }
26 |
--------------------------------------------------------------------------------
/test/small2/Makefile:
--------------------------------------------------------------------------------
1 | # Makefile in small2
2 |
3 | clean:
4 | rm -f *.o *_all.c *cil.c *box.c *_ppp.c *.i *.origi *infer.c *cabs.c
5 | rm -f comb enuminit multiplestatics staticafternostorage
6 | rm -f hola partialbracket ptrtolocal rmunused recursetype
7 | rm -f regbeforeassign simplewild tprintf voidfree
8 | rm -f *.exe *.obj *.pdb *.ilk
9 | rm -f __scalar2pointer.txt ocamlprof.dump "#"*
10 | rm -f *cured.c *.optim.c *_comb.c
11 | rm -rf *.browser
12 |
--------------------------------------------------------------------------------
/test/small2/align.c:
--------------------------------------------------------------------------------
1 |
2 | typedef struct {
3 | volatile unsigned int lock;
4 | } spinlock_t;
5 |
6 | typedef struct {
7 | } __attribute__((__aligned__((1 << ((5) ) ) ))) irq_desc_t;
8 | extern irq_desc_t irq_desc [224 ];
9 |
10 |
11 |
12 | int main () {
13 | return 0;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small2/arrayinit.c:
--------------------------------------------------------------------------------
1 | // arrayinit.c
2 | // char array with initializer exactly filling it, not including NUL
3 | // from sac at stevechamberlain dot com
4 |
5 | #include // assert
6 |
7 | char a[5]="12345"; // CIL prior to 8/01/03 16:17 yielded a warning
8 | char b[5]="1234"; // 5th char is a NUL
9 | char c[]="12345"; // 6th char is a NUL
10 | char d[5]="123"; // 4th, 5th char are NULs
11 | //char e[5]="123456"; // too big! (yields a warning)
12 |
13 | int main()
14 | {
15 | assert(sizeof(a) / sizeof(a[0]) == 5);
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/test/small2/asmfndecl.c:
--------------------------------------------------------------------------------
1 | typedef void (*__sighandler_t) (int) ;
2 |
3 | extern __sighandler_t
4 | mysignal(int __sig, __sighandler_t __handler)
5 | __asm__ ( "" "__sysv_signal" ) ;
6 |
7 | int main()
8 | {
9 | // make some use of the signal function so that we don't drop it
10 | mysignal(5, (__sighandler_t)0);
11 | return 0;
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/test/small2/attrib.c:
--------------------------------------------------------------------------------
1 | struct mpc_config_bus
2 | {
3 | unsigned char mpc_bustype[6] __attribute((packed));
4 | };
5 |
6 | int main () {
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small2/badasm.c:
--------------------------------------------------------------------------------
1 | extern inline void __set_64bit (unsigned long long * ptr,
2 | unsigned int low, unsigned int high)
3 | {
4 | __asm__ __volatile__ (
5 | "\n1:\t"
6 | "movl (%0), %%eax\n\t"
7 | "movl 4(%0), %%edx\n\t"
8 | "cmpxchg8b (%0)\n\t"
9 | "jnz 1b"
10 | :
11 | : "D"(ptr),
12 | "b"(low),
13 | "c"(high)
14 | : "ax","dx","memory");
15 | }
16 |
--------------------------------------------------------------------------------
/test/small2/baddef1.c:
--------------------------------------------------------------------------------
1 | // baddef1.c: complain about inconsistent redef
2 |
3 | struct S {
4 | int x;
5 | int y;
6 | };
7 |
8 | int size1() { return sizeof(struct S); }
9 |
--------------------------------------------------------------------------------
/test/small2/baddef2.c:
--------------------------------------------------------------------------------
1 | // baddef2.c: other def'n
2 |
3 | #include
4 |
5 | struct S {
6 | int x;
7 | int y;
8 | int z; // third field!
9 | };
10 |
11 | int size2() { return sizeof(struct S); }
12 | int size1(); // from baddef1
13 |
14 | int main()
15 | {
16 | int s1, s2;
17 |
18 | printf("size1: %d\n", s1=size1());
19 | printf("size2: %d\n", s2=size2());
20 | printf("(correct output is 8, then 12)\n");
21 |
22 | if (s1==8 && s2==12) {
23 | return 0;
24 | }
25 | else {
26 | return 2;
27 | }
28 | }
29 |
30 |
31 |
--------------------------------------------------------------------------------
/test/small2/bisonerror.c:
--------------------------------------------------------------------------------
1 | /* Generated by Frontc */
2 |
3 | typedef struct core {
4 | int somefield;
5 | } core ;
6 |
7 | void closure(short * core , int n )
8 | {
9 | short * csend ;
10 | csend = core + n;
11 | }
12 |
13 | int main () {
14 | core x;
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/test/small2/bogus_redef.c:
--------------------------------------------------------------------------------
1 | // provoke bogus "redefinition" message
2 |
3 | //This will not compile on gcc 4.0 or later, but CIL handles it.
4 |
5 | int foo()
6 | {
7 | // call before decl
8 | return bar();
9 | }
10 |
11 | // now define statically
12 | static // comment me out to make problem disappear
13 | int bar()
14 | {
15 | return 4;
16 | }
17 |
18 | int main()
19 | {
20 | return foo() - 4;
21 | }
22 |
--------------------------------------------------------------------------------
/test/small2/bzero.c:
--------------------------------------------------------------------------------
1 | // bzero.c
2 | // we call bzero w/o any complaint?
3 |
4 | //#include // bzero
5 |
6 | char buf[80];
7 |
8 | int main()
9 | {
10 | bzero(buf, (void*)80); // this is how anagram does it
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small2/checkstore2.c:
--------------------------------------------------------------------------------
1 |
2 | int *globptr;
3 |
4 | int global;
5 |
6 | int foo() {
7 | int local;
8 | int *s = &local; s += (&global - s); // s == &global but with the home of the local
9 | globptr = s; // Store away the pointer. Succeeds because s's value is not on the stack
10 | return (int)&local; // We'll need this later
11 | }
12 |
13 | int main() {
14 | int localaddr = foo();
15 | globptr += (localaddr - (int)globptr);// glob == &local with the home of the &local
16 | return *globptr; // We are reading from a dead stack frame
17 | }
18 |
--------------------------------------------------------------------------------
/test/small2/checkstore3.c:
--------------------------------------------------------------------------------
1 | // Makes sure that pointers within structures are checked.
2 | // NUMERRORS 1
3 |
4 | struct foo
5 | {
6 | char * __FSEQ p;
7 | };
8 |
9 | int
10 | bar(struct foo *fp)
11 | {
12 | struct foo f;
13 | char buf[10];
14 | f.p = buf;
15 | *fp = f; // ERROR(1):Storing stack address
16 | return 0;
17 | }
18 |
19 | int
20 | main(void)
21 | {
22 | struct foo f;
23 | return bar(&f);
24 | }
25 |
--------------------------------------------------------------------------------
/test/small2/comb1.c:
--------------------------------------------------------------------------------
1 | // comb1.c
2 | // part 1/4 of a program expected to be combined
3 |
4 | #ifndef __HEAPIFY
5 | #define __HEAPIFY
6 | #endif
7 |
8 | int global_com4; //even without an extern decl, this should link to comb4's
9 | //global var, which is initialized to 5.
10 |
11 | int *globalPtr;
12 |
13 | void hpfy()
14 | {
15 | int local __HEAPIFY;
16 | globalPtr = &local;
17 | }
18 |
19 | int foo_com1(int x)
20 | {
21 | return x + global_com4;
22 | }
23 |
24 |
--------------------------------------------------------------------------------
/test/small2/comb2.c:
--------------------------------------------------------------------------------
1 | // comb2.c
2 | // part 2/4 of a program expected to be combined
3 |
4 | #include "../small1/testharness.h"
5 |
6 | static int global_com2 = 5;
7 |
8 | int foo2_com2(int x)
9 | {
10 | return x + global_com2;
11 | }
12 |
13 | extern int foo_com3(int x);
14 | extern void hpfy();
15 |
16 | int main()
17 | {
18 | int res1 = foo_com3(6);
19 | int res2 = foo2_com4(61);
20 | printf("foo_com3(6): %d\n", res1);
21 | printf("foo2_com4(61): %d\n", res2);
22 | if (res1 != (11+sizeof(int*))) E(1);
23 | if (res2 != 70) E(2);
24 | hpfy();
25 | return 0;
26 | }
27 |
--------------------------------------------------------------------------------
/test/small2/comb3.c:
--------------------------------------------------------------------------------
1 | // comb3.c
2 | // part 3/4 of a program expected to be combined
3 |
4 | static double global_com2 = 1.0;
5 | extern int foo_com1(int x);
6 |
7 | int foo_com3(int x)
8 | {
9 | return foo_com1(x) + sizeof(int*);
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/test/small2/comb4.c:
--------------------------------------------------------------------------------
1 | // comb4.c
2 | // part 4/4 of a program expected to be combined
3 |
4 | int global_com4 = 5;
5 | int foo2_com2(int x);
6 |
7 | int foo2_com4(int x)
8 | {
9 | return foo2_com2(x) +4;
10 | }
11 |
12 |
--------------------------------------------------------------------------------
/test/small2/constdecl.c:
--------------------------------------------------------------------------------
1 | // tricky const decl
2 |
3 | #include // strlen
4 |
5 | // first declare the fn
6 | static int foo(char const *a, char const *b);
7 |
8 | // now define it using old-style args
9 | static int foo(a, b)
10 | #if 0
11 | char const *a, *b; // looks like we're not associating 'const' with 'b'?
12 | #else
13 | char const *a; // actually, this fails too..
14 | char const *b;
15 | #endif
16 | {
17 | return strlen(a) + strlen(b);
18 | }
19 |
20 | int main()
21 | {
22 | return foo("aa", "bbb") - 5;
23 | }
24 |
--------------------------------------------------------------------------------
/test/small2/constfold.c:
--------------------------------------------------------------------------------
1 | // constfold.c
2 | // problem with ijpeg and power constant folding
3 |
4 | double sqrt(double x)
5 | {
6 | return x*x; // close enough for parsing testing
7 | }
8 |
9 | int main()
10 | {
11 | {
12 | float z10, z5, tmp12;
13 | tmp12 = (float )(- 2.613125930) * z10 + z5; // ijpeg
14 | }
15 |
16 | {
17 | double a,b,c,root;
18 | root = (-b-sqrt(b*b-4*a*c))/(2*a); // power
19 | }
20 |
21 | return 0;
22 | }
23 |
--------------------------------------------------------------------------------
/test/small2/constfold2.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | enum foo {
4 | e0 = sizeof(int),
5 | e1,
6 | e2 = e0 + 1
7 | };
8 |
9 | int useenum(enum foo x) {
10 | switch(x) {
11 | case e1: return 0;
12 | case e2 * 2: return 1;
13 | case sizeof(int): return 2;
14 |
15 | }
16 | }
17 |
18 | TESTDEF "enum1" : success ~ case +sizeof *\( *int *\)
19 | TESTDEF "enum2" : success ~ e2 *\* *2
20 | TESTDEF "enum3" : success ~ e0 *\+ *1
21 | int main() {
22 | return 0;
23 | }
24 |
--------------------------------------------------------------------------------
/test/small2/ctype.c:
--------------------------------------------------------------------------------
1 | // test ctype functions
2 |
3 | #include // various
4 | #include // printf
5 |
6 | void analyze(int ch)
7 | {
8 | printf("character: %c\n", ch);
9 | printf(" decimal: %d\n", ch);
10 | printf(" isalpha: %d\n", !!isalpha(ch));
11 | printf(" isdigit: %d\n", !!isdigit(ch));
12 | }
13 |
14 | int main()
15 | {
16 | analyze('a');
17 | analyze('5');
18 | analyze('$');
19 | analyze('Z');
20 | return 0;
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/test/small2/enumattr.c:
--------------------------------------------------------------------------------
1 | // enumattr.c
2 | // enums with attributes
3 |
4 | typedef enum {
5 | x = 256
6 | } __attribute__((__packed__)) large_enum;
7 |
8 | large_enum enum_l = x;
9 |
10 | int main()
11 | {
12 | return 0;
13 | }
14 |
--------------------------------------------------------------------------------
/test/small2/enuminit.c:
--------------------------------------------------------------------------------
1 | // enums where one tag is init'd with another
2 |
3 | int printf(char const *fmt, ...);
4 |
5 | // this was messing up the parser
6 | enum __rlimit_resource {
7 | _RLIMIT_CPU = 0,
8 | RLIMIT_CPU = _RLIMIT_CPU,
9 | _RLIMIT_FSIZE = 1,
10 | RLIMIT_FSIZE = _RLIMIT_FSIZE,
11 | _RLIMIT_DATA = 2,
12 | RLIMIT_DATA = _RLIMIT_DATA,
13 | };
14 |
15 | #define PVAL(val) printf(#val " = %d\n", val)
16 |
17 | int main()
18 | {
19 | printf("whazzup?!\n");
20 | PVAL(_RLIMIT_CPU);
21 | PVAL(RLIMIT_CPU);
22 | PVAL(_RLIMIT_FSIZE);
23 | PVAL(RLIMIT_FSIZE);
24 | PVAL(_RLIMIT_DATA);
25 | PVAL(RLIMIT_DATA);
26 | return 0;
27 | }
28 |
--------------------------------------------------------------------------------
/test/small2/enuminit2.c:
--------------------------------------------------------------------------------
1 | // enuminit2.c
2 | // from sac at stevechamberlain dot com
3 |
4 | // some weird expression kinds for enums
5 |
6 | // NUMERRORS 1
7 |
8 | // should fail
9 | enum {x = 3.0 }; // ERROR(1)
10 |
11 | // should pass
12 | struct a { int j:' ';} p;
13 |
14 |
15 | int main()
16 | {
17 | return 0;
18 | }
19 |
--------------------------------------------------------------------------------
/test/small2/errorinfn.c:
--------------------------------------------------------------------------------
1 |
2 | int main () {
3 | char c[8] = "an error!";
4 | return c[0] - 'a' + c[7] - 'r';
5 | }
6 |
--------------------------------------------------------------------------------
/test/small2/fmtstr.c:
--------------------------------------------------------------------------------
1 | // fmtstr.c
2 | // demonstrate a format-string bug
3 |
4 | #include
5 |
6 | int main()
7 | {
8 | char *s = "%d -- bad!\n";
9 | printf(s);
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/test/small2/funcname.c:
--------------------------------------------------------------------------------
1 | extern void exit(int);
2 | extern int strcmp(const char*, const char*);
3 | extern int printf(const char*, ...);
4 |
5 | //Note that the concatenation in the strcmp arguments doesn't work on gcc4.
6 | //Maybe __FUNCTION__ is no longer considered a literal??
7 |
8 | int main(void) {
9 |
10 | printf("__FUNCTION__ = %s\n", __FUNCTION__);
11 | printf("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
12 |
13 | if(strcmp("This is " __FUNCTION__, "This is main") ||
14 | strcmp("This is " __PRETTY_FUNCTION__, "This is main")) {
15 | exit(1);
16 | }
17 | exit(0);
18 | }
19 |
--------------------------------------------------------------------------------
/test/small2/funptr1.c:
--------------------------------------------------------------------------------
1 | /* This exhibits a bug with the types of tagged functions whose arguments
2 | * appear tagged */
3 | int foo(int x);
4 |
5 | struct S {
6 | void (*fptr)();
7 | } g = { &foo };
8 |
9 | int main() {
10 | // Make g (and thus foo) TAGGED
11 | int *pg = (int*)&g;
12 | }
13 |
14 | int foo(int arg) {
15 | // Now take the address of x and make it tagged
16 | int **px = &arg;
17 | return arg;
18 | }
19 |
--------------------------------------------------------------------------------
/test/small2/gimpdouble.c:
--------------------------------------------------------------------------------
1 | // gimpdouble.c
2 | // examples of gimp's usage of doubles and enums
3 |
4 | typedef enum {
5 | ZERO,
6 | ONE
7 | } Something;
8 |
9 | int main()
10 | {
11 | double d;
12 | Something s;
13 |
14 | d = ZERO;
15 | s = d;
16 |
17 | return s;
18 | }
19 |
20 |
--------------------------------------------------------------------------------
/test/small2/globalprob.c:
--------------------------------------------------------------------------------
1 |
2 | typedef struct {
3 | volatile unsigned int lock;
4 | } spinlock_t;
5 |
6 | spinlock_t runqueue_lock __attribute__((__aligned__(32 ),
7 | __section__(".data.cacheline_aligned"))) = (spinlock_t) { 1 } ;
8 |
9 |
10 | int main () {
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small2/globtable.c:
--------------------------------------------------------------------------------
1 | // a global table
2 |
3 | int nums[] = { 1,2,3 };
4 |
5 | struct Foo {
6 | int a,b;
7 | };
8 | struct Foo foos[] = { {4,5}, {6,7} };
9 |
10 | int main()
11 | {
12 | return nums[1] - 2 +
13 | foos[0].b - 5;
14 | }
15 |
--------------------------------------------------------------------------------
/test/small2/handler1.handlers:
--------------------------------------------------------------------------------
1 |
2 |
3 | ignore UBOUND
4 | stop * at handler1.c:10 : main()
5 |
6 | ignore LBOUND at *:20
7 |
--------------------------------------------------------------------------------
/test/small2/initedextern.c:
--------------------------------------------------------------------------------
1 | // initedextern.c
2 | // from sac at stevechamberlain dot com
3 |
4 | // claim is that this is common enough that we should support it
5 |
6 | extern int foo = 3;
7 |
8 | int main()
9 | {
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/test/small2/invalredef.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | extern int wchgat(const void *);
4 |
5 | int wchgat(const void *opts __attribute__((unused)) )
6 | {
7 | return 1;
8 | }
9 |
10 | int main () {
11 | return 0;
12 | }
13 |
--------------------------------------------------------------------------------
/test/small2/invalredef2.c:
--------------------------------------------------------------------------------
1 |
2 | enum token {
3 | TERM = - 1
4 | } ; /*onlytypedef*/
5 |
6 |
7 | static int parse(int * ) ;
8 |
9 | static int parse(enum token * tok )
10 | {
11 | return 0;
12 | }
13 |
14 | int main () {
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/test/small2/kernel1.c:
--------------------------------------------------------------------------------
1 | // This test is nonsense: DECLARE_WAIT_QUEUE_HEAD is a macro in Linux kernel
2 | DECLARE_WAIT_QUEUE_HEAD(log_wait);
3 |
4 |
5 |
6 | int main () {
7 | return 0;
8 | }
9 |
10 |
11 |
--------------------------------------------------------------------------------
/test/small2/kernel2.c:
--------------------------------------------------------------------------------
1 | struct module
2 | {
3 | unsigned long size_of_struct;
4 | const char *name;
5 | };
6 |
7 |
8 | static struct module kernel_module =
9 | {
10 | size_of_struct: sizeof(struct module),
11 | name: "",
12 | };
13 |
14 | int main () {
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/test/small2/litstruct.c:
--------------------------------------------------------------------------------
1 | extern void exit(int);
2 |
3 | struct Foo {
4 | int a;
5 | int b;
6 | } structure;
7 |
8 | int main()
9 | {
10 | char **foo;
11 |
12 | structure = ((struct Foo) {3, 4});
13 | if(structure.a + structure.b != 7) exit(1);
14 |
15 |
16 | foo = (char *[]) { "x", "y", "z"};
17 | if(* foo[1] != 'y') exit(2);
18 |
19 |
20 | if( ((int[]) { 1, 2, 3})[1] != 2) exit(3);
21 |
22 | exit(0);
23 | }
24 |
25 |
--------------------------------------------------------------------------------
/test/small2/main.c:
--------------------------------------------------------------------------------
1 |
2 | #pragma pack(1)
3 |
4 | #pragma pack()
5 |
6 | struct udf_sb_info
7 | {
8 | struct buffer_head *s_block_bitmap[8 ];
9 |
10 | struct inode *s_vat;
11 | };
12 |
13 | int main () {
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/test/small2/memset_sizeof.c:
--------------------------------------------------------------------------------
1 | // boxing sizeof?
2 |
3 | #include // printf
4 | #include // memset
5 |
6 | struct S {
7 | int *x;
8 | };
9 |
10 | int main()
11 | {
12 | //printf("sizeof is %d\n", sizeof(struct S));
13 | memset(NULL, 0, sizeof(struct S));
14 | //return sizeof(struct S);
15 | return 0;
16 | }
17 |
--------------------------------------------------------------------------------
/test/small2/merge-ar.c:
--------------------------------------------------------------------------------
1 |
2 | //There's a problem with the merger when a parameter overlaps with a static local.
3 |
4 |
5 | int fun1(int n)
6 | {
7 | return n;
8 | }
9 |
10 | int qux()
11 | {
12 | static int n = 3;
13 | return n;
14 | }
15 |
16 | int fun2()
17 | {
18 | int n; //This local doesn't seem to cause any problems.
19 | return n;
20 | }
21 |
22 |
23 |
24 | int main() {
25 | return 0;
26 | }
27 |
--------------------------------------------------------------------------------
/test/small2/merge-twice-1.c:
--------------------------------------------------------------------------------
1 | // merge-twice: testcase of merging merged results
2 |
3 | int foo()
4 | {
5 | return 3;
6 | }
7 |
--------------------------------------------------------------------------------
/test/small2/merge-twice-2.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int bar()
4 | {
5 | return 4;
6 | }
7 |
--------------------------------------------------------------------------------
/test/small2/merge-twice-3.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int baz()
4 | {
5 | return 7;
6 | }
7 |
--------------------------------------------------------------------------------
/test/small2/mergeinit1.c:
--------------------------------------------------------------------------------
1 |
2 | int f1(void)
3 | {
4 | return(1);
5 | }
6 |
7 |
8 |
--------------------------------------------------------------------------------
/test/small2/mergeinit1.h:
--------------------------------------------------------------------------------
1 |
2 | extern int f1(void);
3 |
--------------------------------------------------------------------------------
/test/small2/mergeinit2.h:
--------------------------------------------------------------------------------
1 |
2 | extern int (*table[2])();
3 |
--------------------------------------------------------------------------------
/test/small2/mergeinit2_1_reftable.c:
--------------------------------------------------------------------------------
1 | #include "mergeinit2.h"
2 |
3 |
--------------------------------------------------------------------------------
/test/small2/mergeinit2_2_definition.c:
--------------------------------------------------------------------------------
1 | #include "mergeinit1.h"
2 | #include "mergeinit2.h"
3 | #include "mergeinit3.h"
4 |
5 |
6 | int (*table[2])(void) =
7 | {
8 | &f1,
9 | &f3
10 | };
11 |
--------------------------------------------------------------------------------
/test/small2/mergeinit3.c:
--------------------------------------------------------------------------------
1 |
2 | int f3(void)
3 | {
4 | return(3);
5 | }
6 |
7 |
8 |
--------------------------------------------------------------------------------
/test/small2/mergeinit3.h:
--------------------------------------------------------------------------------
1 |
2 | extern int f3(void);
3 |
--------------------------------------------------------------------------------
/test/small2/mergeinit4.c:
--------------------------------------------------------------------------------
1 | #include "mergeinit2.h"
2 |
3 | int main(){
4 | return(table[0]());
5 | }
6 |
--------------------------------------------------------------------------------
/test/small2/mergeinline1.c:
--------------------------------------------------------------------------------
1 | // mergeinline1.c
2 | // hypothesis about fill_n_... problem
3 |
4 | // prototype
5 | static long *fill();
6 |
7 | // call
8 | int foo()
9 | {
10 | long *w = fill();
11 | return (int)(*w);
12 | }
13 |
14 | // inline definition
15 | // (remove "__inline" to work around the bug)
16 | __inline static long *fill()
17 | {
18 | return 0;
19 | }
20 |
21 | int main()
22 | {
23 | return 0;
24 | }
25 |
--------------------------------------------------------------------------------
/test/small2/mergeinline2.c:
--------------------------------------------------------------------------------
1 | // mergeinline2.c
2 | // counterpart to mergeinline1.c
3 |
4 | // prototype
5 | static long *fill();
6 |
7 | // call
8 | int bar()
9 | {
10 | long *w = fill();
11 | return (int)(*w);
12 | }
13 |
14 | // inline definition
15 | // (remove "__inline" to work around the bug)
16 | __inline static long *fill()
17 | {
18 | return 0;
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/test/small2/mergestruct1.c:
--------------------------------------------------------------------------------
1 | // mergestruct1.c
2 | // test merging of structures whose field names differ
3 |
4 | struct A {
5 | int x;
6 | };
7 |
8 | // make A's type part of the interface
9 | extern struct A *connection;
10 |
11 | // decl of foo()
12 | int foo();
13 |
14 | // refer to A::x
15 | int foo()
16 | {
17 | if (connection) {
18 | return connection->x;
19 | }
20 | else {
21 | return 3;
22 | }
23 | }
24 |
25 | // unrelated: test merging of 'unsigned char' and 'signed char'
26 | unsigned char sharedChar;
27 |
--------------------------------------------------------------------------------
/test/small2/mergestruct2.c:
--------------------------------------------------------------------------------
1 | // mergestruct2.c
2 | // other half of mergestruct1.c
3 |
4 | struct B {
5 | int y;
6 | };
7 |
8 | // connect A and B
9 | struct B *connection;
10 |
11 | // refer to B::y
12 | int main()
13 | {
14 | int whatever;
15 |
16 | if (connection) {
17 | whatever = connection->y;
18 | }
19 | whatever += foo(); // for the heck of it
20 |
21 | return whatever-whatever;
22 | }
23 |
24 | // unrelated: test merging of 'unsigned char' and 'signed char'
25 | // (I edit this to introduce inconsistency..)
26 | unsigned char sharedChar;
27 |
--------------------------------------------------------------------------------
/test/small2/metabug3.c:
--------------------------------------------------------------------------------
1 | #include "../small1/testharness.h"
2 | #include "../small1/testkinds.h"
3 |
4 | #ifndef ERROR
5 | #define __WILD
6 | #endif
7 |
8 | // NUMERRORS 1
9 | typedef struct foo Foo;
10 | struct bar
11 | {
12 | Foo * __WILD next;
13 | };
14 | struct foo
15 | {
16 | int *base;
17 | unsigned int length;
18 | struct bar link;
19 | };
20 | int main()
21 | {
22 | struct foo s, *sptr = &s;
23 | if(HAS_KIND(sptr->base, WILD_KIND)) E(1); //ERROR(1):Error 1
24 | }
25 |
--------------------------------------------------------------------------------
/test/small2/multiplestatics.c:
--------------------------------------------------------------------------------
1 | // two static variables with the same name
2 |
3 | int foo()
4 | {
5 | static int x = 0;
6 | return x;
7 | }
8 |
9 | int bar()
10 | {
11 | static int x = 5;
12 | return x;
13 | }
14 |
15 | int main()
16 | {
17 | return !( foo() + bar() == 5 );
18 | return 0;
19 | }
20 |
21 |
--------------------------------------------------------------------------------
/test/small2/neg64.c:
--------------------------------------------------------------------------------
1 | // neg64.c
2 | // testcase for -2^63 problem
3 | // from sac at stevechamberlain dot com
4 |
5 | float
6 | sll2f(s)
7 | long long int s;
8 | {
9 | return s;
10 | }
11 |
12 | main()
13 | {
14 | if (sll2f((long long int)(~((~0ULL) >> 1))) != (float)(long long int)~((~0ULL) >> 1)) /* 0x80000000 */
15 | abort();
16 |
17 | exit(0);
18 | }
19 |
--------------------------------------------------------------------------------
/test/small2/nested.c:
--------------------------------------------------------------------------------
1 | // example of a situation where nested areas are registered
2 |
3 | #include // printf
4 |
5 | struct Foo {
6 | int a;
7 | int b[8];
8 | } foo [16];
9 |
10 | int main()
11 | {
12 | struct Foo *f = foo;
13 | int i;
14 | int acc = 0;
15 |
16 | printf("start of nested\n");
17 |
18 | for (i=0; i<16; i++) {
19 | int *b = f[i].b;
20 | b += 2;
21 | b[0] = 3;
22 | b[1] = 4;
23 | acc += b[1] - b[0];
24 | }
25 |
26 | printf("end of nested\n");
27 |
28 | return acc - 16;
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/test/small2/nonwilderror.c:
--------------------------------------------------------------------------------
1 | extern void error(int status , int errnum , const char * format , ...)
2 | __attribute__((__format__(__printf__, 3, 4))) ;
3 |
4 |
5 | static void parse_group(const char * name) {
6 | if(0) error(1, 0, gettext("invalid group name %s"), quote(name));
7 | }
8 |
9 |
10 | int main(int argc , char * * argv ) {
11 | return 0;
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/test/small2/oldstyle.c:
--------------------------------------------------------------------------------
1 | // oldstyle decls are problematic in themselves?
2 |
3 | static int foo(int x); // right now, 'static' is the problem
4 |
5 | int foo(x)
6 | int x;
7 | {
8 | return x;
9 | }
10 |
11 | int main()
12 | {
13 | return foo(0);
14 | }
15 |
--------------------------------------------------------------------------------
/test/small2/partialbracket.c:
--------------------------------------------------------------------------------
1 | // partially-bracketed initializers cause problems
2 |
3 | struct S {
4 | int x, y;
5 | };
6 |
7 | struct S array[] = {
8 | 1,2,
9 | 3,4
10 | };
11 |
12 | struct S array_ok[] = {
13 | {1,2},
14 | {3,4}
15 | };
16 |
17 | int main()
18 | {
19 | return array[0].x - 1; // should be 0
20 | }
21 |
--------------------------------------------------------------------------------
/test/small2/pset.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int main()
4 | {
5 | int someVariable, restrict;
6 |
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small2/ptrinint.c:
--------------------------------------------------------------------------------
1 | // test storing ints in pointers
2 |
3 |
4 | int main()
5 | {
6 | // local variable
7 | int local = 7;
8 |
9 | // pointer to this variable
10 | int *ptr = &local;
11 | *ptr = 9; // modify via pointer
12 |
13 | // now store an int in the ptr
14 | ptr = (int*)23;
15 | local = (int)ptr; // read the int out of the ptr
16 |
17 | // point the ptr back at the local
18 | ptr = &local;
19 |
20 | // and verify everything is 23
21 | return *ptr + local*10 - (23 + 23*10);
22 | }
23 |
--------------------------------------------------------------------------------
/test/small2/regbeforeassign.c:
--------------------------------------------------------------------------------
1 | // registers before assigning
2 |
3 | #include // printf
4 |
5 | void innerDoTreeStuff(int letGcFree)
6 | {
7 | int i;
8 |
9 | /* Add and delete random numbers from the hash table */
10 | printf("inserting...\n");
11 | }
12 |
13 | int main()
14 | {
15 | innerDoTreeStuff(0);
16 | return 0;
17 | }
18 |
--------------------------------------------------------------------------------
/test/small2/runall_misc.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int main (int argc, char **argv)
4 | {
5 | return 0;
6 | }
7 | //Our parser was allowing trailing right braces
8 | } //KEEP rbrace: error = syntax error
9 |
10 |
--------------------------------------------------------------------------------
/test/small2/rusage.c:
--------------------------------------------------------------------------------
1 | struct rusage ;
2 |
3 | struct foobar_not_used;
4 |
5 | int w3(struct rusage *__usage ) { return 0; }
6 |
7 | int main()
8 | {
9 | struct rusage *r;
10 | w3(r);
11 | return 0;
12 | }
13 |
14 |
--------------------------------------------------------------------------------
/test/small2/s59.c:
--------------------------------------------------------------------------------
1 | typedef unsigned char hashtyp;
2 | typedef unsigned short strindx;
3 |
4 |
5 | typedef struct S59 * idptr;
6 | typedef struct S59 {
7 | idptr inext;
8 | unsigned char inref;
9 | hashtyp ihash;
10 | strindx istr;
11 | } idnode;
12 |
13 | void printtok(strindx istr){}
14 |
15 | void
16 | printid(ip)
17 | idptr ip;
18 | {
19 | printtok(ip->istr);
20 | }
21 |
22 | int main()
23 | {
24 | return 0;
25 | }
26 |
--------------------------------------------------------------------------------
/test/small2/segfault.c:
--------------------------------------------------------------------------------
1 | #include // malloc
2 |
3 | #define N 100000
4 |
5 | struct S1 { struct T1* b; };
6 | struct S2 { struct T2* b; };
7 |
8 | struct T1 { int x; };
9 | struct T2 { int x, y[N]; };
10 |
11 | int main() {
12 |
13 | struct S1 *s1p;
14 | struct S2 *s2p;
15 |
16 | s2p = (struct S2*)malloc(sizeof(struct S2));
17 |
18 | s1p = (struct S1*) s2p;
19 |
20 | s1p->b = (struct T1*)malloc(sizeof(struct T1));
21 | //s2p->b = (struct T2*)(s1p->b);
22 |
23 | s2p->b->x = 1;
24 |
25 | /* if N is large enough, this should segfault */
26 | s2p->b->y[N-1] = 3;
27 |
28 | return 0;
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/test/small2/stackptr.c:
--------------------------------------------------------------------------------
1 | #include "../small1/testharness.h"
2 |
3 | #define NUMERRORS 2
4 |
5 | char * global;
6 |
7 | int notmain() {
8 | char loc;
9 | // We check that the __checkStackBottom is not too lenient
10 | global = &loc; //ERROR(2):STORE_SP
11 | }
12 |
13 | int main(int argv, char **argv, char **envp) {
14 | char mainloc;
15 | // We should be able to store mainloc
16 | global = & mainloc; E(1); // ERROR(1):Error 1
17 |
18 | // We should be able to store argv
19 | global = *argv; E(2); // ERROR(2):Error 2
20 |
21 | // And envp
22 | global = *envp; E(3); // ERROR(3):Error 3
23 |
24 | SUCCESS;
25 | }
26 |
--------------------------------------------------------------------------------
/test/small2/stackptrptr.c:
--------------------------------------------------------------------------------
1 | // stackptrptr.c
2 | // NUMERRORS(1)
3 | // demonstrate problem with stack ptr to stack ptr
4 |
5 | #define MESS_UP // ERROR(1)
6 |
7 | #ifndef MESS_UP
8 | int main()
9 | {
10 | int x = 0;
11 | int *px = &x;
12 | int **ppx = &px; // allowed
13 |
14 | return **ppx;
15 | }
16 |
17 | #else
18 | int main()
19 | {
20 | int x = 0;
21 | int *px = &x;
22 | int *ppx[1];
23 |
24 | ppx[0] = &px; // not allowed
25 | return *(ppx[0]);
26 | }
27 | #endif // 0/1
28 |
--------------------------------------------------------------------------------
/test/small2/structattr3.c:
--------------------------------------------------------------------------------
1 | // structattr3.c
2 | // yet more experiments
3 |
4 |
5 | struct S { char a; } __attribute__((aligned(8))) const x = {1};
6 |
7 | struct S y[10] = {1,2,3};
8 | int z = 5;
9 |
10 | int main() { return 0; }
11 |
--------------------------------------------------------------------------------
/test/small2/tagfile.txt:
--------------------------------------------------------------------------------
1 | # tagfile.txt
2 | # lists all the functions to tag
3 | # (hash isn't really a comment, but any line with a leading hash
4 | # is sure not to match any function name)
5 |
6 | # blank lines should be ok too
7 |
8 | foo
9 |
10 | # end of tagfile.txt
11 |
12 |
--------------------------------------------------------------------------------
/test/small2/tagfile1.c:
--------------------------------------------------------------------------------
1 | // tagfile1.c
2 | // first half of a tagfile tester
3 |
4 | // perfectly ordinary definition
5 | int foo(int x)
6 | {
7 | return x+7;
8 | }
9 |
10 | #ifdef STATIC_FUNC
11 | // wrong function type
12 | typedef void (*VoidFn)();
13 |
14 | // static function definition that will provoke a descriptor
15 | static int bar(int *p)
16 | {
17 | VoidFn vf;
18 | vf = (VoidFn)bar;
19 | return *p;
20 | }
21 | #endif // STATIC_FUNC
22 |
--------------------------------------------------------------------------------
/test/small2/tagfile2.c:
--------------------------------------------------------------------------------
1 | // tagfile2.c
2 | // second half of a tagfile tester
3 |
4 | // external decl of function in tagfile1.c
5 | int foo(int x);
6 |
7 | typedef void (*VoidFn)();
8 |
9 | int main()
10 | {
11 | VoidFn tagMaker;
12 | int x;
13 |
14 | tagMaker = (VoidFn)&foo; // make CCured tag 'foo'
15 | x = foo(3); // but call it normally
16 |
17 | return x-10; // should be 0
18 | }
19 |
20 |
21 | #ifdef STATIC_FUNC
22 | // static function definition that will provoke a descriptor
23 | static int bar(int *p)
24 | {
25 | VoidFn vf;
26 | vf = (VoidFn)bar;
27 | return *p;
28 | }
29 | #endif // STATIC_FUNC
30 |
--------------------------------------------------------------------------------
/test/small2/thing.c:
--------------------------------------------------------------------------------
1 | // thing.c
2 | // strange casts to 'void' on pointer comparisons??
3 |
4 | struct Thing *thing;
5 |
6 | int test()
7 | {
8 | return thing == 0;
9 | }
10 |
11 | int main()
12 | {
13 | test();
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/test/small2/trivial-tb.c:
--------------------------------------------------------------------------------
1 | // trivial-tb.c
2 | // NUMERRORS 4
3 | // test the test-bad target and lib/test-bad script
4 |
5 | #include // printf
6 | #include // exit
7 |
8 | void fail(int val)
9 | {
10 | printf("fail(%d)\n", val);
11 | exit(val);
12 | }
13 |
14 | int main()
15 | {
16 | fail(1); // ERROR(1)
17 | fail(2); // ERROR(2)
18 | fail(3); // ERROR(3)
19 | fail(4); // ERROR(4)
20 |
21 | printf("no failure\n");
22 | return 0;
23 | }
24 |
25 |
26 |
--------------------------------------------------------------------------------
/test/small2/twoprintfs.c:
--------------------------------------------------------------------------------
1 | // call a function twice, which does printf of a literal string
2 |
3 | #include // printf
4 |
5 | void pr()
6 | {
7 | printf("hi there\n");
8 | }
9 |
10 | int main()
11 | {
12 | pr();
13 | pr();
14 | return 0;
15 | }
16 |
--------------------------------------------------------------------------------
/test/small2/typeof.c:
--------------------------------------------------------------------------------
1 | // simple use of typeof
2 |
3 | int globalInt;
4 |
5 | void y() {
6 | exit(-2); //make sure y() is not invoked!
7 | }
8 |
9 | void typeofVoid() {
10 | (typeof(y()))0;
11 | }
12 |
13 |
14 | int main()
15 | {
16 | __typeof(globalInt) localInt;
17 | typeofVoid();
18 | localInt = 6 * 2 - 12;
19 | return localInt;
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/test/small2/undef_func.c:
--------------------------------------------------------------------------------
1 | // Demonstrate what happens when you call a function that is not
2 | // defined.
3 |
4 | int main() {
5 | int a = 3;
6 | gronkwaerawerawerwae(a);
7 | return 0;
8 | }
9 |
--------------------------------------------------------------------------------
/test/small2/unionext.c:
--------------------------------------------------------------------------------
1 | // union decl in a compound statement expression
2 |
3 | int main()
4 | {
5 | int status;
6 |
7 | return
8 | (
9 | (__extension__
10 | ({
11 | union {
12 | __typeof( status ) __in;
13 | int __i;
14 | } __u;
15 |
16 | __u.__in = status;
17 | __u.__i;
18 | })
19 | ) & 0xff00
20 | ) >> 8 ;
21 | }
22 |
--------------------------------------------------------------------------------
/test/small2/volatilestruct.c:
--------------------------------------------------------------------------------
1 | // volatilestruct.c
2 | // from sac at stevechamberlain dot com
3 |
4 | // problem with associating attributes with structs instead
5 | // of the declared instances
6 |
7 | struct foo
8 | {
9 | int AAAAAAAAAAAAAAAAAAA:7;
10 | } xxx;
11 |
12 | int main ()
13 | {
14 | struct foo
15 | {
16 | double BBBBBBBBBBBBBBBBBBB;
17 | } volatile bar;
18 |
19 | static struct foo baz;
20 | bar = baz;
21 |
22 | return 0;
23 | }
24 |
--------------------------------------------------------------------------------
/test/small2/xcheckers.c:
--------------------------------------------------------------------------------
1 |
2 | typedef struct {
3 | unsigned long cmap ;
4 | } Screen ; /*typedef*/
5 |
6 | typedef struct _XDisplay Display ; /*typedef*/
7 | typedef struct {
8 | Screen * screens ;
9 | } * _XPrivDisplay ; /*typedef*/
10 |
11 | Display * dpy ;
12 | unsigned long paper ;
13 | static int getColor(unsigned long cmap , char * color_name )
14 | {
15 | return 1;
16 | }
17 |
18 | static void loadImage(void )
19 | {
20 | char * thisScene ;
21 | paper = getColor((& (((_XPrivDisplay )dpy)->screens)[1])->cmap, thisScene);
22 | /*(colorTable[1]).c_color);*/
23 |
24 | }
25 |
26 | int main () {
27 | return 0;
28 | }
29 |
--------------------------------------------------------------------------------
/test/testcil:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | eval 'exec perl -I . -S ./testcil.pl ${1+"$@"}'
3 | if 0;
4 |
--------------------------------------------------------------------------------
/test/testcil.bat:
--------------------------------------------------------------------------------
1 | perl -S testcil.pl %*
2 |
--------------------------------------------------------------------------------