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

Richard Smith richard at metafoo.co.uk
Tue Feb 18 11:16:35 PST 2014

  I don't like that parts of the test here are duplicated in three different places; can you refactor to improve that? Maybe factor out a `CanEmitAsAvailableExternally` from `GetOrCreateLLVMGlobal` and `GetLLVMLinkageVarDefinition`, call `isTypeConstant` in there rather than asserting it, and remove the assert from `shouldEmitGlobalVariable`?

  It also seems weird to me that `shouldEmitGlobalVariable` would return `true` when `GetLLVMLinkageVarDefinition` returns `llvm::GlobalVariable::ExternalLinkage` (even though in practice this never actually happens).

Comment at: lib/CodeGen/CodeGenModule.cpp:1908-1909
@@ +1907,4 @@
+  if (D->hasInit() && !D->hasDefinition(Context)) {
+    assert(isTypeConstant(D->getType(), /*ExcludeCtor=*/true) &&
+           "Variable to be emitted as available externally must be constant!");
+    return llvm::GlobalValue::AvailableExternallyLinkage;
Why is this an assert rather than a test?


More information about the cfe-commits mailing list