From 6b053f24c71237586af7c23613356393149614a2 Mon Sep 17 00:00:00 2001 From: Roy Frostig Date: Wed, 25 Aug 2010 17:15:15 -0700 Subject: [PATCH] Insure bools remain 0x1 or 0x0 by having boolean-NOT not just be a simple bit-NOT. --- src/Makefile | 1 + src/boot/me/trans.ml | 5 ++++- src/test/run-pass/bool-not.rs | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/bool-not.rs diff --git a/src/Makefile b/src/Makefile index 5d7b9dc9b2f..558ba771c71 100644 --- a/src/Makefile +++ b/src/Makefile @@ -440,6 +440,7 @@ TEST_XFAILS_LLVM := $(TASK_XFAILS) \ bind-thunk.rs \ bind-trivial.rs \ bitwise.rs \ + bool-not.rs \ box-in-tup.rs \ box-unbox.rs \ cast.rs \ diff --git a/src/boot/me/trans.ml b/src/boot/me/trans.ml index 2c1ecee141a..8deda6270ba 100644 --- a/src/boot/me/trans.ml +++ b/src/boot/me/trans.ml @@ -2058,7 +2058,10 @@ let trans_visitor in anno (); emit (Il.unary op dst src); - Il.Cell dst + (* Insist the bool domain being 0x0 and 0x1 *) + if unop = Ast.UNOP_not + then trans_binary Ast.BINOP_and (Il.Cell dst) one + else Il.Cell dst | Ast.EXPR_atom a -> trans_atom a diff --git a/src/test/run-pass/bool-not.rs b/src/test/run-pass/bool-not.rs new file mode 100644 index 00000000000..ba70bdb1318 --- /dev/null +++ b/src/test/run-pass/bool-not.rs @@ -0,0 +1,15 @@ +// -*- rust -*- + +fn main() { + if (!false) { + check (true); + } else { + check (false); + } + + if (!true) { + check (false); + } else { + check (true); + } +}