From: Nicolai Stange <nicstange@xxxxxxxxx> 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@xxxxxxxxx> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- expression.c | 1 + validation/constexpr-labelref.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 validation/constexpr-labelref.c diff --git a/expression.c b/expression.c index 00edd1f99..241ab7bad 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 000000000..15b5293ae --- /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 + */ -- 2.12.0 -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html