shithub: riscv

Download patch

ref: 3fe2924287628a02d9c5f7d208a5af4623588034
parent: 9a4b5f2e6122ea261ce90fcab3f7361f76580bc8
author: Ori Bernstein <[email protected]>
date: Mon Mar 23 05:18:44 EDT 2020

evaluate #if expressions using vlong

#if expressions are expected to be evaluated using intmax_t,
according to the C99 spec, 6.10.1 p3. On plan9, intmax_t maps
to vlong.

--- a/sys/src/cmd/cpp/cpp.h
+++ b/sys/src/cmd/cpp/cpp.h
@@ -123,7 +123,7 @@
 void	glue(Tokenrow *, Token *, Token *);
 Tokenrow *stringify(Tokenrow *);
 int	lookuparg(Nlist *, Token *);
-long	eval(Tokenrow *, int);
+vlong	eval(Tokenrow *, int);
 void	genline(void);
 void	setempty(Tokenrow *);
 void	makespace(Tokenrow *);
--- a/sys/src/cmd/cpp/eval.c
+++ b/sys/src/cmd/cpp/eval.c
@@ -10,7 +10,7 @@
 #define	UNSMARK	0x1000
 
 struct value {
-	long	val;
+	vlong	val;
 	int	type;
 };
 
@@ -99,7 +99,7 @@
 /*
  * Evaluate an #if #elif #ifdef #ifndef line.  trp->tp points to the keyword.
  */
-long
+vlong
 eval(Tokenrow *trp, int kw)
 {
 	Token *tp;
@@ -217,7 +217,7 @@
 evalop(struct pri pri)
 {
 	struct value v1, v2;
-	long rv1, rv2;
+	vlong rv1, rv2;
 	int rtype, oper;
 
 	rv2=0;
@@ -277,21 +277,21 @@
 		case GT:
 			rv1 = rv1>rv2; break;
 		case LEQ|UNSMARK:
-			rv1 = (unsigned long)rv1<=rv2; break;
+			rv1 = (uvlong)rv1<=rv2; break;
 		case GEQ|UNSMARK:
-			rv1 = (unsigned long)rv1>=rv2; break;
+			rv1 = (uvlong)rv1>=rv2; break;
 		case LT|UNSMARK:
-			rv1 = (unsigned long)rv1<rv2; break;
+			rv1 = (uvlong)rv1<rv2; break;
 		case GT|UNSMARK:
-			rv1 = (unsigned long)rv1>rv2; break;
+			rv1 = (uvlong)rv1>rv2; break;
 		case LSH:
 			rv1 <<= rv2; break;
 		case LSH|UNSMARK:
-			rv1 = (unsigned long)rv1<<rv2; break;
+			rv1 = (uvlong)rv1<<rv2; break;
 		case RSH:
 			rv1 >>= rv2; break;
 		case RSH|UNSMARK:
-			rv1 = (unsigned long)rv1>>rv2; break;
+			rv1 = (uvlong)rv1>>rv2; break;
 		case LAND:
 			rtype = UND;
 			if (v1.type==UND)
@@ -342,7 +342,7 @@
 				break;
 			}
 			if (rtype==UNS)
-				rv1 /= (unsigned long)rv2;
+				rv1 /= (uvlong)rv2;
 			else
 				rv1 /= rv2;
 			break;
@@ -352,7 +352,7 @@
 				break;
 			}
 			if (rtype==UNS)
-				rv1 %= (unsigned long)rv2;
+				rv1 %= (uvlong)rv2;
 			else
 				rv1 %= rv2;
 			break;
@@ -386,7 +386,7 @@
 	struct value v;
 	Nlist *np;
 	int i, base, c, longcc;
-	unsigned long n;
+	uvlong n;
 	Rune r;
 	uchar *p;
 
@@ -426,7 +426,7 @@
 			n *= base;
 			n += i;
 		}
-		if (n>=0x80000000 && base!=10)
+		if (n>=(1ULL<<63) && base!=10)
 			v.type = UNS;
 		for (; *p; p++) {
 			if (*p=='u' || *p=='U')