diff options
author | Richard Smith <richard@metafoo.co.uk> | 2020-09-20 23:18:04 -0700 |
---|---|---|
committer | Richard Smith <richard@metafoo.co.uk> | 2020-11-09 22:10:27 -0800 |
commit | b637148ecb62b900872b34eedd78b923bb43c378 (patch) | |
tree | 28b5a4d27001a817fa50b807a1a5c0e5f68be52e /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 892605b449f8375c62227df2eac2b8f1d7180af6 (diff) | |
download | llvm-b637148ecb62b900872b34eedd78b923bb43c378.zip llvm-b637148ecb62b900872b34eedd78b923bb43c378.tar.gz llvm-b637148ecb62b900872b34eedd78b923bb43c378.tar.bz2 |
[c++20] For P0732R2 / P1907R1: Basic code generation and name
mangling support for non-type template parameters of class type and
template parameter objects.
The Itanium side of this follows the approach I proposed in
https://github.com/itanium-cxx-abi/cxx-abi/issues/47 on 2020-09-06.
The MSVC side of this was determined empirically by observing MSVC's
output.
Differential Revision: https://reviews.llvm.org/D89998
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 92b2b5c..f50aaf3 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2636,8 +2636,29 @@ ConstantAddress CodeGenModule::GetAddrOfMSGuidDecl(const MSGuidDecl *GD) { ConstantAddress CodeGenModule::GetAddrOfTemplateParamObject( const TemplateParamObjectDecl *TPO) { - ErrorUnsupported(TPO, "template parameter object"); - return ConstantAddress::invalid(); + StringRef Name = getMangledName(TPO); + CharUnits Alignment = getNaturalTypeAlignment(TPO->getType()); + + if (llvm::GlobalVariable *GV = getModule().getNamedGlobal(Name)) + return ConstantAddress(GV, Alignment); + + ConstantEmitter Emitter(*this); + llvm::Constant *Init = Emitter.emitForInitializer( + TPO->getValue(), TPO->getType().getAddressSpace(), TPO->getType()); + + if (!Init) { + ErrorUnsupported(TPO, "template parameter object"); + return ConstantAddress::invalid(); + } + + auto *GV = new llvm::GlobalVariable( + getModule(), Init->getType(), + /*isConstant=*/true, llvm::GlobalValue::LinkOnceODRLinkage, Init, Name); + if (supportsCOMDAT()) + GV->setComdat(TheModule.getOrInsertComdat(GV->getName())); + Emitter.finalize(GV); + + return ConstantAddress(GV, Alignment); } ConstantAddress CodeGenModule::GetWeakRefReference(const ValueDecl *VD) { |