[PATCH] [ms-cxxabi] Implement guard variables for static initialization

Eli Friedman eli.friedman at gmail.com
Tue Aug 20 12:27:20 PDT 2013


On Tue, Aug 20, 2013 at 11:30 AM, Reid Kleckner <rnk at google.com> wrote:

> On Mon, Aug 19, 2013 at 5:51 PM, Eli Friedman <eli.friedman at gmail.com>wrote:
>
>> class MicrosoftFunctionState : public CXXABIFunctionState {
>> public:
>>   MicrosoftFunctionState() : NumGuardedInitsEmitted(0), GuardGV(0) {}
>>   int NumGuardedInitsEmitted;
>>   llvm::GlobalVariable *GuardGV;
>> };
>>
>> This is very suspicious.  For the Itanium ABI, to get this right, we have
>> to track it in the AST.  (See clang::MangleNumberingContext etc.)  A
>> testcase (which we messed up with the Itanium ABI until quite recently):
>>
>> int foo();
>> inline void f() {
>>   if (0) {
>>     static int x = foo();
>>   }
>>   static int x = foo();
>> }
>> void g() { f(); }
>>
>
> Yeah, I get the bit numbers wrong.  What I actually need to do is to
> number all the static local VarDecls in a DeclContext based on source order
> like this:
>
> inline void f() {
>   if (0) {
>     static int x = foo(); // 1
>   }
>   static int x = foo(); // 2
>   static int y = foo(); // 3
>   static int z = foo(); // 4
> }
>
> Maybe what we should do here is ask the AST/CXXABI class to create the
> ManglingNumberContext, and I can provide an implementation for the
> Microsoft C++ ABI.  Sound good?
>

That sounds like the right direction.


>
> ---
>
> By the way, lambdas are mangled totally differently.  David knows more.
>  We think it's some kind of hash of the token stream that clang will
> probably never be able to replicate.  We may have to make up our own
> mangling.
>

Really?  Wow.  (In the Itanium ABI, we number them in source order.)

-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130820/c0735e8e/attachment.html>


More information about the cfe-commits mailing list