Giter Club home page Giter Club logo

frontc's People

Contributors

cdisselkoen avatar codyroux avatar gitoleg avatar ivg avatar roptat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

frontc's Issues

Fail parsing attributes after __asm__

Trying to parse string.h from my system, I get this error:

Syntax error: extern int strerror_r (int __errnum, char *__buf, size_t __buflen) __asm__ ("" "__xpg_strerror_r") __attribute__ ((__nothrow__ , __leaf__))

You can reproduce with something like:

extern int foo() __asm__("") __attribute(());

which doesn't parse, whereas

extern int foo() __attribute(()) __asm__("");

does. I think this is because the rule global has a case for global_type global_proto basic_asm SEMICOLON, and global_proto can have attributes, so the second case is covered.

support additional floating types

Example,

/usr/include/x86_64-linux-gnu/bits/mathcalls-helper-functions.h[21] Syntax error: extern int __fpclassifyf128 (_Float128 __value) __attribute__ ((__nothrow__ , __leaf__))

Cannot parse 'inline' from OCaml headers

Using calipso/FrontC 4.0.0 on Fedora34:

cat >x.c <<EOF
#include "caml/mlvalues.h"
#include "caml/memory.h"
#include "caml/alloc.h"

value dummy(value x) {
  CAMLparam1(x);
  CAMLreturn(x);
}
EOF
calipso_stat -p 'gcc -std=c99 -E -I /home/edwin/.opam/4.11.0/lib/ocaml/ %i -o %o' y.c
/home/edwin/.opam/4.11.0/lib/ocaml/caml/misc.h[214] Syntax error: static inline int caml_uadd_overflow(uintnat a, uintnat b, uintnat * res)
goto total = 0
goto average = -
goto maximum = 0
goto functions = 0
label total = 0
label average = -
label maximum = 0
label functions = 0

Note: std=c99 is needed otherwise it fails at a different place:
/usr/lib/gcc/x86_64-redhat-linux/11/include/stddef.h[416] Syntax error: long long __max_align_ll __attribute__((__aligned__(__alignof__(long long))));

(If I save the preprocessed file and delete the inline the next failure will be:
/usr/include/stdio.h[415] Syntax error: extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ , __leaf__)))

Fail parsing named type right after it is defined

Hi,

from latest master, I'm having issues with a file that defines a new type and uses it right after it:

typedef struct my_t {
  int foo;
} my_t;
my_t bar();

gives me a parsing error on my_t on the last line. However:

typedef struct my_t {
  int foo;
} my_t;
int baz();
my_t bar();

gives no parsing error

Fails to parse re-typedefs

FrontC fails to parse the following:

typedef int a;
typedef int b;
typedef b a;

even though this is accepted by clang.

Probably related is that FrontC fails to parse the following:

typedef int a;
typedef int a;

even though this is also accepted by clang.

cannot parse `typedef` with `bitfields`

FrontC cannot parse

typedef int int_t;
struct test1{
  int_t a : 4;
  int b : 13;
  int c : 1;
};

If we remove the typedef, then it works

struct test1{
  int a : 4;
  int b : 13;
  int c : 1;
};

designated initializer style

Sorry, here's another one :D

struct point {
  int    x;
  int    y;
};

int main() {
  struct point p = { .y = 2, .x = 1 };
}

fails to parse the initialization of variable p.

designated initializer style is a C99 feature.

Repository has diverged with sourcesup/renater FrontC git repository

Hi,

I recently came to learn the existence of another FrontC repository maintained by the TRACES team/University of Toulouse, the original authors (Hugues Cassé).
The repository lives at https://git.renater.fr/anonscm/git/orange/Frontc.git (project is https://sourcesup.renater.fr/scm/?group_id=5026).

You can preview the large diff at https://github.com/BinaryAnalysisPlatform/FrontC/compare/master...jordr:FrontC:sourcesup?expand=1
Do you know what's going on / suggest a course of action?

prints `const char *` as `char const *`

If we parse and print the following example

const char *foo(const char *q, char const *z){
  return q;
}

shows up as

char  const *foo(char  const *q, char  const *z)
{
	return q;
}

const char * became char const *, which is causing compile errors.

Syntax error on enums with trailing comma

Frontc can't parse enums which have a trailing comma after the last variant.

// enum-commas.c
typedef enum {
  Little,
  Medium,
  Big,
} Size;

Calling parse_file prints the error message enum-commas.c[5] Syntax error: } Size;.

anonymous union and struct

Hi,

now that the previous issues are fixed, I have more :D. This time, it's about anonymous structs and unions:

struct Scope {
    // Anonymous union
    union {
        char alpha;
        int num;
    };
};

struct Scope2
{
    // Anonymous structure
    struct
    {
        char alpha;
        int num;
    };
};

both structs have a parsing error, because a field is supposed to be a type with names, but the inner union and struct do not have a name. This is apparently part of C11, and also a GNU extension (in the file I have, the anonymous union is even preceded by __extension__). I tried applying the attached patch, but ctoxml gives me back empty structs:

<file>
	<struct id="struct:Scope"/>
	<struct id="struct:Scope2"/>
</file>

anonymous-union-structs.patch

