From f096c02afcfad5fbb2e0021af89520c3745084e5 Mon Sep 17 00:00:00 2001 From: Ian Bolton Date: Thu, 19 Aug 2010 08:12:31 +0000 Subject: [PATCH] For Ian Bolton * tree-switch-conversion.c (gen_inbound_check): Ensure that the type for the conditional has wide enough range. * testsuite/g++.dg/pr44328.C: New test. From-SVN: r163366 --- gcc/ChangeLog | 5 +++++ gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/g++.dg/pr44328.C | 39 ++++++++++++++++++++++++++++++++++ gcc/tree-switch-conversion.c | 7 ++++-- 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr44328.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index f7e5e33069b..4711095729f 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2010-08-19 Ian Bolton + + * tree-switch-conversion.c (gen_inbound_check): Ensure that the + type for the conditional has wide enough range. + 2010-08-18 Uros Bizjak PR target/45327 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index db26a97676e..afd8b999f6c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2010-08-19 Ian Bolton + + * g++.dg/pr44328.C: New test. + 2010-08-19 Tobias Burnus PR fortran/36158 diff --git a/gcc/testsuite/g++.dg/pr44328.C b/gcc/testsuite/g++.dg/pr44328.C new file mode 100644 index 00000000000..bbfe233340a --- /dev/null +++ b/gcc/testsuite/g++.dg/pr44328.C @@ -0,0 +1,39 @@ +/* { dg-do compile } */ +/* { dg-options "-c -O2 -Wextra" } */ +#define O_RDONLY (1<<0) +#define O_WRONLY (1<<1) +#define O_RDWR (O_RDONLY|O_WRONLY) +#define O_CREAT (1<<3) +#define O_TRUNC (1<<6) + +typedef enum { + OM_READ = 0, + OM_WRITE, + OM_READWRITE_NOCREATE, + OM_READWRITE_CREATE +} OpenMode; + +extern int open(const char *name, int mode); + +void open_file(const char *filename, const OpenMode rw) +{ + int mode = 0; + + switch( rw ) + { + case OM_WRITE: + mode = O_WRONLY|O_CREAT|O_TRUNC; + break; + case OM_READ: + mode = O_RDONLY; + break; + case OM_READWRITE_NOCREATE: + mode = O_RDWR; + break; + case OM_READWRITE_CREATE: + mode = O_RDWR|O_CREAT|O_TRUNC; + break; + } + + open( filename, mode ); +} diff --git a/gcc/tree-switch-conversion.c b/gcc/tree-switch-conversion.c index ed8b5ce5c0c..7072af8f5ab 100644 --- a/gcc/tree-switch-conversion.c +++ b/gcc/tree-switch-conversion.c @@ -96,6 +96,7 @@ eight) times the number of the actual switch branches. */ #include "gimple-pretty-print.h" #include "tree-dump.h" #include "timevar.h" +#include "langhooks.h" /* The main structure of the pass. */ struct switch_conv_info @@ -694,9 +695,11 @@ gen_inbound_check (gimple swtch) /* Make sure we do not generate arithmetics in a subrange. */ if (TREE_TYPE (TREE_TYPE (info.index_expr))) - utype = unsigned_type_for (TREE_TYPE (TREE_TYPE (info.index_expr))); + utype = lang_hooks.types.type_for_mode + (TYPE_MODE (TREE_TYPE (TREE_TYPE (info.index_expr))), 1); else - utype = unsigned_type_for (TREE_TYPE (info.index_expr)); + utype = lang_hooks.types.type_for_mode + (TYPE_MODE (TREE_TYPE (info.index_expr)), 1); /* (end of) block 0 */ gsi = gsi_for_stmt (info.arr_ref_first);