Skip to content

Commit 936b041

Browse files
committed
Merge pull request #24 from scolin/scolin-misc-fixes
This pull request solves two minor bugs and a more important one
2 parents 9eca9ad + d5d2776 commit 936b041

File tree

13 files changed

+90
-1
lines changed

13 files changed

+90
-1
lines changed

src/frontc/cparser.mly

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,11 @@ asmopname:
15421542

15431543
asmclobber:
15441544
/* empty */ { [] }
1545-
| COLON asmcloberlst_ne { $2 }
1545+
| COLON asmcloberlst { $2 }
1546+
;
1547+
asmcloberlst:
1548+
/* empty */ { [] }
1549+
| asmcloberlst_ne { $1 }
15461550
;
15471551
asmcloberlst_ne:
15481552
one_string_constant { [$1] }

src/mergecil.ml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,34 @@ class renameVisitorClass = object (self)
993993
* variable. Must do its type and attributes. *)
994994
method vvdec (vi: varinfo) = DoChildren
995995

996+
method vglob (g: global) : global list visitAction =
997+
match g with
998+
| GVar(v, init, loc) ->
999+
let update_init glob =
1000+
match glob with
1001+
| GVar(u, uinit, loc) -> GVar(u, u.vinit, loc)
1002+
| _ -> glob
1003+
in
1004+
let update_all_inits = List.map update_init in
1005+
let () =
1006+
match v.vinit.init, init.init with
1007+
| None, None -> ()
1008+
(* This case may happen when a definition is encountered, but
1009+
the variable was already seen through a declaration and thus
1010+
has no definition *)
1011+
| None, Some(_) -> v.vinit.init <- init.init
1012+
(* The following case should never happen because it should never be emitted *)
1013+
| Some(_), None -> assert false
1014+
(* The following case is either never emitted (same
1015+
initializations, or different initializations but an error is
1016+
thrown) or emitted when first encountering a definition
1017+
(hence the initializations are supposed to be identical) *)
1018+
| Some(_), Some(_) -> ()
1019+
in
1020+
ChangeDoChildrenPost([g], update_all_inits)
1021+
| _ -> DoChildren
1022+
1023+
9961024
(* This is a variable use. See if we must change it *)
9971025
method vvrbl (vi: varinfo) : varinfo visitAction =
9981026
if not vi.vglob then DoChildren else

test/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,14 @@ mergestruct: $(TESTDIR)/small2/mergestruct1.c $(TESTDIR)/small2/mergestruct2.c
363363
$(CILLY) mergestruct1.c mergestruct2.c -o mergestruct.exe
364364
$(TESTDIR)/small2/mergestruct.exe
365365

366+
# sc: this tests for a merger bug in global variables initializations
367+
mergeinit: $(TESTDIR)/small2/mergeinit1.h $(TESTDIR)/small2/mergeinit1.c \
368+
$(TESTDIR)/small2/mergeinit2.h $(TESTDIR)/small2/mergeinit2_1_reftable.c $(TESTDIR)/small2/mergeinit2_2_definition.c \
369+
$(TESTDIR)/small2/mergeinit3.h $(TESTDIR)/small2/mergeinit3.c \
370+
$(TESTDIR)/small2/mergeinit4.c
371+
cd $(TESTDIR)/small2; \
372+
$(CILLY) --merge --strictcheck --keepunused mergeinit1.c mergeinit2_1_reftable.c mergeinit2_2_definition.c mergeinit3.c mergeinit4.c
373+
366374
# sm: yet another merger test (I know there's a target somewhere)
367375
mergeinline: $(TESTDIR)/small2/mergeinline1.c $(TESTDIR)/small2/mergeinline2.c
368376
cd $(TESTDIR)/small2; \
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
int main(){
3+
asm ("xor %%eax, %%eax"
4+
: /* No outputs. */
5+
: /* No inputs */
6+
: );
7+
return(0);
8+
}

test/small2/mergeinit1.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
int f1(void)
3+
{
4+
return(1);
5+
}
6+
7+

test/small2/mergeinit1.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
extern int f1(void);

test/small2/mergeinit2.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
extern int (*table[2])();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "mergeinit2.h"
2+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
};

test/small2/mergeinit3.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
int f3(void)
3+
{
4+
return(3);
5+
}
6+
7+

0 commit comments

Comments
 (0)