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

Reid Kleckner rnk at google.com
Tue Aug 20 11:30:10 PDT 2013


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?

---

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130820/e7e7171f/attachment.html>


More information about the cfe-commits mailing list