Le-Chun Wu | 18 Jul 19:21

How to determine if a decl is a class member in GCC

Hi,

In my attribute handlers that handle the new thread-safety attributes
(in c-common.c), I need to check if a decl is a class member. How do
people do that? My original code was checking if a decl is a
FIELD_DECL but that doesn't work for static members. I also tried to
use DECL_CONTEXT but it is not set (in the C++ front-end) for data
members. (I was able to use DECL_CONTEXT for member functions,
though.) Is there any other way that I should use?

BTW, as an experiment, I went ahead and made the following change in
C++ front-end to set the DECL_CONTEXT of class data members. The patch
appears to work and doesn't seem to break any g++ and gcc regression
tests. (I will be running gdb testsuite later.) I think there must be
a reason why the DECL_CONTEXT of data members wasn't set in the
front-end, but it's not clear to my why. Can someone kindly explain
why that is and whether the patch is OK?

Thanks,

Le-chun

Index: cp/decl.c
===================================================================
--- cp/decl.c   (revision 137849)
+++ cp/decl.c   (working copy)
@@ -9074,6 +9074,11 @@ grokdeclarator (const cp_declarator *dec

               if (thread_p)
                 DECL_TLS_MODEL (decl) = decl_default_tls_model (decl);
(Continue reading)

Le-Chun Wu | 22 Jul 02:25

Re: How to determine if a decl is a class member in GCC

Hi,

I haven't heard anything back on my questions. Can any of C++ frontend
maintainers please shed some light (or comment on my proposed patch)?
Thanks a lot.

Le-chun

On Fri, Jul 18, 2008 at 10:22 AM, Le-Chun Wu <lcwu <at> google.com> wrote:
> Hi,
>
> In my attribute handlers that handle the new thread-safety attributes
> (in c-common.c), I need to check if a decl is a class member. How do
> people do that? My original code was checking if a decl is a
> FIELD_DECL but that doesn't work for static members. I also tried to
> use DECL_CONTEXT but it is not set (in the C++ front-end) for data
> members. (I was able to use DECL_CONTEXT for member functions,
> though.) Is there any other way that I should use?
>
> BTW, as an experiment, I went ahead and made the following change in
> C++ front-end to set the DECL_CONTEXT of class data members. The patch
> appears to work and doesn't seem to break any g++ and gcc regression
> tests. (I will be running gdb testsuite later.) I think there must be
> a reason why the DECL_CONTEXT of data members wasn't set in the
> front-end, but it's not clear to my why. Can someone kindly explain
> why that is and whether the patch is OK?
>
> Thanks,
>
> Le-chun
(Continue reading)

Benjamin Smedberg | 22 Jul 21:34

Re: How to determine if a decl is a class member in GCC

Le-Chun Wu wrote:
> Hi,
> 
> I haven't heard anything back on my questions. Can any of C++ frontend
> maintainers please shed some light (or comment on my proposed patch)?
> Thanks a lot.
> 
> Le-chun
> 
> On Fri, Jul 18, 2008 at 10:22 AM, Le-Chun Wu <lcwu <at> google.com> wrote:
>> Hi,
>>
>> In my attribute handlers that handle the new thread-safety attributes
>> (in c-common.c), I need to check if a decl is a class member. How do
>> people do that? My original code was checking if a decl is a
>> FIELD_DECL but that doesn't work for static members. I also tried to
>> use DECL_CONTEXT but it is not set (in the C++ front-end) for data
>> members. (I was able to use DECL_CONTEXT for member functions,
>> though.) Is there any other way that I should use?

I created a simple testcase for treehydra and it seems that DECL_CONTEXT was 
set and correct for all of the following in 4.3.0:

struct A {
   int a;
   int f();
   static int sa;
   static int sf();
};

(Continue reading)

Le-Chun Wu | 22 Jul 23:40

Re: How to determine if a decl is a class member in GCC

Benjamin,

Thanks for looking into this issue. I see what's going on here. It's
basically a phase ordering problem. I am trying to determine whether a
declaration is a class member when attributes are parsed and handled
(in c-common.c), which happens earlier than where the context of a
data member is set (which takes place either in
finish_static_data_member_decl or finish_member_declaration). Do you
know of any way to determine whether a decl is a class member when we
are parsing the decl attributes?

Thanks,

Le-chun

On Tue, Jul 22, 2008 at 12:34 PM, Benjamin Smedberg
<bsmedberg <at> mozilla.com> wrote:
> Le-Chun Wu wrote:
>>
>> Hi,
>>
>> I haven't heard anything back on my questions. Can any of C++ frontend
>> maintainers please shed some light (or comment on my proposed patch)?
>> Thanks a lot.
>>
>> Le-chun
>>
>> On Fri, Jul 18, 2008 at 10:22 AM, Le-Chun Wu <lcwu <at> google.com> wrote:
>>>
>>> Hi,
(Continue reading)

Benjamin Smedberg | 23 Jul 00:22

Re: How to determine if a decl is a class member in GCC

Le-Chun Wu wrote:
> Benjamin,
> 
> Thanks for looking into this issue. I see what's going on here. It's
> basically a phase ordering problem. I am trying to determine whether a
> declaration is a class member when attributes are parsed and handled
> (in c-common.c), which happens earlier than where the context of a
> data member is set (which takes place either in
> finish_static_data_member_decl or finish_member_declaration). Do you
> know of any way to determine whether a decl is a class member when we
> are parsing the decl attributes?

I don't know for certain, but you could certainly try current_class_type, 
which is derived from the scope chain.

--BDS


Gmane