On 03/27/2018 01:17 AM, Tom de Vries wrote: > On 03/26/2018 11:57 PM, Cesar Philippidis wrote: >> As noted in PR85056, the nvptx BE isn't declaring external arrays using >> PTX array notation. Specifically, it's emitting code that's missing the >> empty angle brackets '[]'. > > [ FYI, see https://en.wikipedia.org/wiki/Bracket > > For '[]' I find "square brackets, closed brackets, hard brackets, third > brackets, crotchets, or brackets (US)". > > Angle brackets are different symbols. ]
Sorry, you're correct. I meant square brackets. >> This patch corrects that problem. >> >> Tom, in contrast to my earlier patch in the PR, this patch only >> considers external arrays. The patch I posted incorrectly handled >> zero-length arrays and empty structs. >> >> I tested this patch with a standalone nvptx toolchain using newlib 3.0, >> and I found no new regressions. However I'm still waiting for the >> results that are using the older version of newlib. Is this patch OK for >> trunk if the results come back clean? >> > > OK for stage4 trunk. Can I backport this patch to GCC 6 and 7? That fix is necessary to build an updated version of newlib that I'm working on. Thanks, Cesar > [ A minor style nit: in submission emails, rather than having the very > specific but rather non-descriptive subject "Fix PR85056", move the PR > number to "[PATCH,nvptx,PR85056]" and add a subject line that describes > the nature of the patch, f.i.: "Fix declaration of external array with > unknown size". > > So, something like: > ... > [PATCH,nvptx,PR85056] Fix declaration of external array with unknown size > ... > > Then, use the subject line as commit log header line (dropping "PATCH", > and the PR number): > ... > [nvptx] Fix declaration of external array with unknown size > ... > ] > > Thanks, > - Tom > >> Thanks, >> Cesar >> >> >> nvptx-extern-arrays.diff >> >> >> 2018-03-26 Cesar Philippidis <ce...@codesourcery.com> >> >> gcc/ >> >> PR target/85056 >> * config/nvptx/nvptx.c (nvptx_assemble_decl_begin): Add '[]' to >> extern array declarations. >> >> gcc/testsuite/ >> * testsuite/gcc.target/nvptx/pr85056.c: New test. >> * testsuite/gcc.target/nvptx/pr85056a.c: New test. >> >> >> diff --git a/gcc/config/nvptx/nvptx.c b/gcc/config/nvptx/nvptx.c >> index 3cb33ae8c2d..38f25add6ab 100644 >> --- a/gcc/config/nvptx/nvptx.c >> +++ b/gcc/config/nvptx/nvptx.c >> @@ -2038,6 +2038,9 @@ static void >> nvptx_assemble_decl_begin (FILE *file, const char *name, const char >> *section, >> const_tree type, HOST_WIDE_INT size, unsigned align) >> { >> + bool atype = (TREE_CODE (type) == ARRAY_TYPE) >> + && (TYPE_DOMAIN (type) == NULL_TREE); >> + >> while (TREE_CODE (type) == ARRAY_TYPE) >> type = TREE_TYPE (type); >> @@ -2077,6 +2080,8 @@ nvptx_assemble_decl_begin (FILE *file, const >> char *name, const char *section, >> /* We make everything an array, to simplify any initialization >> emission. */ >> fprintf (file, "[" HOST_WIDE_INT_PRINT_DEC "]", >> init_frag.remaining); >> + else if (atype) >> + fprintf (file, "[]"); >> } >> /* Called when the initializer for a decl has been completely >> output through >> diff --git a/gcc/testsuite/gcc.target/nvptx/pr85056.c >> b/gcc/testsuite/gcc.target/nvptx/pr85056.c >> new file mode 100644 >> index 00000000000..fe7f8af856e >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/nvptx/pr85056.c >> @@ -0,0 +1,20 @@ >> +/* { dg-do run } */ >> +/* { dg-additional-sources "pr85056a.c" } */ >> + >> +extern void abort (); >> + >> +extern int a[]; >> + >> +int >> +main () >> +{ >> + int i, sum; >> + >> + for (i = 0; i < 10; i++) >> + sum += a[i]; >> + >> + if (sum != 55) >> + abort (); >> + >> + return 0; >> +} >> diff --git a/gcc/testsuite/gcc.target/nvptx/pr85056a.c >> b/gcc/testsuite/gcc.target/nvptx/pr85056a.c >> new file mode 100644 >> index 00000000000..a45a5f2b07f >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/nvptx/pr85056a.c >> @@ -0,0 +1,3 @@ >> +/* { dg-skip-if "" { *-*-* } } */ >> + >> +int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; >> >