[cfe-dev] Gobal register variables marked local

Reid Kleckner rnk at google.com
Fri May 9 10:40:38 PDT 2014


On Fri, May 9, 2014 at 10:19 AM, Renato Golin <renato.golin at linaro.org>wrote:

> On 9 May 2014 18:14, Reid Kleckner <rnk at google.com> wrote:
> > Please don't make VarDecl ~4 bytes bigger just to support a rarely used
> gnu
> > extension.
>
> Hi Reid,
>
> As I said, that's just a marker to help me find the right decl while
> debugging. I wouldn't leave it in the final patch.


Sorry, reading is hard.

> I think it might be better to model the asm blob as an initializer, which
> > would save space and fix your tentative definition problems.
>
> The problem is that this "variable" will never be properly initialized
> because it only refers to access to a register. So, what I need to do
> is to keep the VarDecl around, maybe even lying about it's
> initialization status, and detect that the variable is a named
> register (SC_Register + AsmLableAttr) and emit the intrinsic instead.
>
> I'm looking for the common place where all the reads/writes to
> variables get lowered, so that I only change in one/two place/s.
>

It's not just lib/CodeGen/CGExpr.cpp?  That seems like the kind of place
where we'd lower a regular old DeclRefExpr referring to a local or global
variable.

It looks like Sema is confused with your variable because it has
SC_Register for its storage class, which makes hasGlobalStorage() return
false.  This is the relevant code:

  /// hasLocalStorage - Returns true if a variable with function scope
  ///  is a non-static local variable.
  bool hasLocalStorage() const {
    if (getStorageClass() == SC_None)
      // Second check is for C++11 [dcl.stc]p4.
      return !isFileVarDecl() && getTSCSpec() == TSCS_unspecified;

    // Return true for:  Auto, Register.
    // Return false for: Extern, Static, PrivateExtern,
OpenCLWorkGroupLocal.

    return getStorageClass() >= SC_Auto;
  }
...
  /// \brief Returns true for all variables that do not have local storage.
  ///
  /// This includes all global variables as well as static variables
declared
  /// within a function.
  bool hasGlobalStorage() const { return !hasLocalStorage(); }

Maybe hasLocalStorage() should be fixed to work on non-function scope
variables, or assert that it is only ever called on function scope
variables.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140509/e6ec8c3c/attachment.html>


More information about the cfe-dev mailing list