summaryrefslogtreecommitdiff
path: root/6
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2016-01-30 01:43:20 -0800
committerOri Bernstein <ori@eigenstate.org>2016-01-30 01:43:20 -0800
commitf7141e2d8ed52e0fb493810ea71adf22fa57a49e (patch)
tree5337807fcfdb8be6ca0b92f2237634d806828029 /6
parent92c71814af7cba149c2320dbc37627f7da8fa638 (diff)
downloadmc-f7141e2d8ed52e0fb493810ea71adf22fa57a49e.tar.gz
Fix isconstfn.
A constant function also needs to be initialized with a literal function.
Diffstat (limited to '6')
-rw-r--r--6/gen.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/6/gen.c b/6/gen.c
index c9674db..9d81fa6 100644
--- a/6/gen.c
+++ b/6/gen.c
@@ -85,7 +85,7 @@ char *genlocallblstr(char *buf, size_t sz)
int isconstfn(Node *n)
{
- Node *d;
+ Node *d, *e;
Type *t;
if (n->type == Nexpr) {
@@ -96,9 +96,16 @@ int isconstfn(Node *n)
d = n;
}
t = tybase(decltype(d));
- if (d && d->decl.isconst && d->decl.isglobl && !d->decl.isgeneric)
- return t->type == Tyfunc || t->type == Tycode;
- return 0;
+ if (!d || !d->decl.isconst || !d->decl.isglobl || d->decl.isgeneric)
+ return 0;
+ if (t->type != Tyfunc && t->type != Tycode)
+ return 0;
+ e = d->decl.init;
+ if (e && (exprop(e) != Olit || e->expr.args[0]->lit.littype != Lfunc))
+ return 0;
+ if (!e && !d->decl.isextern && !d->decl.isimport)
+ return 0;
+ return 1;
}
/*