* src/SDCC.y (type_specifier2, pointer),
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 27 Dec 2006 16:28:04 +0000 (16:28 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 27 Dec 2006 16:28:04 +0000 (16:28 +0000)
* src/SDCCsymt.h,
* src/SDCCsymt.c (mergeSpec, checkSClass),
* support/Util/SDCCerr.c,
* support/Util/SDCCerr.h: Parse and validate the restrict keyword
* support/valdiag/valdiag.py: Allow test cases to specify
  required language standard
* support/valdiag/tests/restrict.c: New file to test restrict keyword
* support/valdiag/tests/tentdecl.c: Supress empty source file error

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4531 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCsymt.c
src/SDCCsymt.h
support/Util/SDCCerr.c
support/Util/SDCCerr.h
support/valdiag/tests/restrict.c [new file with mode: 0644]
support/valdiag/tests/tentdecl.c
support/valdiag/valdiag.py

index 1bd07a15372583e74e06d26c978df8c2804fb01e..ea4d5c7a6b316b2bf04f3b787a2adf8a96031913 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2006-12-27 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
+
+       * src/SDCC.y (type_specifier2, pointer),
+       * src/SDCCsymt.h,
+       * src/SDCCsymt.c (mergeSpec, checkSClass),
+       * support/Util/SDCCerr.c,
+       * support/Util/SDCCerr.h: Parse and validate the restrict keyword
+       * support/valdiag/valdiag.py: Allow test cases to specify
+         required language standard
+       * support/valdiag/tests/restrict.c: New file to test restrict keyword
+       * support/valdiag/tests/tentdecl.c: Supress empty source file error 
+
 2006-12-27 Borut Razem <borut.razem AT siol.net>
 
        * support/cpp2/cppmain.c, support/cpp2/mbchar.[ch]: removed
          hopefully fixes #1604915 (other device libraries are still affected)
 
 2006-12-10 Erik Petrich <epetrich AT ivorytower.norman.ok.us>
+
        * src/mcs51/ralloc.c (packRegsForAssign),
        * src/hc08/ralloc.c (packRegsForAssign): fixed bug #1605880
 
index c65c3e2f965da328d1853bce5a27131d975d9ff4..ddedaf069bf944696f3112d4f8999ab790edf839 100644 (file)
@@ -657,6 +657,7 @@ mergeSpec (sym_link * dest, sym_link * src, char *name)
   SPEC_CONST(dest) |= SPEC_CONST (src);
   SPEC_ABSA (dest) |= SPEC_ABSA (src);
   SPEC_VOLATILE (dest) |= SPEC_VOLATILE (src);
+  SPEC_RESTRICT (dest) |= SPEC_RESTRICT (src);
   SPEC_ADDR (dest) |= SPEC_ADDR (src);
   SPEC_OCLS (dest) = SPEC_OCLS (src);
   SPEC_BLEN (dest) |= SPEC_BLEN (src);
@@ -1443,6 +1444,24 @@ checkSClass (symbol * sym, int isProto)
       SPEC_VOLATILE (sym->etype) = 1;
     }
   
+  /* make sure restrict is only used with pointers */
+  if (SPEC_RESTRICT (sym->etype))
+    {
+      werrorfl (sym->fileDef, sym->lineDef, E_BAD_RESTRICT);
+      SPEC_RESTRICT (sym->etype) = 0;
+    }
+  t = sym->type;
+  while (t)
+    {
+      if (IS_DECL (t) && DCL_PTR_RESTRICT (t) && !IS_PTR (t))
+        {
+          werrorfl (sym->fileDef, sym->lineDef, E_BAD_RESTRICT);
+         DCL_PTR_RESTRICT (t) = 0;
+          break;
+        }
+      t = t->next;
+    }
+  
   /* if absolute address given then it mark it as
      volatile -- except in the PIC port */
 
