[cfe-dev] Sema && redefinitions

Douglas Gregor dgregor at apple.com
Thu Dec 4 17:37:40 PST 2008


On Dec 5, 2008, at 3:56 AM, Anton Korobeynikov wrote:

> Hello, Everyone
>
> We faced with the following problem trying to add sema checks for
> dllimport / dllexport attributes.
>
> Consider the following situation:
>
> void __attribute__((dllimport)) foo();
>
> void foo() {
> }
>
> In this situation we need to ignore dllimport attribute everywhere and
> issue warning. The problem is that at the point, when we just saw the
> body of foo() w/o dllimport attribute - all attributes were already
> merged in and thus we cannot distinguish declaration and redefintion.

Couldn't you just scan the getPreviousDeclaration() chain backward, to  
find the first declaration of this function that contains the  
dllimport attribute? You can complain about that declaration, then  
remove the attribute from all of the declarations to silence any  
further warnings.

> Another approach is the store first decl somewhere and process in the
> late end of sema. But then we faced with one problem... How one can
> obtain definition of 'foo' given a first declaration? It seems, that
> getPreviousDeclaration() works only backward, is there way to obtain  
> the
> definition?

If you've processed the whole translation unit, you could look up the  
most recent declaration of 'foo' and call getBody on it to find the  
definition.

	- Doug



More information about the cfe-dev mailing list