From 7aa88ce70c95d4dd27e7245cb624a46835b9fe0c Mon Sep 17 00:00:00 2001 From: Andrey Bokhanko Date: Thu, 14 Jan 2016 10:41:16 +0000 Subject: PR25910: clang allows two var definitions with the same mangled name Proper diagnostic and resolution of mangled names' conflicts in variables. When there is a declaration and a definition using the same name but different types, we emit what is in the definition. When there are two conflicting definitions, we issue an error. Differential Revision: http://reviews.llvm.org/D15686 llvm-svn: 257754 --- clang/lib/CodeGen/CodeGenModule.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.h') diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index fdb4d78..c7b8258 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -696,11 +696,14 @@ public: unsigned GetGlobalVarAddressSpace(const VarDecl *D, unsigned AddrSpace); /// Return the llvm::Constant for the address of the given global variable. - /// If Ty is non-null and if the global doesn't exist, then it will be greated + /// If Ty is non-null and if the global doesn't exist, then it will be created /// with the specified type instead of whatever the normal requested type - /// would be. + /// would be. If IsForDefinition is true, it is guranteed that an actual + /// global with type Ty will be returned, not conversion of a variable with + /// the same mangled name but some other type. llvm::Constant *GetAddrOfGlobalVar(const VarDecl *D, - llvm::Type *Ty = nullptr); + llvm::Type *Ty = nullptr, + bool IsForDefinition = false); /// 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. @@ -1136,7 +1139,8 @@ private: llvm::Constant *GetOrCreateLLVMGlobal(StringRef MangledName, llvm::PointerType *PTy, - const VarDecl *D); + const VarDecl *D, + bool IsForDefinition = false); void setNonAliasAttributes(const Decl *D, llvm::GlobalObject *GO); @@ -1147,7 +1151,7 @@ private: void EmitGlobalDefinition(GlobalDecl D, llvm::GlobalValue *GV = nullptr); void EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::GlobalValue *GV); - void EmitGlobalVarDefinition(const VarDecl *D); + void EmitGlobalVarDefinition(const VarDecl *D, bool IsTentative = false); void EmitAliasDefinition(GlobalDecl GD); void EmitObjCPropertyImplementations(const ObjCImplementationDecl *D); void EmitObjCIvarInitializations(ObjCImplementationDecl *D); -- cgit v1.1