From 0e18a035fdb973255cb7a16fe8eed01573cc7861 Mon Sep 17 00:00:00 2001 From: epetrich Date: Wed, 27 Dec 2006 16:28:04 +0000 Subject: [PATCH] * 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 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4531 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 13 ++++++++ src/SDCCsymt.c | 19 +++++++++++ src/SDCCsymt.h | 5 +++ support/Util/SDCCerr.c | 2 ++ support/Util/SDCCerr.h | 2 +- support/valdiag/tests/restrict.c | 57 ++++++++++++++++++++++++++++++++ support/valdiag/tests/tentdecl.c | 2 ++ support/valdiag/valdiag.py | 12 ++++++- 8 files changed, 110 insertions(+), 2 deletions(-) create mode 100644 support/valdiag/tests/restrict.c diff --git a/ChangeLog b/ChangeLog index 1bd07a15..ea4d5c7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2006-12-27 Erik Petrich + + * 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 * support/cpp2/cppmain.c, support/cpp2/mbchar.[ch]: removed @@ -196,6 +208,7 @@ hopefully fixes #1604915 (other device libraries are still affected) 2006-12-10 Erik Petrich + * src/mcs51/ralloc.c (packRegsForAssign), * src/hc08/ralloc.c (packRegsForAssign): fixed bug #1605880 diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index c65c3e2f..ddedaf06 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -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 */ diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index c30beab8..be9fcadd 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -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) diff --git a/support/Util/SDCCerr.c b/support/Util/SDCCerr.c index ef590fb9..6bc3f650 100644 --- a/support/Util/SDCCerr.c +++ b/support/Util/SDCCerr.c @@ -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'" }, }; /* diff --git a/support/Util/SDCCerr.h b/support/Util/SDCCerr.h index ba829ac0..bde43554 100644 --- a/support/Util/SDCCerr.h +++ b/support/Util/SDCCerr.h @@ -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 index 00000000..07683a3c --- /dev/null +++ b/support/valdiag/tests/restrict.c @@ -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 diff --git a/support/valdiag/tests/tentdecl.c b/support/valdiag/tests/tentdecl.c index 60d29862..19297069 100644 --- a/support/valdiag/tests/tentdecl.c +++ b/support/valdiag/tests/tentdecl.c @@ -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 */ diff --git a/support/valdiag/valdiag.py b/support/valdiag/valdiag.py index 370b8b81..74b423bf 100644 --- a/support/valdiag/valdiag.py +++ b/support/valdiag/valdiag.py @@ -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) -- 2.30.2