shithub: scc

Download patch

ref: 8533b9940b37a8939ca2af338d28f5ae17b1b4ce
parent: 1093e4c416c30a25ef1b424e289264ea5e6fc973
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Mon Feb 13 04:13:10 EST 2017

[cc1] Add warnings about promotable types in va_arg()

Bool, char  and short are promoted to int when they are passed through ...,
and it means that it is impossible to have them in a stack created by a
variadic function. This patch warns to the user about it and correct
the type to int.

--- a/cc1/builtin.c
+++ b/cc1/builtin.c
@@ -20,6 +20,12 @@
 		errorp("incorrect parameters for va_arg");
 		return constnode(zero);
 	}
+	if (tp == booltype ||
+	    tp == chartype || tp == uchartype || tp == schartype ||
+	    tp == shortype || tp == ushortype) {
+		warn("bool, char and short are promoted to int when passed through '...'");
+		tp = (tp->prop & TSIGNED) ? inttype : uinttype;
+	}
 
 	np = node(OBUILTIN, tp, ap, NULL);
 	np->sym = sym;