From 2b402022a110613003dda6ebb3067a84db5f1cbb Mon Sep 17 00:00:00 2001 From: Ben Hekster Date: Sat, 16 Jul 2022 00:14:06 -0700 Subject: [PATCH] Explicitly mark global variable definition as having 'undefined' value --- Chapter07/tinylang/lib/CodeGen/CGModule.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Chapter07/tinylang/lib/CodeGen/CGModule.cpp b/Chapter07/tinylang/lib/CodeGen/CGModule.cpp index 9963d2c..04f7c99 100644 --- a/Chapter07/tinylang/lib/CodeGen/CGModule.cpp +++ b/Chapter07/tinylang/lib/CodeGen/CGModule.cpp @@ -97,10 +97,12 @@ void CGModule::run(ModuleDeclaration *Mod) { if (auto *Var = llvm::dyn_cast(Decl)) { // Create global variables + llvm::Type *T = convertType(Var->getType()); llvm::GlobalVariable *V = new llvm::GlobalVariable( - *M, convertType(Var->getType()), + *M, T, /*isConstant=*/false, - llvm::GlobalValue::PrivateLinkage, nullptr, + llvm::GlobalValue::PrivateLinkage, + llvm::UndefValue::get(T), mangleName(Var)); Globals[Var] = V; if (CGDebugInfo *Dbg = getDbgInfo())