diff options
| author | Edmund Grimley Evans <Edmund.Grimley.Evans@gmail.com> | 2015-11-20 23:17:24 +0000 |
|---|---|---|
| committer | Edmund Grimley Evans <Edmund.Grimley.Evans@gmail.com> | 2015-11-20 23:17:24 +0000 |
| commit | 4ae626451e5b64d2b5e0ad19e67b77a88a7bab55 (patch) | |
| tree | 0a686ec6f138295a3c29b0dcf6ed8e032e165b0c | |
| parent | 8dd185917603f68ffcdc3e98eb39f2497e99d563 (diff) | |
| download | tinycc-4ae626451e5b64d2b5e0ad19e67b77a88a7bab55.tar.gz tinycc-4ae626451e5b64d2b5e0ad19e67b77a88a7bab55.tar.bz2 | |
Bug fix for commit 553242c18a2387fb896df66eb9b5a502f0e87ff0.
In gtst, vtop->c.i is not usually zero, but it is when compiling:
int f(void) { return 1 && 1 ? 1 : 1; }
| -rw-r--r-- | i386-gen.c | 12 | ||||
| -rw-r--r-- | x86_64-gen.c | 12 |
2 files changed, 14 insertions, 10 deletions
@@ -678,12 +678,14 @@ ST_FUNC int gtst(int inv, int t) } else if (v == VT_JMP || v == VT_JMPI) { /* && or || optimization */ if ((v & 1) == inv) { - uint32_t n1, n = vtop->c.i; /* insert vtop->c jump list in t */ - while ((n1 = read32le(cur_text_section->data + n))) - n = n1; - write32le(cur_text_section->data + n, t); - t = vtop->c.i; + uint32_t n1, n = vtop->c.i; + if (n) { + while ((n1 = read32le(cur_text_section->data + n))) + n = n1; + write32le(cur_text_section->data + n, t); + t = vtop->c.i; + } } else { t = gjmp(t); gsym(vtop->c.i); diff --git a/x86_64-gen.c b/x86_64-gen.c index 4ac1e93..692b420 100644 --- a/x86_64-gen.c +++ b/x86_64-gen.c @@ -1716,12 +1716,14 @@ int gtst(int inv, int t) } else if (v == VT_JMP || v == VT_JMPI) { /* && or || optimization */ if ((v & 1) == inv) { - uint32_t n1, n = vtop->c.i; /* insert vtop->c jump list in t */ - while ((n1 = read32le(cur_text_section->data + n))) - n = n1; - write32le(cur_text_section->data + n, t); - t = vtop->c.i; + uint32_t n1, n = vtop->c.i; + if (n) { + while ((n1 = read32le(cur_text_section->data + n))) + n = n1; + write32le(cur_text_section->data + n, t); + t = vtop->c.i; + } } else { t = gjmp(t); gsym(vtop->c.i); |
