Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior (loop) of CIL v1.5.1 after being compiled by OCaml 4.02.0 #6687

Closed
vicuna opened this issue Dec 3, 2014 · 5 comments
Closed
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Dec 3, 2014

Original bug ID: 6687
Reporter: trungtq
Assigned to: @mshinwell
Status: closed (set by @xavierleroy on 2016-12-07T10:37:01Z)
Resolution: not a bug
Priority: normal
Severity: block
Platform: Linux, Kernel 3.13.0-24-generic
OS: Linux Mint 17 - 64bit
OS Version: 17
Version: 4.02.0
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @gasche

Bug description

Hello,

Recently, I tried out OCaml 4.02.0 and find out it's compiler is really fast.
However, I encountered a problem when use this compiler version with CIL tool: http://www.cs.berkeley.edu/~necula/cil/

The binary file built by OCaml 4.02.0 always goes into a loop when running. That doesn't happen with previous version of OCaml like 4.01.0

Could you please check if there is something wrong?

Thank you very much.

Steps to reproduce

  1. I use OCaml to compile the CIL tool:
    http://www.cs.berkeley.edu/~necula/cil/

  2. The tested version is CIL 1.5.1:
    http://sourceforge.net/projects/cil/files/cil/cil-1.5.1.tar.gz/download)

  3. Installation guide of CIL:
    http://www.cs.berkeley.edu/~necula/cil/cil002.html

  4. After compiling CIL, I tested it with a simple C file "hello.c"


// Hello.c
#include<stdio.h>

void main () {
printf("Hello world!");
}

  1. The command to run CIL is:
    ./bin/cilly --save-temps -D HAPPY_MOOD hello.c

  2. The cilly file built by OCaml 4.02.0 prints this output, and goes into a loop:


gcc -D_GNUCC -E -D HAPPY_MOOD -DCIL=1 hello.c -o ./hello.i
/home/trungtq/Setup/cil/cil-1.5.1/obj/x86_LINUX/cilly.asm.exe --out ./hello.cil.c ./hello.i

and it doesn't generate any output files hello.i

  1. I also try OCaml 4.03.0 out and it has the same bug.

  2. But this problem doesn't happen with OCaml 4.01.0. And here is the output given by OCaml 4.01.0:
    gcc -D_GNUCC -E -D HAPPY_MOOD -DCIL=1 ../hello.c -o ./hello.i /home/trungtq/Setup/cil/cil-1.5.1/obj/x86_LINUX/cilly.asm.exe --out ./hello.cil.c ./hello.i
    gcc -D_GNUCC -E -D HAPPY_MOOD ./hello.cil.c -o ./hello.cil.i
    gcc -D_GNUCC -c -D HAPPY_MOOD -o ./hello.o ./hello.cil.i
    gcc -D_GNUCC -o a.out -D HAPPY_MOOD ./hello.o

  3. For more information:

The binary file generated by the compiler of OCaml 4.01.0, can execute normally under OCaml 4.02.0 environment and doesn't go to a loop.
So, I guess it's a problem of the compiler.

@vicuna
Copy link
Author

vicuna commented Dec 3, 2014

Comment author: trungtq

I also test this bug in Ubuntu Server 12.04, 14.04 and it still occurs.

@vicuna
Copy link
Author

vicuna commented Dec 3, 2014

Comment author: @mshinwell

I am going to attempt to reproduce this.

@vicuna
Copy link
Author

vicuna commented Dec 3, 2014

Comment author: @mshinwell

This appears to be a problem with the Cil code, which was using an unsafe means of converting a format to a string. The following patch appears to make it work.

Please re-open this issue if you have further problems. Perhaps you could report this failure to the Cil developers.

--

--- cil-1.5.1/ocamlutil/pretty.ml 2012-07-14 11:20:43.000000000 +0100
+++ cil-1.5.1-fixed/ocamlutil/pretty.ml 2014-12-03 08:18:39.683517931 +0000
@@ -640,7 +640,7 @@

let gprintf (finish : doc -> 'b)
(format : ('a, unit, doc, 'b) format4) : 'a =

  • let format = (Obj.magic format : string) in
  • let format = string_of_format format in

    (* Record the starting align depth *)
    let startAlignDepth = !alignDepth in

@vicuna
Copy link
Author

vicuna commented Dec 3, 2014

Comment author: @gasche

(One may start wondering given the amount of code with this bug: string_of_format was added in 2002, first exposed in 3.07)

@vicuna
Copy link
Author

vicuna commented Dec 3, 2014

Comment author: trungtq

Wow, you react so fast. It's really a CIL bug. I will report to its developers.

Thank you so much for your promptly support.

Have a nice day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants