diff options
author | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2010-04-02 07:55:14 +0000 |
---|---|---|
committer | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2010-04-02 07:55:14 +0000 |
commit | e7b822497b940e181dab799a8c17dc49e2062f0a (patch) | |
tree | 435131d5b79a3305fd97fa8441cb9115fafdb19d | |
parent | c5b0c22b818f5a7a07da999c562abad9ed757715 (diff) | |
download | compcert-e7b822497b940e181dab799a8c17dc49e2062f0a.tar.gz compcert-e7b822497b940e181dab799a8c17dc49e2062f0a.zip |
In cparser/SimplExpr.ml:
- wrong simplification of && and || in the Set case
- generated nicer code for && and || in the Eval case
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1308 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
-rw-r--r-- | cparser/SimplExpr.ml | 26 | ||||
-rw-r--r-- | test/regression/Makefile | 2 | ||||
-rw-r--r-- | test/regression/Results/expr5 | 1 | ||||
-rw-r--r-- | test/regression/expr5.c | 13 |
4 files changed, 30 insertions, 12 deletions
diff --git a/cparser/SimplExpr.ml b/cparser/SimplExpr.ml index 484e2d87..330b1841 100644 --- a/cparser/SimplExpr.ml +++ b/cparser/SimplExpr.ml @@ -90,6 +90,10 @@ let simpl_expr loc env e act = let new_temp ty = Transform.new_temp (erase_attributes_type env ty) in + let eboolvalof e = + { edesc = EBinop(One, e, intconst 0L IInt, TInt(IInt, [])); + etyp = TInt(IInt, []) } in + let sseq s1 s2 = Cutil.sseq loc s1 s2 in let sassign e1 e2 = @@ -265,14 +269,14 @@ let simpl_expr loc env e act = let (s2, e2') = simpl e2 RHS in let tmp = new_temp e.etyp in (sseq s1 (sif e1' - (sseq s2 (sif e2' - (sassign tmp (intconst 1L IInt)) - (sassign tmp (intconst 0L IInt)))) - (sassign tmp (intconst 0L IInt))), + (sseq s2 (sassign tmp (eboolvalof e2'))) + (sassign tmp (intconst 0L IInt))), tmp) | Set lv -> - let (s2, _) = simpl e2 (Set lv) in - (sseq s1 (sif e1' s2 (sassign lv (intconst 0L IInt))), + let (s2, e2') = simpl e2 RHS in + (sseq s1 (sif e1' + (sseq s2 (sassign lv (eboolvalof e2'))) + (sassign lv (intconst 0L IInt))), voidconst) end @@ -291,13 +295,13 @@ let simpl_expr loc env e act = let tmp = new_temp e.etyp in (sseq s1 (sif e1' (sassign tmp (intconst 1L IInt)) - (sseq s2 (sif e2' - (sassign tmp (intconst 1L IInt)) - (sassign tmp (intconst 0L IInt))))), + (sseq s2 (sassign tmp (eboolvalof e2')))), tmp) | Set lv -> - let (s2, _) = simpl e2 (Set lv) in - (sseq s1 (sif e1' (sassign lv (intconst 1L IInt)) s2), + let (s2, e2') = simpl e2 RHS in + (sseq s1 (sif e1' + (sassign lv (intconst 1L IInt)) + (sseq s2 (sassign lv (eboolvalof e2')))), voidconst) end diff --git a/test/regression/Makefile b/test/regression/Makefile index 8407329f..1ec2264e 100644 --- a/test/regression/Makefile +++ b/test/regression/Makefile @@ -7,7 +7,7 @@ CCOMPFLAGS=-stdlib ../../runtime -dparse -dclight -dasm \ LIBS=$(LIBMATH) # Can run and have reference output in Results -TESTS=bitfields1 expr1 initializers volatile2 funct3 +TESTS=bitfields1 expr1 initializers volatile2 funct3 expr5 # Other tests: should compile to .s without errors (but expect warnings) EXTRAS=commaprec expr2 expr3 expr4 extern1 funct2 funptr1 init1 \ diff --git a/test/regression/Results/expr5 b/test/regression/Results/expr5 new file mode 100644 index 00000000..d00491fd --- /dev/null +++ b/test/regression/Results/expr5 @@ -0,0 +1 @@ +1 diff --git a/test/regression/expr5.c b/test/regression/expr5.c new file mode 100644 index 00000000..b41aeb88 --- /dev/null +++ b/test/regression/expr5.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +int foo(void) +{ + return 2; +} + +int main(void) +{ + int g_46 = 0 || foo(); + printf ("%d\n", g_46); + return 0; +} |