aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
-rw-r--r--builtin.c8
-rw-r--r--validation/builtin-objsize-self-init.c11
2 files changed, 19 insertions, 0 deletions
diff --git a/builtin.c b/builtin.c
index 8e1d2d7e..3a29c3ae 100644
--- a/builtin.c
+++ b/builtin.c
@@ -546,11 +546,19 @@ static int expand_object_size(struct expression *expr, int cost)
// a deref is just intermediate variable
// and so the offset needs to be zeroed.
if (arg->op == '*') {
+ struct expression *parent = arg;
arg = arg->unop;
off = 0;
switch (arg->type) {
case EXPR_SYMBOL:
arg = arg->symbol->initializer;
+ if (arg == parent) {
+ // stop at self-initialized vars
+ // and do not expand them.
+ arg = NULL;
+ val = -1;
+ break;
+ }
continue;
default:
break;
diff --git a/validation/builtin-objsize-self-init.c b/validation/builtin-objsize-self-init.c
new file mode 100644
index 00000000..77e3da43
--- /dev/null
+++ b/validation/builtin-objsize-self-init.c
@@ -0,0 +1,11 @@
+static void f(void)
+{
+ void *param = param;
+ __builtin_object_size(param, 0);
+}
+
+/*
+ * check-name: builtin-objsize-self-init
+ * check-timeout:
+ * check-error-end
+ */