Module Name:    src
Committed By:   rillig
Date:           Mon Dec  6 23:26:28 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: gcc_builtin_alloca.c
            gcc_builtin_alloca.exp
        src/usr.bin/xlint/lint1: tree.c

Log Message:
lint: fix return type of GCC's __builtin_alloca

Needed for libgmp.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c \
    src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.exp
cvs rdiff -u -r1.396 -r1.397 src/usr.bin/xlint/lint1/tree.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c
diff -u src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c:1.1 src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c:1.2
--- src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c:1.1	Mon Dec  6 23:20:26 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.c	Mon Dec  6 23:26:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: gcc_builtin_alloca.c,v 1.1 2021/12/06 23:20:26 rillig Exp $	*/
+/*	$NetBSD: gcc_builtin_alloca.c,v 1.2 2021/12/06 23:26:28 rillig Exp $	*/
 # 3 "gcc_builtin_alloca.c"
 
 /*
@@ -11,11 +11,13 @@
 void
 example(void)
 {
-	/* expect+1: warning: illegal combination of pointer (pointer to char) and integer (int) [183] */
 	char *ptr = __builtin_alloca(8);
 	ptr[4] = '4';
 
-	/* expect+1: warning: illegal combination of pointer (pointer to char) and integer (int) [183] */
 	char *aligned_ptr = __builtin_alloca_with_align(8, 64);
 	aligned_ptr[0] = '\0';
+
+	/* expect+1: warning: illegal combination of pointer (pointer to char) and integer (int) [183] */
+	char *unknown = __builtin_allocate(8);
+	unknown[0] = '\0';
 }
Index: src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.exp
diff -u src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.exp:1.1 src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.exp:1.2
--- src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.exp:1.1	Mon Dec  6 23:20:26 2021
+++ src/tests/usr.bin/xlint/lint1/gcc_builtin_alloca.exp	Mon Dec  6 23:26:28 2021
@@ -1,2 +1 @@
-gcc_builtin_alloca.c(15): warning: illegal combination of pointer (pointer to char) and integer (int) [183]
-gcc_builtin_alloca.c(19): warning: illegal combination of pointer (pointer to char) and integer (int) [183]
+gcc_builtin_alloca.c(21): warning: illegal combination of pointer (pointer to char) and integer (int) [183]

Index: src/usr.bin/xlint/lint1/tree.c
diff -u src/usr.bin/xlint/lint1/tree.c:1.396 src/usr.bin/xlint/lint1/tree.c:1.397
--- src/usr.bin/xlint/lint1/tree.c:1.396	Sat Dec  4 00:01:24 2021
+++ src/usr.bin/xlint/lint1/tree.c	Mon Dec  6 23:26:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: tree.c,v 1.396 2021/12/04 00:01:24 rillig Exp $	*/
+/*	$NetBSD: tree.c,v 1.397 2021/12/06 23:26:28 rillig Exp $	*/
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.396 2021/12/04 00:01:24 rillig Exp $");
+__RCSID("$NetBSD: tree.c,v 1.397 2021/12/06 23:26:28 rillig Exp $");
 #endif
 
 #include <float.h>
@@ -234,6 +234,14 @@ is_gcc_bool_builtin(const char *name)
 		str_endswith(name, "_overflow_p"));
 }
 
+/* https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html */
+static bool
+is_gcc_void_pointer_builtin(const char *name)
+{
+	return strcmp(name, "__builtin_alloca") == 0 ||
+	       strncmp(name, "__builtin_alloca_", 17) == 0;
+}
+
 static void
 build_name_call(sym_t *sym)
 {
@@ -247,6 +255,8 @@ build_name_call(sym_t *sym)
 
 		if (is_gcc_bool_builtin(sym->s_name))
 			sym->s_type = gettyp(BOOL);
+		else if (is_gcc_void_pointer_builtin(sym->s_name))
+			sym->s_type = derive_type(gettyp(VOID), PTR);
 
 	} else if (Sflag) {
 		/* function '%s' implicitly declared to return int */

Reply via email to