aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorNicolai Stange <nicstange@gmail.com>2016-02-01 03:42:10 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-03-31 02:27:12 +0200
commit722199c0867a391df6ba78b4ca57ee93f71b6e42 (patch)
tree15db3642e9a1c8c9af0ec1d6583c3e75cceb1331
parenta39fedb0d7bf128bbef74c9a618f4ee6fe875a92 (diff)
downloadsparse-dev-722199c0867a391df6ba78b4ca57ee93f71b6e42.tar.gz
constexpr: recognize references to labels as address constants
As an extension, GCC allows labels to be referenced a la label1: ... void *ptr = &&label1; Tag these label references as being address constants allowing them to be used as initializers for objects of static storage duration. Signed-off-by: Nicolai Stange <nicstange@gmail.com> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--expression.c1
-rw-r--r--validation/constexpr-labelref.c14
2 files changed, 15 insertions, 0 deletions
diff --git a/expression.c b/expression.c
index 00edd1f9..241ab7ba 100644
--- a/expression.c
+++ b/expression.c
@@ -681,6 +681,7 @@ static struct token *unary_expression(struct token *token, struct expression **t
sym->ctype.modifiers |= MOD_ADDRESSABLE;
add_symbol(&function_computed_target_list, sym);
}
+ label->flags = CEF_ADDR;
label->label_symbol = sym;
*tree = label;
return token->next->next;
diff --git a/validation/constexpr-labelref.c b/validation/constexpr-labelref.c
new file mode 100644
index 00000000..15b5293a
--- /dev/null
+++ b/validation/constexpr-labelref.c
@@ -0,0 +1,14 @@
+static void a(void)
+{
+label1:
+ ;
+ static void *b = &&label1;
+}
+
+/*
+ * check-name: label reference constness verification.
+ * check-command: sparse -Wconstexpr-not-const $file
+ *
+ * check-error-start
+ * check-error-end
+ */