[hackers] [scc] Fix #line directive || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Sun, 24 Jan 2016 16:19:19 +0100 (CET)

commit 65d393be241273b385ef13c463cd4ada5aa74e62
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Sun Jan 24 08:28:43 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Sun Jan 24 08:34:36 2016 +0100

    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.

diff --git a/cc1/cpp.c b/cc1/cpp.c
index 240ed4e..4885f13 100644
--- a/cc1/cpp.c
+++ b/cc1/cpp.c
_AT_@ -520,6 +520,7 @@ line(void)
         if (cppoff)
                 return;
 
+ disexpand = 0;
         next();
         n = strtol(yytext, &endp, 10);
         if (n <= 0 || n > USHRT_MAX || *endp != '\0') {
_AT_@ -541,7 +542,7 @@ line(void)
         next();
 
 set_line:
- input->nline = n;
+ input->nline = n - 1;
 }
 
 static void
diff --git a/cc1/symbol.c b/cc1/symbol.c
index ee8d8b7..a1695c8 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
_AT_@ -271,7 +271,7 @@ lookup(int ns, char *name)
                  * 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;
diff --git a/cc1/tests/test006.c b/cc1/tests/test006.c
index 880932d..d504d84 100644
--- a/cc1/tests/test006.c
+++ b/cc1/tests/test006.c
_AT_@ -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
diff --git a/cc1/tests/test010.c b/cc1/tests/test010.c
index fe9eb6c..cafad7a 100644
--- a/cc1/tests/test010.c
+++ b/cc1/tests/test010.c
_AT_@ -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
 {
diff --git a/cc1/tests/test011.c b/cc1/tests/test011.c
index 8f35f8b..0dc344d 100644
--- a/cc1/tests/test011.c
+++ b/cc1/tests/test011.c
_AT_@ -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
 {
diff --git a/cc1/tests/test012.c b/cc1/tests/test012.c
index d9abf47..2c76c85 100644
--- a/cc1/tests/test012.c
+++ b/cc1/tests/test012.c
_AT_@ -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
 {
diff --git a/cc1/tests/test014.c b/cc1/tests/test014.c
index e6d52b6..b266b60 100644
--- a/cc1/tests/test014.c
+++ b/cc1/tests/test014.c
_AT_@ -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
diff --git a/cc1/tests/test016.c b/cc1/tests/test016.c
index b3ff1e1..830c413 100644
--- a/cc1/tests/test016.c
+++ b/cc1/tests/test016.c
_AT_@ -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
diff --git a/cc1/tests/test019.c b/cc1/tests/test019.c
index ecb39be..2999418 100644
--- a/cc1/tests/test019.c
+++ b/cc1/tests/test019.c
_AT_@ -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
 {
diff --git a/cc1/tests/test060.c b/cc1/tests/test060.c
new file mode 100644
index 0000000..9883c07
--- /dev/null
+++ b/cc1/tests/test060.c
_AT_@ -0,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;
+}
+
Received on Sun Jan 24 2016 - 16:19:19 CET

This archive was generated by hypermail 2.3.0 : Sun Jan 24 2016 - 16:24:21 CET