public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/35835]  New: Compiler fails to recognize match of local "extern" declarations
@ 2008-04-05 18:33 oder at eleks dot lviv dot ua
  2008-04-05 19:56 ` [Bug c++/35835] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: oder at eleks dot lviv dot ua @ 2008-04-05 18:33 UTC (permalink / raw)
  To: gcc-bugs

Consider following program
======= begin of test.cpp ========
#include <stdio.h>

static inline void SetValue(int i)
{
  extern int g_iValue;

  g_iValue = i;
}

static inline int GetValue()
{
  extern int g_iValue;

  return g_iValue;
}



int g_iValue = 0;


int main()
{
  int iValueSave = GetValue();

  SetValue(1);
  printf("%d\n", GetValue());

  SetValue(iValueSave);

  return 0;
}
======= end of test.cpp ========
I use this apptoach to only publish get/set global variable accessors in header
while keeping variable itself hidden in cpp.

If compiled with optimizations turned on, compiler fails identify two local
"extern" declarations as a single memory object and uses initial value
retrieved for iValueSafe in call to printf as well (as if SetValue() was
unrelated to g_iValue).

If compiled and run, program outputs 0 instead of 1.
osx-leopard:build oder$ g++ -O3 -o test test.cpp
osx-leopard:build oder$ ./test
0

Output of "g++ -v" is:
Using built-in specs.
Target: powerpc-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5478~1/src/configure --disable-checking
-enable-werror --prefix=/usr --mandir=/share/man
--enable-languages=c,objc,c++,obj-c++
--program-transform-name=/^[cg][^.-]*$/s/$/-4.0/
--with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib
--build=powerpc-apple-darwin9 --host=powerpc-apple-darwin9
--target=powerpc-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5478)


-- 
           Summary: Compiler fails to recognize match of local "extern"
                    declarations
           Product: gcc
           Version: 4.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: oder at eleks dot lviv dot ua
 GCC build triplet: ppc
  GCC host triplet: ppc
GCC target triplet: ppc


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35835


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/35835] Compiler fails to recognize match of local "extern" declarations
  2008-04-05 18:33 [Bug c++/35835] New: Compiler fails to recognize match of local "extern" declarations oder at eleks dot lviv dot ua
@ 2008-04-05 19:56 ` pinskia at gcc dot gnu dot org
  2008-04-05 20:02 ` oder at eleks dot lviv dot ua
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-04-05 19:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2008-04-05 19:56 -------
First, this bug should be filed with Apple as you are using Apple's modified
compiler.  Second 4.0.x is no longer being maintained, so please try 4.1.x.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35835


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/35835] Compiler fails to recognize match of local "extern" declarations
  2008-04-05 18:33 [Bug c++/35835] New: Compiler fails to recognize match of local "extern" declarations oder at eleks dot lviv dot ua
  2008-04-05 19:56 ` [Bug c++/35835] " pinskia at gcc dot gnu dot org
@ 2008-04-05 20:02 ` oder at eleks dot lviv dot ua
  2008-04-05 20:05 ` [Bug middle-end/35835] " pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: oder at eleks dot lviv dot ua @ 2008-04-05 20:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from oder at eleks dot lviv dot ua  2008-04-05 20:02 -------
(In reply to comment #1)
> First, this bug should be filed with Apple as you are using Apple's modified
> compiler.  Second 4.0.x is no longer being maintained, so please try 4.1.x.

I don't have root access to the build machine and I can only use the version of
compiler which is installed there.

Also, I don't think the problem is related to target platform. It should be
reproduceable on all the platforms. 
If you can't try it yourself, I can run the test on SunOS or Linux tomorrow.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35835


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/35835] Compiler fails to recognize match of local "extern" declarations
  2008-04-05 18:33 [Bug c++/35835] New: Compiler fails to recognize match of local "extern" declarations oder at eleks dot lviv dot ua
  2008-04-05 19:56 ` [Bug c++/35835] " pinskia at gcc dot gnu dot org
  2008-04-05 20:02 ` oder at eleks dot lviv dot ua
