This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

const weak variables are inlined.


hello,

This is a problem if the variable is replaced at link time by a strong one, like in:

------ module1
const int  __attribute__((weak)) vaca = 0;

int
f(void)
{
  return vaca;
}

------ module2
#include <stdio.h>

const int vaca = 2;

extern int f(void);

main()
{
  printf ("%d\n", f()); /* should print 2 */
  return 0;
}
------

This patch doesn't consider a value as constant if it is weak.

regtested for i686-pc-linux-gnu and sh-superh-elf.

is it ok ?

thanks,

2008-04-29 Christian Bruel <christian.bruel@st.com>

* gcc.dg/const-weak.c: New testcase.

2008-04-29 Christian Bruel <christian.bruel@st.com>

	* gcc/c-typeck.c (decl_constant_value): check DECL_WEAK.
	* gcc/tree-ssa-ccp.c (get_symbol_constant_value): Likewise.



Attachment: const-weak.c
Description: application/source

Index: gcc/tree-ssa-ccp.c
===================================================================
--- gcc/tree-ssa-ccp.c	(revision 134799)
+++ gcc/tree-ssa-ccp.c	(working copy)
@@ -275,6 +275,7 @@
 {
   if (TREE_STATIC (sym)
       && TREE_READONLY (sym)
+      && !DECL_WEAK (sym)
       && !MTAG_P (sym))
     {
       tree val = DECL_INITIAL (sym);
Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c	(revision 134799)
+++ gcc/c-typeck.c	(working copy)
@@ -1545,6 +1545,7 @@
       && !TREE_THIS_VOLATILE (decl)
       && TREE_READONLY (decl)
       && DECL_INITIAL (decl) != 0
+      && !DECL_WEAK (decl)
       && TREE_CODE (DECL_INITIAL (decl)) != ERROR_MARK
       /* This is invalid if initial value is not constant.
 	 If it has either a function call, a memory reference,

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]