First Last Prev Next    No search results available
Details
: [cbackend] Static globals are prototyped as 'extern'
Bug#: 472
: libraries
: Backend: C
Status: RESOLVED
Resolution: FIXED
: All
: All
: 1.0
: P2
: normal
: 1.4

:
: compile-fail
:
:
  Show dependency tree - Show dependency graph
People
Reporter: Markus F.X.J. Oberhumer <markus@oberhumer.com>
Assigned To: Chris Lattner <sabre@nondot.org>

Attachments


Note

You need to log in before you can comment on or make changes to this bug.

Related actions


Description:   Opened: 2004-12-03 11:11
The C writer currently generates invalid C code (static followed by extern which
will be an error in gcc-4.0, see also http://gcc.gnu.org/PR18799 ).

For example:

static char msg[] = "hello";
char *foo(void) { return msg; }


gets translated into:


/* Global Variable Declarations */
extern signed char l1__2E_msg_1[6];

/* Global Variable Definitions and Initialization */
static signed char l1__2E_msg_1[6] = "hello";

/* Function Bodies */
signed char *foo(void) {

  return (&(l1__2E_msg_1[0]));
}


A fix would be to emit a static forward declaration instead of extern. And even
better - though this might not be easy - the static forward declaration should
only be emitted if it is actually needed as they are invalid in C++.
------- Comment #1 From Chris Lattner 2004-12-03 11:13:12 -------
Mine.
------- Comment #2 From Chris Lattner 2004-12-03 11:19:39 -------
Fixed.  Testcase here:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20041129/021616.html

Patch here:
http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20041129/021617.html

Thanks a lot for noticing this!

-Chris

First Last Prev Next    No search results available