@ 2008-04-05 20:05 ` pinskia at gcc dot gnu dot org
  2008-04-05 20:59 ` rguenth at gcc dot gnu dot org
  2008-04-05 21:16 ` [Bug c++/35835] " pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-04-05 20:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2008-04-05 20:05 -------
(In reply to comment #2)
> I don't have root access to the build machine and I can only use the version of
> compiler which is installed there.

You don't need root access to install a newer version of GCC.  You can
configure GCC with --prefix=${HOME}/gcc-4.3 if you wanted.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |middle-end


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35835


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug middle-end/35835] Compiler fails to recognize match of local "extern" declarations
  2008-04-05 18:33 [Bug c++/35835] New: Compiler fails to recognize match of local "extern" declarations oder at eleks dot lviv dot ua
                   ` (2 preceding siblings ...)
  2008-04-05 20:05 ` [Bug middle-end/35835] " pinskia at gcc dot gnu dot org
@ 2008-04-05 20:59 ` rguenth at gcc dot gnu dot org
  2008-04-05 21:16 ` [Bug c++/35835] " pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-04-05 20:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2008-04-05 20:58 -------
(works with the C frontend)

We don't share the decls of g_iValue properly, but doesn't this program
violate the ODR anyway?

void SetValue(int) (iD.2309)
{
<bb 2>:
  g_iValueD.2312 ={v} iD.2309_1(D);
  return;

}

int GetValue() ()
{
  intD.2 D.2316;

<bb 2>:
  D.2316_1 = g_iValueD.2315;
  return D.2316_1;

}

int main() ()
{
  intD.2 D.2333;
  intD.2 D.2333;
  intD.2 iValueSaveD.2320;

<bb 2>:
  iValueSaveD.2320_6 = g_iValueD.2315;
  g_iValueD.2312 ={v} 1;
  D.2333_7 = g_iValueD.2315;
  printf (&"%d\n"[0], D.2333_7);
  g_iValueD.2312 ={v} iValueSaveD.2320_6;
  return 0;

}


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35835


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/35835] Compiler fails to recognize match of local "extern" declarations
  2008-04-05 18:33 [Bug c++/35835] New: Compiler fails to recognize match of local "extern" declarations oder at eleks dot lviv dot ua
                   ` (3 preceding siblings ...)
  2008-04-05 20:59 ` rguenth at gcc dot gnu dot org
@ 2008-04-05 21:16 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-04-05 21:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2008-04-05 21:16 -------
(In reply to comment #4)
> (works with the C frontend)
> We don't share the decls of g_iValue properly, but doesn't this program
> violate the ODR anyway?

No it does not as there is only one g_iValue variable.  The reasoning behind
using extern int g_iValue; is so it does not get into the global scope. 

The reason why the C front-end works is because we have a non TU scope which we
add decls to and then look up global decls that way and get that decl instead
of creating a new one.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2008-04-05 21:16:01
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35835


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/35835] Compiler fails to recognize match of local "extern" declarations
       [not found] <bug-35835-4@http.gcc.gnu.org/bugzilla/>
  2021-12-17 11:48 ` pinskia at gcc dot gnu.org
@ 2021-12-20  8:11 ` egallager at gcc dot gnu.org
  1 sibling, 0 replies; 8+ messages in thread
From: egallager at gcc dot gnu.org @ 2021-12-20  8:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35835

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |egallager at gcc dot gnu.org

--- Comment #7 from Eric Gallager <egallager at gcc dot gnu.org> ---
(this bug is a good example of why I think -Wnested-externs should be enabled
by -Wall or -Wextra, btw)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/35835] Compiler fails to recognize match of local "extern" declarations
       [not found] <bug-35835-4@http.gcc.gnu.org/bugzilla/>
@ 2021-12-17 11:48 ` pinskia at gcc dot gnu.org
  2021-12-20  8:11 ` egallager at gcc dot gnu.org
  1 sibling, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-17 11:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35835

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |11.0
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED
      Known to fail|                            |10.3.0
           Keywords|                            |needs-bisection
      Known to work|                            |11.1.0

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed for GCC 11 by r11-3699-g4e62aca0e0520e4ed2532f2d815358.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-12-20  8:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-05 18:33 [Bug c++/35835] New: Compiler fails to recognize match of local "extern" declarations oder at eleks dot lviv dot ua
2008-04-05 19:56 ` [Bug c++/35835] " pinskia at gcc dot gnu dot org
2008-04-05 20:02 ` oder at eleks dot lviv dot ua
2008-04-05 20:05 ` [Bug middle-end/35835] " pinskia at gcc dot gnu dot org
2008-04-05 20:59 ` rguenth at gcc dot gnu dot org
2008-04-05 21:16 ` [Bug c++/35835] " pinskia at gcc dot gnu dot org
     [not found] <bug-35835-4@http.gcc.gnu.org/bugzilla/>
2021-12-17 11:48 ` pinskia at gcc dot gnu.org
2021-12-20  8:11 ` egallager at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).