[cfe-commits] r153723 - in /cfe/trunk: lib/CodeGen/CGDecl.cpp lib/CodeGen/ItaniumCXXABI.cpp test/CodeGenCXX/static-init.cpp
John McCall
rjmccall at apple.com
Thu Mar 29 21:46:23 PDT 2012
On Mar 29, 2012, at 9:41 PM, Eli Friedman wrote:
> On Thu, Mar 29, 2012 at 9:25 PM, John McCall <rjmccall at apple.com> wrote:
>> Author: rjmccall
>> Date: Thu Mar 29 23:25:14 2012
>> New Revision: 153723
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=153723&view=rev
>> Log:
>> When emitting a static local variable in C++, handle
>> the case that the variable already exists. Partly this is just
>> protection against people making crazy declarations with custom
>> asm labels or extern "C" names that intentionally collide with
>> the manglings of such variables, but the main reason is that we
>> can actually emit a static local variable twice with the
>> requirement that it match up. There may be other cases with
>> (e.g.) the various nested functions, but the main exemplar is
>> with constructor variants, where we can be forced into
>> double-emitting the function body under certain circumstances
>> like (currently) the presence of virtual bases.
>>
>> Modified:
>> cfe/trunk/lib/CodeGen/CGDecl.cpp
>> cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
>> cfe/trunk/test/CodeGenCXX/static-init.cpp
>>
>> Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=153723&r1=153722&r2=153723&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
>> +++ cfe/trunk/lib/CodeGen/CGDecl.cpp Thu Mar 29 23:25:14 2012
>> @@ -184,6 +184,24 @@
>> Name = GetStaticDeclName(*this, D, Separator);
>>
>> llvm::Type *LTy = CGM.getTypes().ConvertTypeForMem(Ty);
>> +
>> + // In C++, there are strange possibilities here involving the
>> + // double-emission of constructors and destructors.
>> + if (CGM.getLangOpts().CPlusPlus) {
>> + llvm::GlobalValue *value = CGM.getModule().getNamedValue(Name);
>> + if (value && isa<llvm::GlobalVariable>(value) &&
>> + value->getType() ==
>> + LTy->getPointerTo(CGM.getContext().getTargetAddressSpace(Ty)))
>> + return cast<llvm::GlobalVariable>(value);
>
> This check won't work reliably: the global's type isn't guaranteed to
> be the same as the IR type of the variable.
Is there a situation you have in mind where the type check I've got would
be inadequate?
John.
More information about the cfe-commits
mailing list