diff options
author | Dan Gohman <gohman@apple.com> | 2010-10-15 20:23:12 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-10-15 20:23:12 +0000 |
commit | 0b5c4fc2ae3b503c2b1f354bf52b718aa50a6aee (patch) | |
tree | a22c990010c34113a566f02f41c7f2a02ba5cfc2 /lib/CodeGen/CodeGenTBAA.cpp | |
parent | 2a8fe339fbcd92993a0e9568696ba165c2519fba (diff) |
Experimental TBAA support for enum types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116613 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CodeGenTBAA.cpp')
-rw-r--r-- | lib/CodeGen/CodeGenTBAA.cpp | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/lib/CodeGen/CodeGenTBAA.cpp b/lib/CodeGen/CodeGenTBAA.cpp index f9082fc917..99a58a7457 100644 --- a/lib/CodeGen/CodeGenTBAA.cpp +++ b/lib/CodeGen/CodeGenTBAA.cpp @@ -12,6 +12,7 @@ //===----------------------------------------------------------------------===// #include "CodeGenTBAA.h" +#include "Mangle.h" #include "clang/AST/ASTContext.h" #include "llvm/LLVMContext.h" #include "llvm/Metadata.h" @@ -19,14 +20,15 @@ using namespace clang; using namespace CodeGen; CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext& VMContext, - const LangOptions &Features) - : Context(Ctx), VMContext(VMContext), Features(Features), Root(0), Char(0) { + const LangOptions &Features, MangleContext &MContext) + : Context(Ctx), VMContext(VMContext), Features(Features), MContext(MContext), + Root(0), Char(0) { } CodeGenTBAA::~CodeGenTBAA() { } -llvm::MDNode *CodeGenTBAA::getTBAAInfoForNamedType(const char *NameStr, +llvm::MDNode *CodeGenTBAA::getTBAAInfoForNamedType(llvm::StringRef NameStr, llvm::MDNode *Parent) { llvm::Value *Ops[] = { llvm::MDString::get(VMContext, NameStr), @@ -85,6 +87,32 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) { if (Ty->isPointerType()) return MetadataCache[Ty] = getTBAAInfoForNamedType("TBAA.pointer", Char); + // Enum types are distinct types. In C++ they have "underlying types", + // however they aren't related for TBAA. + if (const EnumType *ETy = dyn_cast<EnumType>(Ty)) { + // In C mode, two anonymous enums are compatible iff their members + // are the same -- see C99 6.2.7p1. For now, be conservative. We could + // theoretically implement this by combining information about all the + // members into a single identifying MDNode. + if (!Features.CPlusPlus && + ETy->getDecl()->getTypedefForAnonDecl()) + return MetadataCache[Ty] = Char; + + // In C++ mode, types have linkage, so we can rely on the ODR and + // on their mangled names, if they're external. + // TODO: Is there a way to get a program-wide unique name for a + // decl with local linkage or no linkage? + if (Features.CPlusPlus && + ETy->getDecl()->getLinkage() != ExternalLinkage) + return MetadataCache[Ty] = Char; + + // TODO: This is using the RTTI name. Is there a better way to get + // a unique string for a type? + llvm::SmallString<256> OutName; + MContext.mangleCXXRTTIName(QualType(ETy, 0), OutName); + return MetadataCache[Ty] = getTBAAInfoForNamedType(OutName, Char); + } + // For now, handle any other kind of type conservatively. return MetadataCache[Ty] = Char; } |