most of this is plumbing to get CompileOptions down into
CodeGenModule. Once there, add a new NoCommon option to
it and implement -fno-common.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67735 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 92af03e..8a88051 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -11,12 +11,13 @@
//
//===----------------------------------------------------------------------===//
-#include "CGDebugInfo.h"
#include "CodeGenModule.h"
+#include "CGDebugInfo.h"
#include "CodeGenFunction.h"
#include "CGCall.h"
#include "CGObjCRuntime.h"
#include "Mangle.h"
+#include "clang/Frontend/CompileOptions.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclCXX.h"
@@ -31,10 +32,11 @@
using namespace CodeGen;
-CodeGenModule::CodeGenModule(ASTContext &C, const LangOptions &LO,
+CodeGenModule::CodeGenModule(ASTContext &C, const CompileOptions &compileOpts,
llvm::Module &M, const llvm::TargetData &TD,
- Diagnostic &diags, bool GenerateDebugInfo)
- : BlockModule(C, M, TD, Types, *this), Context(C), Features(LO), TheModule(M),
+ Diagnostic &diags)
+ : BlockModule(C, M, TD, Types, *this), Context(C),
+ Features(C.getLangOptions()), CompileOpts(compileOpts), TheModule(M),
TheTargetData(TD), Diags(diags), Types(C, M, TD), Runtime(0),
MemCpyFn(0), MemMoveFn(0), MemSetFn(0), CFConstantStringClassRef(0) {
@@ -48,7 +50,7 @@
Runtime = CreateMacObjCRuntime(*this);
// If debug info generation is enabled, create the CGDebugInfo object.
- DebugInfo = GenerateDebugInfo ? new CGDebugInfo(this) : 0;
+ DebugInfo = CompileOpts.DebugInfo ? new CGDebugInfo(this) : 0;
}
CodeGenModule::~CodeGenModule() {
@@ -767,7 +769,7 @@
case VarDecl::Register:
assert(0 && "Can't have auto or register globals");
case VarDecl::None:
- if (!D->getInit())
+ if (!D->getInit() && !CompileOpts.NoCommon)
GV->setLinkage(llvm::GlobalVariable::CommonLinkage);
else
GV->setLinkage(llvm::GlobalVariable::ExternalLinkage);
diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h
index a327748..228020c 100644
--- a/lib/CodeGen/CodeGenModule.h
+++ b/lib/CodeGen/CodeGenModule.h
@@ -14,15 +14,13 @@
#ifndef CLANG_CODEGEN_CODEGENMODULE_H
#define CLANG_CODEGEN_CODEGENMODULE_H
-#include "CodeGenTypes.h"
#include "clang/AST/Attr.h"
+#include "CGBlocks.h"
+#include "CGCall.h"
+#include "CodeGenTypes.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringSet.h"
-
-#include "CGBlocks.h"
-#include "CGCall.h"
-
#include <list>
namespace llvm {
@@ -52,6 +50,7 @@
class ValueDecl;
class VarDecl;
class LangOptions;
+ class CompileOptions;
class Diagnostic;
class AnnotateAttr;
@@ -71,6 +70,7 @@
ASTContext &Context;
const LangOptions &Features;
+ const CompileOptions &CompileOpts;
llvm::Module &TheModule;
const llvm::TargetData &TheTargetData;
Diagnostic &Diags;
@@ -138,9 +138,8 @@
/// strings. This value has type int * but is actually an Obj-C class pointer.
llvm::Constant *CFConstantStringClassRef;
public:
- CodeGenModule(ASTContext &C, const LangOptions &Features, llvm::Module &M,
- const llvm::TargetData &TD, Diagnostic &Diags,
- bool GenerateDebugInfo);
+ CodeGenModule(ASTContext &C, const CompileOptions &CompileOpts,
+ llvm::Module &M, const llvm::TargetData &TD, Diagnostic &Diags);
~CodeGenModule();
diff --git a/lib/CodeGen/ModuleBuilder.cpp b/lib/CodeGen/ModuleBuilder.cpp
index 3e3f5e4..6c0b68b 100644
--- a/lib/CodeGen/ModuleBuilder.cpp
+++ b/lib/CodeGen/ModuleBuilder.cpp
@@ -13,20 +13,17 @@
#include "clang/CodeGen/ModuleBuilder.h"
#include "CodeGenModule.h"
+#include "clang/Frontend/CompileOptions.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
-using namespace clang;
-
-//===----------------------------------------------------------------------===//
-// LLVM Emitter
-
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/TargetInfo.h"
#include "llvm/Module.h"
#include "llvm/Target/TargetData.h"
#include "llvm/Support/Compiler.h"
#include "llvm/ADT/OwningPtr.h"
+using namespace clang;
namespace {
@@ -34,17 +31,14 @@
Diagnostic &Diags;
llvm::OwningPtr<const llvm::TargetData> TD;
ASTContext *Ctx;
- const LangOptions &Features;
- bool GenerateDebugInfo;
+ const CompileOptions CompileOpts; // Intentionally copied in.
protected:
llvm::OwningPtr<llvm::Module> M;
llvm::OwningPtr<CodeGen::CodeGenModule> Builder;
public:
- CodeGeneratorImpl(Diagnostic &diags, const LangOptions &LO,
- const std::string& ModuleName,
- bool DebugInfoFlag)
- : Diags(diags), Features(LO), GenerateDebugInfo(DebugInfoFlag),
- M(new llvm::Module(ModuleName)) {}
+ CodeGeneratorImpl(Diagnostic &diags, const std::string& ModuleName,
+ const CompileOptions &CO)
+ : Diags(diags), CompileOpts(CO), M(new llvm::Module(ModuleName)) {}
virtual ~CodeGeneratorImpl() {}
@@ -62,8 +56,8 @@
M->setTargetTriple(Ctx->Target.getTargetTriple());
M->setDataLayout(Ctx->Target.getTargetDescription());
TD.reset(new llvm::TargetData(Ctx->Target.getTargetDescription()));
- Builder.reset(new CodeGen::CodeGenModule(Context, Features, *M, *TD,
- Diags, GenerateDebugInfo));
+ Builder.reset(new CodeGen::CodeGenModule(Context, CompileOpts,
+ *M, *TD, Diags));
}
virtual void HandleTopLevelDecl(Decl *D) {
@@ -93,8 +87,7 @@
}
CodeGenerator *clang::CreateLLVMCodeGen(Diagnostic &Diags,
- const LangOptions &Features,
const std::string& ModuleName,
- bool GenerateDebugInfo) {
- return new CodeGeneratorImpl(Diags, Features, ModuleName, GenerateDebugInfo);
+ const CompileOptions &CO) {
+ return new CodeGeneratorImpl(Diags, ModuleName, CO);
}