[PATCH] CodeGen: Emit globals with a constant initializer but no definition as available_externally.

Richard Smith richard at metafoo.co.uk
Fri Feb 21 11:00:03 PST 2014


  Patch looks good to me. Just one more thing (hopefully...): does this behave correctly if the global variable lifetime-extends a temporary? Given:

    struct Q { int &&r; };
    struct S {
      static constexpr Q q = { 0 };
    };
    int k = S::q.r;

  ... how do we emit `@_ZN1S1qE` and `@_ZGRN1S1qE`?


================
Comment at: lib/CodeGen/CodeGenModule.cpp:1263-1268
@@ +1262,8 @@
+
+bool CodeGenModule::shouldEmitGlobalVariable(const VarDecl *D) {
+  if (canEmitGlobalAsAvailableExternally(D))
+    return CodeGenOpts.OptimizationLevel != 0;
+
+  return true;
+}
+
----------------
Can you find a better name for this function? It returns `true` for variables that we shouldn't emit at all, which makes me uneasy. Maybe just inline it into its only call site (which already has a comment describing exactly what this code does)?


http://llvm-reviews.chandlerc.com/D1982



More information about the cfe-commits mailing list