From d195d4c520d3e26ab508b348b461e6414e253197 Mon Sep 17 00:00:00 2001 From: John McCall Date: Wed, 30 Nov 2016 23:25:13 +0000 Subject: [PATCH] Introduce a type-safe enum for ForDefinition. llvm-svn: 288289 --- clang/lib/CodeGen/CGCXX.cpp | 5 +++-- clang/lib/CodeGen/CodeGenModule.cpp | 18 +++++++++--------- clang/lib/CodeGen/CodeGenModule.h | 23 +++++++++++++++++------ clang/lib/CodeGen/ModuleBuilder.cpp | 2 +- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/clang/lib/CodeGen/CGCXX.cpp b/clang/lib/CodeGen/CGCXX.cpp index 7472d65..589dea0 100644 --- a/clang/lib/CodeGen/CGCXX.cpp +++ b/clang/lib/CodeGen/CGCXX.cpp @@ -218,7 +218,7 @@ llvm::Function *CodeGenModule::codegenCXXStructor(const CXXMethodDecl *MD, getTypes().arrangeCXXStructorDeclaration(MD, Type); auto *Fn = cast( getAddrOfCXXStructor(MD, Type, &FnInfo, /*FnType=*/nullptr, - /*DontDefer=*/true, /*IsForDefinition=*/true)); + /*DontDefer=*/true, ForDefinition)); GlobalDecl GD; if (const auto *DD = dyn_cast(MD)) { @@ -239,7 +239,8 @@ llvm::Function *CodeGenModule::codegenCXXStructor(const CXXMethodDecl *MD, llvm::Constant *CodeGenModule::getAddrOfCXXStructor( const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo, - llvm::FunctionType *FnType, bool DontDefer, bool IsForDefinition) { + llvm::FunctionType *FnType, bool DontDefer, + ForDefinition_t IsForDefinition) { GlobalDecl GD; if (auto *CD = dyn_cast(MD)) { GD = GlobalDecl(CD, toCXXCtorType(Type)); diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e9cfb5e..78f43bd 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -1296,7 +1296,7 @@ void CodeGenModule::EmitDeferred() { // might had been created for another decl with the same mangled name but // different type. llvm::GlobalValue *GV = dyn_cast( - GetAddrOfGlobal(D, /*IsForDefinition=*/true)); + GetAddrOfGlobal(D, ForDefinition)); // In case of different address spaces, we may still get a cast, even with // IsForDefinition equal to true. Query mangled names table to get @@ -1864,7 +1864,7 @@ CodeGenModule::GetOrCreateLLVMFunction(StringRef MangledName, GlobalDecl GD, bool ForVTable, bool DontDefer, bool IsThunk, llvm::AttributeSet ExtraAttrs, - bool IsForDefinition) { + ForDefinition_t IsForDefinition) { const Decl *D = GD.getDecl(); // Lookup the entry, lazily creating it if necessary. @@ -2024,7 +2024,7 @@ llvm::Constant *CodeGenModule::GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty, bool ForVTable, bool DontDefer, - bool IsForDefinition) { + ForDefinition_t IsForDefinition) { // If there was no specific requested type, just convert it now. if (!Ty) { const auto *FD = cast(GD.getDecl()); @@ -2103,7 +2103,7 @@ llvm::Constant * CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::PointerType *Ty, const VarDecl *D, - bool IsForDefinition) { + ForDefinition_t IsForDefinition) { // Lookup the entry, lazily creating it if necessary. llvm::GlobalValue *Entry = GetGlobalValue(MangledName); if (Entry) { @@ -2218,7 +2218,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(StringRef MangledName, llvm::Constant * CodeGenModule::GetAddrOfGlobal(GlobalDecl GD, - bool IsForDefinition) { + ForDefinition_t IsForDefinition) { if (isa(GD.getDecl())) return getAddrOfCXXStructor(cast(GD.getDecl()), getFromCtorType(GD.getCtorType()), @@ -2295,7 +2295,7 @@ CodeGenModule::CreateOrReplaceCXXRuntimeVariable(StringRef Name, /// variable with the same mangled name but some other type. llvm::Constant *CodeGenModule::GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty, - bool IsForDefinition) { + ForDefinition_t IsForDefinition) { assert(D->hasGlobalStorage() && "Not a global variable"); QualType ASTTy = D->getType(); if (!Ty) @@ -2485,7 +2485,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, llvm::Type* InitType = Init->getType(); llvm::Constant *Entry = - GetAddrOfGlobalVar(D, InitType, /*IsForDefinition=*/!IsTentative); + GetAddrOfGlobalVar(D, InitType, ForDefinition_t(!IsTentative)); // Strip off a bitcast if we got one back. if (auto *CE = dyn_cast(Entry)) { @@ -2518,7 +2518,7 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, // Make a new global with the correct type, this is now guaranteed to work. GV = cast( - GetAddrOfGlobalVar(D, InitType, /*IsForDefinition=*/!IsTentative)); + GetAddrOfGlobalVar(D, InitType, ForDefinition_t(!IsTentative))); // Replace all uses of the old global with the new global llvm::Constant *NewPtrForOldDecl = @@ -2922,7 +2922,7 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, if (!GV || (GV->getType()->getElementType() != Ty)) GV = cast(GetAddrOfFunction(GD, Ty, /*ForVTable=*/false, /*DontDefer=*/true, - /*IsForDefinition=*/true)); + ForDefinition)); // Already emitted. if (!GV->isDeclaration()) diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index c7ef80e..be45bb8 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -94,6 +94,11 @@ class FunctionArgList; class CoverageMappingModuleGen; class TargetCodeGenInfo; +enum ForDefinition_t : bool { + NotForDefinition = false, + ForDefinition = true +}; + struct OrderGlobalInits { unsigned int priority; unsigned int lex_order; @@ -676,7 +681,9 @@ public: llvm_unreachable("unknown visibility!"); } - llvm::Constant *GetAddrOfGlobal(GlobalDecl GD, bool IsForDefinition = false); + llvm::Constant *GetAddrOfGlobal(GlobalDecl GD, + ForDefinition_t IsForDefinition + = NotForDefinition); /// Will return a global variable of the given type. If a variable with a /// different type already exists then a new variable with the right type @@ -706,14 +713,16 @@ public: /// the same mangled name but some other type. llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty = nullptr, - bool IsForDefinition = false); + ForDefinition_t IsForDefinition + = NotForDefinition); /// Return the address of the given function. If Ty is non-null, then this /// function will use the specified type if it has to create it. llvm::Constant *GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty = nullptr, bool ForVTable = false, bool DontDefer = false, - bool IsForDefinition = false); + ForDefinition_t IsForDefinition + = NotForDefinition); /// Get the address of the RTTI descriptor for the given type. llvm::Constant *GetAddrOfRTTIDescriptor(QualType Ty, bool ForEH = false); @@ -821,7 +830,8 @@ public: getAddrOfCXXStructor(const CXXMethodDecl *MD, StructorType Type, const CGFunctionInfo *FnInfo = nullptr, llvm::FunctionType *FnType = nullptr, - bool DontDefer = false, bool IsForDefinition = false); + bool DontDefer = false, + ForDefinition_t IsForDefinition = NotForDefinition); /// Given a builtin id for a function like "__builtin_fabsf", return a /// Function* for "fabsf". @@ -1151,12 +1161,13 @@ private: bool ForVTable, bool DontDefer = false, bool IsThunk = false, llvm::AttributeSet ExtraAttrs = llvm::AttributeSet(), - bool IsForDefinition = false); + ForDefinition_t IsForDefinition = NotForDefinition); llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName, llvm::PointerType *PTy, const VarDecl *D, - bool IsForDefinition = false); + ForDefinition_t IsForDefinition + = NotForDefinition); void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO); diff --git a/clang/lib/CodeGen/ModuleBuilder.cpp b/clang/lib/CodeGen/ModuleBuilder.cpp index 952d162..f925c25 100644 --- a/clang/lib/CodeGen/ModuleBuilder.cpp +++ b/clang/lib/CodeGen/ModuleBuilder.cpp @@ -112,7 +112,7 @@ namespace { } llvm::Constant *GetAddrOfGlobal(GlobalDecl global, bool isForDefinition) { - return Builder->GetAddrOfGlobal(global, isForDefinition); + return Builder->GetAddrOfGlobal(global, ForDefinition_t(isForDefinition)); } void Initialize(ASTContext &Context) override { -- 2.7.4