shithub: scc

Download patch

ref: 7b7d12f633d61116de104d3920e0e24cdd7ad802
parent: d6af37e2eea58d72a4f860b5289798206dcd3723
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Dec 15 02:19:34 EST 2016

[cc1] Fix #elif clauses

The implmentation of elif was evaluating the if part always, even
when due to the else part it was disabled, and it was generating
that the current state of the preprocessor was corrupted.

--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -657,8 +657,9 @@
 		return;
 	}
 
-	status = (ifstatus[cppctx-1] ^= 1);
-	cppoff += (status) ? -1 : 1;
+	status = ifstatus[cppctx-1];
+	ifstatus[cppctx-1] = !status;
+	cppoff += (status) ? 1 : -1;
 }
 
 static void
@@ -672,8 +673,10 @@
 elif(void)
 {
 	elseclause();
-	--cppctx;
-	cppif();
+	if (ifstatus[cppctx-1]) {
+		--cppctx;
+		cppif();
+	}
 }
 
 static void