From d36f31dcff21f84c5f1f65ae8b0e07e989a6cee3 Mon Sep 17 00:00:00 2001 From: Greg King Date: Sat, 8 Aug 2015 22:04:38 -0400 Subject: [PATCH 1/4] Improved the format of the global symbols' lists of flags, in cc65's debugging output. --- src/cc65/symentry.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cc65/symentry.c b/src/cc65/symentry.c index aa5949f97..980ee27f2 100644 --- a/src/cc65/symentry.c +++ b/src/cc65/symentry.c @@ -126,19 +126,19 @@ void DumpSymEntry (FILE* F, const SymEntry* E) /* Print the assembler name if we have one */ if (E->AsmName) { fprintf (F, " AsmName: %s\n", E->AsmName); - } + } /* Print the flags */ SymFlags = E->Flags; - fprintf (F, " Flags: "); + fprintf (F, " Flags:"); for (I = 0; I < sizeof (Flags) / sizeof (Flags[0]) && SymFlags != 0; ++I) { if ((SymFlags & Flags[I].Val) == Flags[I].Val) { SymFlags &= ~Flags[I].Val; - fprintf (F, "%s ", Flags[I].Name); + fprintf (F, " %s", Flags[I].Name); } } if (SymFlags != 0) { - fprintf (F, "%04X", SymFlags); + fprintf (F, " 0x%05X", SymFlags); } fprintf (F, "\n"); From 4e9842ef33789dae702302509d6c6b8d0acccb13 Mon Sep 17 00:00:00 2001 From: Greg King Date: Sun, 9 Aug 2015 06:27:05 -0400 Subject: [PATCH 2/4] Stopped extern declarations from changing previous static, but otherwise identical, declarations. --- src/cc65/symtab.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 1f63e9430..0e4de4ea2 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -813,6 +813,11 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags) } } + /* An extern declaration must not change the current linkage. */ + if (IsFunc || (Flags & (SC_EXTERN | SC_DEF)) == SC_EXTERN) { + Flags &= ~SC_EXTERN; + } + /* Add the new flags */ Entry->Flags |= Flags; From 6032849e60dfa51ab1f39f99845d75a07c6e4e10 Mon Sep 17 00:00:00 2001 From: Greg King Date: Mon, 10 Aug 2015 13:39:17 -0400 Subject: [PATCH 3/4] Added warning diagnostics for conflicts between extern/public and static declarations. --- src/cc65/symtab.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 0e4de4ea2..fdf459873 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -813,11 +813,25 @@ SymEntry* AddGlobalSym (const char* Name, const Type* T, unsigned Flags) } } + /* If a static declaration follows a non-static declaration, then + ** warn about the conflict. (It will compile a public declaration.) + */ + if ((Flags & SC_EXTERN) == 0 && (Entry->Flags & SC_EXTERN) != 0) { + Warning ("static declaration follows non-static declaration of `%s'.", Name); + } + /* An extern declaration must not change the current linkage. */ if (IsFunc || (Flags & (SC_EXTERN | SC_DEF)) == SC_EXTERN) { Flags &= ~SC_EXTERN; } + /* If a public declaration follows a static declaration, then + ** warn about the conflict. (It will compile a public declaration.) + */ + if ((Flags & SC_EXTERN) != 0 && (Entry->Flags & SC_EXTERN) == 0) { + Warning ("public declaration follows static declaration of `%s'.", Name); + } + /* Add the new flags */ Entry->Flags |= Flags; From 1baecf4a155842defd64d406de5b56f19a99859b Mon Sep 17 00:00:00 2001 From: Greg King Date: Thu, 13 Aug 2015 03:39:35 -0400 Subject: [PATCH 4/4] Added regression tests of diagnostics for conflicts between extern/public and static declarations. --- test/err/static-2.c | 20 ++++++++++++++++++++ test/err/static-3.c | 20 ++++++++++++++++++++ test/err/static-4.c | 20 ++++++++++++++++++++ test/val/static-1.c | 20 ++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 test/err/static-2.c create mode 100644 test/err/static-3.c create mode 100644 test/err/static-4.c create mode 100644 test/val/static-1.c diff --git a/test/err/static-2.c b/test/err/static-2.c new file mode 100644 index 000000000..c89097825 --- /dev/null +++ b/test/err/static-2.c @@ -0,0 +1,20 @@ +/* + !!DESCRIPTION!! global non-static and static conflicts + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +#pragma warn(error, on) + +int n; +static int n; /* should give an error */ + +int main(void) +{ + return n; +} diff --git a/test/err/static-3.c b/test/err/static-3.c new file mode 100644 index 000000000..5b6839a6a --- /dev/null +++ b/test/err/static-3.c @@ -0,0 +1,20 @@ +/* + !!DESCRIPTION!! global non-static and static conflicts + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +#pragma warn(error, on) + +extern int n; +static int n; /* should give an error */ + +int main(void) +{ + return n; +} diff --git a/test/err/static-4.c b/test/err/static-4.c new file mode 100644 index 000000000..a2cdeb78a --- /dev/null +++ b/test/err/static-4.c @@ -0,0 +1,20 @@ +/* + !!DESCRIPTION!! global non-static and static conflicts + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +#pragma warn(error, on) + +static int n; +int n; /* should give an error */ + +int main(void) +{ + return n; +} diff --git a/test/val/static-1.c b/test/val/static-1.c new file mode 100644 index 000000000..ae2ba6289 --- /dev/null +++ b/test/val/static-1.c @@ -0,0 +1,20 @@ +/* + !!DESCRIPTION!! global non-static and static conflicts + !!ORIGIN!! cc65 regression tests + !!LICENCE!! Public Domain + !!AUTHOR!! Greg King +*/ + +/* + see: https://github.com/cc65/cc65/issues/191 +*/ + +#pragma warn(error, on) + +static int n = 0; +extern int n; /* should not give an error */ + +int main(void) +{ + return n; +}