shithub: scc

Download patch

ref: 65d393be241273b385ef13c463cd4ada5aa74e62
parent: 517dc5a89fc3274dd6457b32653616e355369717
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Jan 24 03:28:43 EST 2016

Fix #line directive

1) Line must set the value for the next line, and since the line
   is incremented at the end of the line, we have to set the
   desired line minus 1.
2) Macros were not expanded in the line directive parameters
3) Lookup was returning macros while it looked up for
   cpp clauses.

--- a/cc1/cpp.c
+++ b/cc1/cpp.c
@@ -520,6 +520,7 @@
 	if (cppoff)
 		return;
 
+	disexpand = 0;
 	next();
 	n = strtol(yytext, &endp, 10);
 	if (n <= 0 || n > USHRT_MAX || *endp != '\0') {
@@ -541,7 +542,7 @@
 	next();
 
 set_line:
-	input->nline = n;
+	input->nline = n - 1;
 }
 
 static void
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -271,7 +271,7 @@
 		 * are typedef, because in other case we cannot declare
 		 * fields of such types.
 		 */
-		if (sns == NS_CPP || sns == ns)
+		if (sns == NS_CPP && !disexpand || sns == ns)
 			return sym;
 		if (ns == NS_CPP)
 			continue;
--- a/cc1/tests/test006.c
+++ b/cc1/tests/test006.c
@@ -2,9 +2,9 @@
 name: TEST006
 description: Basic test for if
 error:
-test006.c:6: warning: conditional expression is constant
-test006.c:8: warning: conditional expression is constant
-test006.c:11: warning: conditional expression is constant
+test006.c:5: warning: conditional expression is constant
+test006.c:7: warning: conditional expression is constant
+test006.c:10: warning: conditional expression is constant
 output:
 G1	K	"c
 G3	F	"main
--- a/cc1/tests/test010.c
+++ b/cc1/tests/test010.c
@@ -2,9 +2,9 @@
 name: TEST010
 description: Test for continue and break statements
 error:
-test010.c:9: warning: conditional expression is constant
-test010.c:11: warning: conditional expression is constant
-test010.c:31: warning: conditional expression is constant
+test010.c:8: warning: conditional expression is constant
+test010.c:10: warning: conditional expression is constant
+test010.c:30: warning: conditional expression is constant
 output:
 G2	F	"main
 {
--- a/cc1/tests/test011.c
+++ b/cc1/tests/test011.c
@@ -2,8 +2,8 @@
 name: TEST011
 description: Basic test for goto
 error:
-test011.c:14: warning: 'foo' defined but not used
-test011.c:14: warning: 'start' defined but not used
+test011.c:13: warning: 'foo' defined but not used
+test011.c:13: warning: 'start' defined but not used
 output:
 G2	F	"main
 {
--- a/cc1/tests/test012.c
+++ b/cc1/tests/test012.c
@@ -2,7 +2,7 @@
 name: TEST012
 description: Basic switch test
 error:
-test012.c:39: warning: 'foo' defined but not used
+test012.c:38: warning: 'foo' defined but not used
 output:
 G2	F	"main
 {
--- a/cc1/tests/test014.c
+++ b/cc1/tests/test014.c
@@ -2,22 +2,22 @@
 name: TEST014
 description: Basic storage class test
 error:
-test014.c:16: warning: 'a' defined but not used
-test014.c:16: warning: 'k' defined but not used
-test014.c:16: warning: 'j' defined but not used
-test014.c:16: warning: 'i' defined but not used
-test014.c:16: warning: 'h' defined but not used
-test014.c:22: warning: 'par' defined but not used
-test014.c:22: warning: 'par' defined but not used
-test014.c:27: warning: 'par' defined but not used
-test014.c:29: error: incorrect storage class for file-scope declaration
-test014.c:29: error: invalid storage class for function 'd'
-test014.c:32: error: bad storage class in function parameter
-test014.c:33: error: invalid storage class for function 'func4'
-test014.c:34: error: invalid type specification
-test014.c:35: warning: 'f' defined but not used
-test014.c:35: warning: 'par' defined but not used
-test014.c:38: error: conflicting types for 'd'
+test014.c:15: warning: 'a' defined but not used
+test014.c:15: warning: 'k' defined but not used
+test014.c:15: warning: 'j' defined but not used
+test014.c:15: warning: 'i' defined but not used
+test014.c:15: warning: 'h' defined but not used
+test014.c:21: warning: 'par' defined but not used
+test014.c:21: warning: 'par' defined but not used
+test014.c:26: warning: 'par' defined but not used
+test014.c:28: error: incorrect storage class for file-scope declaration
+test014.c:28: error: invalid storage class for function 'd'
+test014.c:31: error: bad storage class in function parameter
+test014.c:32: error: invalid storage class for function 'func4'
+test014.c:33: error: invalid type specification
+test014.c:34: warning: 'f' defined but not used
+test014.c:34: warning: 'par' defined but not used
+test014.c:37: error: conflicting types for 'd'
 output:
 G1	I	"a
 Y2	K	"b
--- a/cc1/tests/test016.c
+++ b/cc1/tests/test016.c
@@ -2,8 +2,8 @@
 name: TEST016
 description: Basic pointer test
 error:
-test016.c:43: error: redefinition of 'func2'
-test016.c:47: error: incompatible types when assigning
+test016.c:42: error: redefinition of 'func2'
+test016.c:46: error: incompatible types when assigning
 output:
 G1	I	"g
 G3	F	"func1
--- a/cc1/tests/test019.c
+++ b/cc1/tests/test019.c
@@ -3,8 +3,8 @@
 name: TEST019
 description: Basic test of constant folding in integer arithmetic operations
 error:
+test019.c:12: warning: division by 0
 test019.c:13: warning: division by 0
-test019.c:14: warning: division by 0
 output:
 G2	F	"main
 {
--- /dev/null
+++ b/cc1/tests/test060.c
@@ -1,0 +1,26 @@
+/*
+name: TEST060
+description: Test for correctness of #line
+error:
+output:
+G2	F	"main
+{
+\
+	r	#I0
+}
+*/
+
+#undef  line
+#define line 1000
+
+#line line
+#if 1000 != __LINE__
+	#error "  # line line" not work as expected
+#endif
+
+int
+main()
+{
+	return 0;
+}
+