Track protos + globals w/out initializers as undef too (not just helper funcs)
Also handle empty global variable lists -- and initialize
ShAddralign to 1 instead of 0, just in case. Previously
it would try to align by 0 when the variable list was empty.
This should help the crosstests pass with --elf.
BUG=none
R=kschimpf@google.com, stichnot@chromium.org
Review URL: https://codereview.chromium.org/899483002
diff --git a/src/IceConverter.cpp b/src/IceConverter.cpp
index 47f8b39..5316db6 100644
--- a/src/IceConverter.cpp
+++ b/src/IceConverter.cpp
@@ -121,9 +121,20 @@
Ice::Constant *convertConstant(const Constant *Const) {
if (const auto GV = dyn_cast<GlobalValue>(Const)) {
Ice::GlobalDeclaration *Decl = getConverter().getGlobalDeclaration(GV);
- const Ice::RelocOffsetT Offset = 0;
- return Ctx->getConstantSym(Offset, Decl->getName(),
- Decl->getSuppressMangling());
+ bool IsUndefined = false;
+ if (const auto *Func = llvm::dyn_cast<Ice::FunctionDeclaration>(Decl))
+ IsUndefined = Func->isProto();
+ else if (const auto *Var = llvm::dyn_cast<Ice::VariableDeclaration>(Decl))
+ IsUndefined = !Var->hasInitializer();
+ else
+ report_fatal_error("Unhandled GlobalDeclaration type");
+ if (IsUndefined)
+ return Ctx->getConstantExternSym(Decl->getName());
+ else {
+ const Ice::RelocOffsetT Offset = 0;
+ return Ctx->getConstantSym(Offset, Decl->getName(),
+ Decl->getSuppressMangling());
+ }
} else if (const auto CI = dyn_cast<ConstantInt>(Const)) {
Ice::Type Ty = convertToIceType(CI->getType());
return Ctx->getConstantInt(Ty, CI->getSExtValue());