index c30beab8c1570c0695023c74117c49828f037cab..be9fcadde48a2db79655ba794874158d8852df13 100644 (file)
@@ -158,6 +158,7 @@ typedef struct specifier
     unsigned b_absadr:1;                /* absolute address specfied  */
     unsigned b_volatile:1;              /* is marked as volatile      */
     unsigned b_const:1;                 /* is a constant              */
+    unsigned b_restrict:1;              /* is restricted              */
     unsigned b_typedef:1;               /* is typedefed               */
     unsigned b_isregparm:1;             /* is the first parameter     */
     unsigned b_isenum:1;                /* is an enumerated type      */
@@ -205,6 +206,7 @@ typedef struct declarator
                                         /* always 0 for flexible arrays */
     unsigned ptr_const:1;               /* pointer is constant        */
     unsigned ptr_volatile:1;            /* pointer is volatile        */
+    unsigned ptr_restrict:1;            /* pointer is resticted       */
     struct sym_link *tspec;             /* pointer type specifier     */
   }
 declarator;
@@ -364,6 +366,7 @@ extern sym_link *validateLink(sym_link  *l,
 #define DCL_ELEM(l)  validateLink(l, "DCL_ELEM", #l, DECLARATOR, __FILE__, __LINE__)->select.d.num_elem
 #define DCL_PTR_CONST(l) validateLink(l, "DCL_PTR_CONST", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_const
 #define DCL_PTR_VOLATILE(l) validateLink(l, "DCL_PTR_VOLATILE", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_volatile
+#define DCL_PTR_RESTRICT(l) validateLink(l, "DCL_PTR_RESTRICT", #l, DECLARATOR, __FILE__, __LINE__)->select.d.ptr_restrict
 #define DCL_TSPEC(l) validateLink(l, "DCL_TSPEC", #l, DECLARATOR, __FILE__, __LINE__)->select.d.tspec
 
 #define FUNC_DEBUG //assert(IS_FUNC(x));
@@ -437,6 +440,7 @@ extern sym_link *validateLink(sym_link  *l,
 #define SPEC_ISR_SAVED_BANKS(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s._bitStart
 #define SPEC_VOLATILE(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_volatile
 #define SPEC_CONST(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_const
+#define SPEC_RESTRICT(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_restrict
 #define SPEC_STRUCT(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.v_struct
 #define SPEC_TYPEDEF(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_typedef
 #define SPEC_REGPARM(x) validateLink(x, "SPEC_NOUN", #x, SPECIFIER, __FILE__, __LINE__)->select.s.b_isregparm
@@ -456,6 +460,7 @@ extern sym_link *validateLink(sym_link  *l,
                                      DCL_TYPE(x) == CPOINTER   ||    \
                                      DCL_TYPE(x) == UPOINTER  ))
 #define IS_PTR_CONST(x) (IS_PTR(x) && DCL_PTR_CONST(x))
+#define IS_PTR_RESTRICT(x) (IS_PTR(x) && DCL_PTR_RESTRICT(x))
 #define IS_FARPTR(x) (IS_DECL(x) && DCL_TYPE(x) == FPOINTER)
 #define IS_CODEPTR(x) (IS_DECL(x) && DCL_TYPE(x) == CPOINTER)
 #define IS_GENPTR(x) (IS_DECL(x) && DCL_TYPE(x) == GPOINTER)
index ef590fb99379d760410b432dad3e05373baacbb9..6bc3f65027ae86675987281568845de70bf74475 100644 (file)
@@ -436,6 +436,8 @@ struct
    "ISO C forbids an empty source file" },
 { W_BAD_PRAGMA_ARGUMENTS, ERROR_LEVEL_WARNING,
    "#pragma %s: bad argument(s); pragma ignored" },
