From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v6 15/15] add support for wider type in switch-case
Date: Mon, 27 Mar 2017 19:34:05 +0200 [thread overview]
Message-ID: <20170327173405.11405-16-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170327173405.11405-1-luc.vanoostenryck@gmail.com>
Currently the different cases of a switch-statement, or more
exactly the 'struct multijmp' that hold the value of these cases
excepted only value of 'int' type. Trying to use a wider value
results in the value being truncated but any integer value should
be valid.
Fix this by unsigned 'long long' to hold these values.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
linearize.c | 8 ++++----
linearize.h | 2 +-
validation/switch-long.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+), 5 deletions(-)
create mode 100644 validation/switch-long.c
diff --git a/linearize.c b/linearize.c
index 574ccea94..209bd2bf3 100644
--- a/linearize.c
+++ b/linearize.c
@@ -77,7 +77,7 @@ static struct basic_block *alloc_basic_block(struct entrypoint *ep, struct posit
return bb;
}
-static struct multijmp *alloc_multijmp(struct basic_block *target, int begin, int end)
+static struct multijmp *alloc_multijmp(struct basic_block *target, long long begin, long long end)
{
struct multijmp *multijmp = __alloc_multijmp(0);
multijmp->target = target;
@@ -368,9 +368,9 @@ const char *show_instruction(struct instruction *insn)
buf += sprintf(buf, "%s", show_pseudo(insn->cond));
FOR_EACH_PTR(insn->multijmp_list, jmp) {
if (jmp->begin == jmp->end)
- buf += sprintf(buf, ", %d -> .L%u", jmp->begin, jmp->target->nr);
+ buf += sprintf(buf, ", %lld -> .L%u", jmp->begin, jmp->target->nr);
else if (jmp->begin < jmp->end)
- buf += sprintf(buf, ", %d ... %d -> .L%u", jmp->begin, jmp->end, jmp->target->nr);
+ buf += sprintf(buf, ", %lld ... %lld -> .L%u", jmp->begin, jmp->end, jmp->target->nr);
else
buf += sprintf(buf, ", default -> .L%u", jmp->target->nr);
} END_FOR_EACH_PTR(jmp);
@@ -1941,7 +1941,7 @@ static pseudo_t linearize_switch(struct entrypoint *ep, struct statement *stmt)
default_case = bb_case;
continue;
} else {
- int begin, end;
+ long long begin, end;
begin = end = case_stmt->case_expression->value;
if (case_stmt->case_to)
diff --git a/linearize.h b/linearize.h
index 0a70d8129..ce065fe76 100644
--- a/linearize.h
+++ b/linearize.h
@@ -48,7 +48,7 @@ extern struct pseudo void_pseudo;
struct multijmp {
struct basic_block *target;
- int begin, end;
+ long long begin, end;
};
struct asm_constraint {
diff --git a/validation/switch-long.c b/validation/switch-long.c
new file mode 100644
index 000000000..5bfdb4397
--- /dev/null
+++ b/validation/switch-long.c
@@ -0,0 +1,47 @@
+void def(void);
+void r0(void);
+void r1(void);
+
+void sw_long(long long a)
+{
+ switch (a) {
+ case 0: return r0();
+ case 1LL << 00: return r1();
+ case 1LL << 32: return r1();
+ }
+
+ return def();
+}
+
+/*
+ * check-name: switch-long
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+sw_long:
+.L0:
+ <entry-point>
+ switch.64 %arg1, 0 -> .L2, 1 -> .L3, 4294967296 -> .L4, default -> .L1
+
+.L2:
+ call r0
+ br .L5
+
+.L3:
+ call r1
+ br .L5
+
+.L4:
+ call r1
+ br .L5
+
+.L1:
+ call def
+ br .L5
+
+.L5:
+ ret
+
+
+ * check-output-end
+ */
--
2.12.0
next prev parent reply other threads:[~2017-03-27 17:37 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-27 17:33 [PATCH v6 00/15] prepare for LLVM fixes Luc Van Oostenryck
2017-03-27 17:33 ` [PATCH v6 01/15] don't output value of anonymous symbol's pointer Luc Van Oostenryck
2017-03-27 17:33 ` [PATCH v6 02/15] add table to "negate" some opcode Luc Van Oostenryck
2017-03-31 10:30 ` Christopher Li
2017-03-31 19:18 ` Luc Van Oostenryck
2017-03-27 17:33 ` [PATCH v6 03/15] use opcode table for compare_opcode() Luc Van Oostenryck
2017-03-27 17:33 ` [PATCH v6 04/15] canonicalize binops before simplification Luc Van Oostenryck
2017-03-27 17:33 ` [PATCH v6 05/15] canonicalize compare instructions Luc Van Oostenryck
2017-03-27 17:33 ` [PATCH v6 06/15] add is_signed_type() Luc Van Oostenryck
2017-03-27 17:33 ` [PATCH v6 07/15] fix usage of inlined calls Luc Van Oostenryck
2017-03-27 17:33 ` [PATCH v6 08/15] inlined calls should not block BB packing Luc Van Oostenryck
2017-03-27 17:33 ` [PATCH v6 09/15] give function's arguments a type via OP_PUSH Luc Van Oostenryck
2017-03-27 17:34 ` [PATCH v6 10/15] insure that all OP_PUSHs are just before their OP_CALL Luc Van Oostenryck
2017-03-27 17:34 ` [PATCH v6 11/15] give a type to OP_PHISOURCEs Luc Van Oostenryck
2017-03-27 17:34 ` [PATCH v6 12/15] give a type to OP_SELs, always Luc Van Oostenryck
2017-03-27 17:34 ` [PATCH v6 13/15] give a type to OP_SWITCHs Luc Van Oostenryck
2017-03-27 17:34 ` [PATCH v6 14/15] add doc about sparse's instructions/IR Luc Van Oostenryck
2017-03-27 17:34 ` Luc Van Oostenryck [this message]
2017-03-27 21:56 ` [PATCH v6 00/15] prepare for LLVM fixes Ramsay Jones
2017-03-27 22:22 ` Luc Van Oostenryck
2017-03-28 16:01 ` Ramsay Jones
2017-03-28 18:10 ` Linus Torvalds
2017-03-31 4:49 ` Christopher Li
2017-03-31 9:25 ` Luc Van Oostenryck
2017-03-31 10:04 ` Christopher Li
2017-03-31 12:19 ` Luc Van Oostenryck
2017-03-31 12:22 ` Dibyendu Majumdar
2017-03-31 12:24 ` Dibyendu Majumdar
2017-03-31 15:42 ` Christopher Li
2017-03-31 9:26 ` Christopher Li
2017-04-01 10:49 ` [GIT PULL v6] " Luc Van Oostenryck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170327173405.11405-16-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=sparse@chrisli.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).