[cfe-commits] review only please: allow #pragma weak to refer to undeclared identifier

Douglas Gregor dgregor at apple.com
Thu Jul 23 12:55:26 PDT 2009


Hi Ryan,

On Jul 21, 2009, at 10:18 PM, Ryan Flynn wrote:

> i'll commit-after-approval, in that unlikely event.
>
> this is a fairly ugly hack to address this bug:
>
> http://llvm.org/bugs/show_bug.cgi?id=3679
>
> it has the upside of getting FreeBSD's libc and others closer to  
> compiling.

Thanks for taking a shot at this!

> it has the downside that it is fairly ugly and also introduces an
> issue whereby we don't error on incompatible declarations with weak
> attributes, an example is given in the test file.

The introduction of the dummy declaration with a "weak" attribute  
probably isn't going to work in the general case, because there are so  
many ways that new declarations can be introduced (especially in C++),  
and we'll end up playing whack-a-mole.

How about a different approach: when we see a #pragma weak that refers  
to a name that hasn't yet been declared, just put the information  
provided to ActOnPragmaWeakID in a table on the side. Then, whenever a  
new top-level declaration is completed, look into that table to see if  
there's a pending #pragma weak that refers to that name If so, you can  
just call ActOnPragmaWeakID again with the stored information and  
remove the corresponding entry from the table. For bonus points, if  
the table is non-empty at the end of the translation unit, print  
warnings about "pragma weak does not refer to any declaration 'blah'".

For the test cases, I have a few minor comments:
   1) Please don't excerpt code from other projects. It's okay to use  
the form of the code to create a test case, but typically we change  
the names and remove any bits that aren't necessary to test what we're  
trying to test.
   2)The -emit-llvm test should send its results to a temporary file  
(%t), and then there should be RUN lines that grep (or FileCheck) for  
each of the weak declarations.

	- Doug



More information about the cfe-commits mailing list