+{ E_BAD_RESTRICT, ERROR_LEVEL_ERROR,
+   "Only pointers may be qualified with 'restrict'" },
 };
 
 /*
index ba829ac09e9c9cf0fcc20b05fb36511031b2f9a5..bde43554c391f9e87db75cf3aec8c6f3491db08b 100644 (file)
@@ -207,7 +207,7 @@ SDCCERR - SDCC Standard error handler
 #define E_FLEXARRAY_INEMPTYSTRCT      189 /* flexible array in otherwise empty struct */
 #define W_EMPTY_SOURCE_FILE           190 /* ISO C forbids an empty source file */
 #define W_BAD_PRAGMA_ARGUMENTS        191 /* #pragma %s: bad argument(s); pragma ignored */
-
+#define E_BAD_RESTRICT                192 /* Only pointers may be qualified with 'restrict' */
 #define MAX_ERROR_WARNING             256 /* size of disable warnings array */
 
 /** Describes the maximum error level that will be logged.  Any level
diff --git a/support/valdiag/tests/restrict.c b/support/valdiag/tests/restrict.c
new file mode 100644 (file)
index 0000000..07683a3
--- /dev/null
@@ -0,0 +1,57 @@
+
+/* The restrict keyword can only qualify pointers */
+
+#ifdef TEST1_C99
+restrict a;            /* ERROR */
+#endif
+
+#ifdef TEST2_C99
+restrict int a;                /* ERROR */
+#endif
+
+#ifdef TEST3_C99
+restrict int a[10];    /* ERROR */
+#endif
+
+#ifdef TEST4_C99
+restrict int * a;      /* ERROR */
+#endif
+
+#ifdef TEST5_C99
+restrict struct
+  {
+    int a;
+    int b;
+  } x;                 /* ERROR */
+#endif
+
+#ifdef TEST6_C99
+restrict int func(void) {      /* ERROR */
+  return 0;
+}
+#endif
+
+#ifdef TEST7_C99
+void func(restrict int x) {    /* ERROR */
+  x;                           /* IGNORE */
+}
+#endif
+
+
+#ifdef TEST_GOOD1_C99
+int * restrict a;
+#endif
+
+#ifdef TEST_GOOD2_C99
+int * func(int * restrict x)
+{
+  return x;
+}
+#endif
+
+#ifdef TEST_GOOD3_C99
+void func(int * restrict x)
+{
+  x;                           /* IGNORE */
+}
+#endif
index 60d29862fcdd929dbba97ce972b4da75374af4ce..192970695acbddc72130ddb948750240b95da8d7 100644 (file)
@@ -117,3 +117,5 @@ extern volatile XDATA at 0 int a; /* IGNORE */
 volatile XDATA int a;  /* ERROR(SDCC && !(__z80 || __gbz80)) */
 #endif
 #endif
+
+int validDeclaraction;  /* to make sure this is never an empty source file */
index 370b8b8112168a57754b33ddba4cdd2dde95bfd2..74b423bf468518e3f8490c445c39379499c777c4 100644 (file)
@@ -31,6 +31,8 @@ gcc = {
     "CCFLAGS":"-c -Wall -DPORT_HOST=1",
     "CCDEF":"-D",
     "CCOUTPUT":"-o",
+    "C89":"-std=c89",
+    "C99":"-std=c99",
     "defined": {
         "__GNUC__":"1",
         "GCC":"1"
@@ -44,6 +46,8 @@ sdcc = {
     "CCFLAGS":"-c -m{port}",
     "CCDEF":"-D",
     "CCOUTPUT":"-o",
+    "C89":"--std-sdcc89",
+    "C99":"--std-sdcc99",
     "defined": {
         "SDCC":"1",
         "SDCC_{port}":"1",
@@ -267,7 +271,13 @@ failurecount = 0
 
 for testname in testcases.keys():
     ccdef = compilermode["CCDEF"]+testname
-    cmd = string.join([cc,ccflags,ccdef,inputfilename])
+    if testname[-3:] == "C89":
+        ccstd = compilermode["C89"]
+    elif testname[-3:] == "C99":
+        ccstd = compilermode["C99"]
+    else:
+        ccstd = ""
+    cmd = string.join([cc,ccflags,ccstd,ccdef,inputfilename])
     print
     print cmd
     spawn = popen2.Popen4(cmd)