From b3d7fb1bac881a714fed871db33e98e67b9bf1b6 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Fri, 20 May 2022 22:27:08 +0200 Subject: fix infinite loop when expanding __builtin_object_size() with self-init vars expand_object_size(), used to expand __builtin_object_size(), recursively try to get the parent initializer. This fails miserably by looping endlessly when the object is a self-initialized variable. For the moment, fix this in the most obvious way: stop the recursion and do not expand such variables. Note: I wouldn't be surprised if these self-initialized variables create other problems elsewhere. Maybe we should remove their initializer and somehow mark them as "do not warn about -Wuninitialized" (well, there is no such warnings *yet*). Signed-off-by: Luc Van Oostenryck --- builtin.c | 8 ++++++++ validation/builtin-objsize-self-init.c | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 validation/builtin-objsize-self-init.c 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 + */ -- cgit 1.2.3-korg From 99a5645a0edbafac8eb667e0f341a73bebb5f34d Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Mon, 23 May 2022 10:55:03 +0200 Subject: handle clang's option "-meabi gnu" Clang has an option "-meabi " which is used by the kernel for ARMv7. This kind of option, taking a argument without a separating '=', can't be ignored like most other options and must this be special-cased. So, add the special case for this option and consume the argument if it's one of the valid one. Link: https://lore.kernel.org/r/20220331110118.vr4miyyytqlssjoi@pengutronix.de Reported-by: Marc Kleine-Budde Signed-off-by: Luc Van Oostenryck --- options.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/options.c b/options.c index 6704fc8d..187dacd3 100644 --- a/options.c +++ b/options.c @@ -685,6 +685,19 @@ static const struct flag mflags[] = { static char **handle_switch_m(char *arg, char **next) { + if (!strcmp(arg, "meabi") && next[1] && next[1][0] != '-') { + // clang has such an option with syntax: -meabi + // It's used by the kernel for armv7. + // GCC has the same option but with no argument. + // Parse it here to consume the possible argument. + static const char *valid[] = { "gnu", "4", "5", "default", NULL }; + int i; + for (i = 0; valid[i]; i++) { + if (!strcmp(next[1], valid[i])) + return ++next; + } + } + if (!strcmp(arg, "multiarch-dir")) { return handle_multiarch_dir(arg, next); } else { -- cgit 1.2.3-korg From 3d1d65bfe6dad089b9c2a8d69f36ba5301a9509c Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Sun, 22 May 2022 20:46:58 +0200 Subject: fix zero/sign extension of integer character constants An integer character constant has type 'int' but, subtly enough, its value is the one of a 'char' converted to an 'int'. So, do this conversion. Also set the type of wide character constants from 'long' to 'wchar_t'. Link: https://lore.kernel.org/r/20210927130253.GH2083@kadam Reported-by: Dan Carpenter Reported-by: Rasmus Villemoes Signed-off-by: Luc Van Oostenryck --- expression.c | 10 +++++++++- validation/char-constant-signed.c | 9 +++++++++ validation/char-constant-unsigned.c | 9 +++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 validation/char-constant-signed.c create mode 100644 validation/char-constant-unsigned.c diff --git a/expression.c b/expression.c index 221d7780..efdaa367 100644 --- a/expression.c +++ b/expression.c @@ -427,8 +427,16 @@ struct token *primary_expression(struct token *token, struct expression **tree) case TOKEN_CHAR ... TOKEN_WIDE_CHAR_EMBEDDED_3: expr = alloc_expression(token->pos, EXPR_VALUE); expr->flags = CEF_SET_CHAR; - expr->ctype = token_type(token) < TOKEN_WIDE_CHAR ? &int_ctype : &long_ctype; get_char_constant(token, &expr->value); + + // TODO: handle 'u8', 'u' & 'U' prefixes. + if (token_type(token) < TOKEN_WIDE_CHAR) { + expr->ctype = &char_ctype; + cast_value(expr, &int_ctype, expr, expr->ctype); + expr->ctype = &int_ctype; + } else { + expr->ctype = wchar_ctype; + } token = token->next; break; diff --git a/validation/char-constant-signed.c b/validation/char-constant-signed.c new file mode 100644 index 00000000..be0fd5ce --- /dev/null +++ b/validation/char-constant-signed.c @@ -0,0 +1,9 @@ +int test(void) { return '\377' == -1; } + +/* + * check-name: char-constant-signed + * check-command: test-linearize -Wno-decl -fsigned-char $file + * + * check-output-ignore + * check-output-returns: 1 + */ diff --git a/validation/char-constant-unsigned.c b/validation/char-constant-unsigned.c new file mode 100644 index 00000000..d5642b16 --- /dev/null +++ b/validation/char-constant-unsigned.c @@ -0,0 +1,9 @@ +int test(void) { return '\377' == 255; } + +/* + * check-name: char-constant-unsigned + * check-command: test-linearize -Wno-decl -funsigned-char $file + * + * check-output-ignore + * check-output-returns: 1 + */ -- cgit 1.2.3-korg