FrontC 4.0 reverses the fields in the struct

FrontC reverses the fields in a struct. For example, it parses

struct pair{
  int *first;
  int *second;
  int len;
};

as

struct pair{
  int len;
  int *second;
  int *first;
};
PARSING_OK
 [Cabs.ONLYTYPEDEF
   (Cabs.STRUCT ("pair",
     [(Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), Cabs.NO_STORAGE,
       [("len", Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), [], Cabs.NOTHING)]);
      (Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), Cabs.NO_STORAGE,
       [("second", Cabs.PTR (Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN)), 
         [], Cabs.NOTHING)]);
      (Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), Cabs.NO_STORAGE,
       [("first", Cabs.PTR (Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN)), [],
         Cabs.NOTHING)])]),
    Cabs.NO_STORAGE, [])]

FrontC 3.4 keeps the original order.

FrontC documentation compilation error

- ocamlc   unix.cma ../frontc/frontc.cma -o calipso_stat gen.cmo reduce.cmo 
- make[1]: Leaving directory `/home/travis/.opam/4.07.0/.opam-switch/build/FrontC.3.4.2/calipso'
- make[1]: Entering directory `/home/travis/.opam/4.07.0/.opam-switch/build/FrontC.3.4.2/frontc'
- make[1]: Circular cparser.cmx <- clexer.cmx dependency dropped.
- make[1]: Circular cparser.cmx <- clexer.cmx dependency dropped.
- install -d /home/travis/.opam/4.07.0/lib/FrontC
- install frontc.cma cabs.cmi cxml.cmi cprint.cmi clexer.cmi cparser.cmi ctoxml.cmi frontc.cmi /home/travis/.opam/4.07.0/lib/FrontC
- install -d /home/travis/.opam/4.07.0/lib/FrontC
- install frontc.cmxa frontc.a cabs.cmi cxml.cmi cprint.cmi clexer.cmi cparser.cmi ctoxml.cmi frontc.cmi /home/travis/.opam/4.07.0/lib/FrontC
- ocamldoc -html -d ../autodoc  -t "FrontC" cabs.ml cxml.ml cprint.ml ctoxml.ml frontc.ml
- ../autodoc/style.css: No such file or directory
- Fatal error: exception Failure("../autodoc/Cabs.html: No such file or directory")
- make[1]: *** [doc] Error 2
- make[1]: Leaving directory `/home/travis/.opam/4.07.0/.opam-switch/build/FrontC.3.4.2/frontc'
- make[1]: Entering directory `/home/travis/.opam/4.07.0/.opam-switch/build/FrontC.3.4.2/ctoxml'
- install -d /home/travis/.opam/4.07.0/lib/bin
- install ctoxml /home/travis/.opam/4.07.0/lib/bin

See the full log here: https://travis-ci.org/BinaryAnalysisPlatform/bap/jobs/570684148#L2032

It is a build failure for 4.07 OCaml version for my 4.08 PR BinaryAnalysisPlatform/bap#957

Dynamic loading frontc fails

I am trying to load frontc dynamically. If I compile native, it shows this error:

Warning 58: no `cmx` file was found in path for module `Frontc`, and its interface was not compiled with `-opaque`

When execute, it fails with this error:

Error during dynlink: error loading shared library: Dynlink.Error (Dynlink.Cannot_open_dll "Failure(\"/path/bar.cmxs: undefined symbol: camlFrontc\")")

If I compile byte, it compiles, but when I run,

Error during dynlink: this object file uses unsafe features

Fails to parse some GNU attributes

FrontC fails to parse __attribute__((__aligned__(__alignof__(long long)))). This appears in stddef.h on my system, or technically in __stddef_max_align_t.h which is #included in stddef.h.

I believe the root cause of the problem is that here, the rule which matches __alignof__(*) expects an identifier, a constant, or another expression involving parens, but instead it gets long long.

Fails to parse function declaration involving asm

FrontC fails to parse the following:

int a() __asm__("" "");

even though this is accepted by clang.

The root cause for this one seems to be that global_dec doesn't include a case where there is __asm__ after the RPAREN; or, alternately, that opt_gcc_attributes, which would be accepted in this position, only allows __attribute__(...) and not __asm__(...).

Build fails due to syntax error on Set.Make(String)

$ dune.build
File "frontc/cxml.ml", line 43, characters 19-20:
Error: Syntax error

This is because of this code bit:

FrontC/frontc/cxml.ml

Lines 42 to 59 in c95d785

let validate_identifiers toplevel =
let open Set.Make(String) in
let rec node ids x ~accept ~reject = match x with
| TEXT _ | COM _ | PI _ -> accept ids
| ELT (_,attrs,xs) as elt ->
match List.assoc_opt "id" attrs with
| None -> nodes ids xs ~accept ~reject
| Some "" -> reject elt
| Some id -> if mem id ids
then reject elt
else nodes (add id ids) xs ~reject ~accept
and nodes ids xs ~accept ~reject = match xs with
| [] -> accept ids
| x :: xs -> node ids x ~reject ~accept:(fun ids ->
nodes ids xs ~accept ~reject) in
node empty toplevel
~accept:(fun _ -> Ok toplevel)
~reject:(fun elt -> Error elt)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.