r185721 - Don't use mangleCXXRTTIName in TBAA for C code.
Eli Friedman
eli.friedman at gmail.com
Fri Jul 5 13:27:40 PDT 2013
Author: efriedma
Date: Fri Jul 5 15:27:40 2013
New Revision: 185721
URL: http://llvm.org/viewvc/llvm-project?rev=185721&view=rev
Log:
Don't use mangleCXXRTTIName in TBAA for C code.
This changes the TBAA code so it doesn't use mangleCXXRTTIName in C,
because it doesn't really make sense there. Also, as sort of a
defense-in-depth change, fix the mangler so it handles C RecordDecls
correctly.
No tests because I don't know the TBAA code well enough to write a test,
and I don't know how else to trigger mangling a local struct in C.
Fixes a crash with r185450 reported by Joerg Sonnenberger.
Modified:
cfe/trunk/lib/AST/ItaniumMangle.cpp
cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=185721&r1=185720&r2=185721&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Fri Jul 5 15:27:40 2013
@@ -72,11 +72,11 @@ static bool isLocalContainerContext(cons
return isa<FunctionDecl>(DC) || isa<ObjCMethodDecl>(DC) || isa<BlockDecl>(DC);
}
-static const CXXRecordDecl *GetLocalClassDecl(const Decl *D) {
+static const RecordDecl *GetLocalClassDecl(const Decl *D) {
const DeclContext *DC = getEffectiveDeclContext(D);
while (!DC->isNamespace() && !DC->isTranslationUnit()) {
if (isLocalContainerContext(DC))
- return dyn_cast<CXXRecordDecl>(D);
+ return dyn_cast<RecordDecl>(D);
D = cast<Decl>(DC);
DC = getEffectiveDeclContext(D);
}
@@ -1280,7 +1280,7 @@ void CXXNameMangler::mangleLocalName(con
// _ <entity name>
// <discriminator> := _ <non-negative number>
assert(isa<NamedDecl>(D) || isa<BlockDecl>(D));
- const CXXRecordDecl *RD = GetLocalClassDecl(D);
+ const RecordDecl *RD = GetLocalClassDecl(D);
const DeclContext *DC = getEffectiveDeclContext(RD ? RD : D);
Out << 'Z';
@@ -1301,9 +1301,10 @@ void CXXNameMangler::mangleLocalName(con
// numbering will be local to the particular argument in which it appears
// -- other default arguments do not affect its encoding.
bool SkipDiscriminator = false;
- if (RD->isLambda()) {
+ const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD);
+ if (CXXRD->isLambda()) {
if (const ParmVarDecl *Parm
- = dyn_cast_or_null<ParmVarDecl>(RD->getLambdaContextDecl())) {
+ = dyn_cast_or_null<ParmVarDecl>(CXXRD->getLambdaContextDecl())) {
if (const FunctionDecl *Func
= dyn_cast<FunctionDecl>(Parm->getDeclContext())) {
Out << 'd';
Modified: cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp?rev=185721&r1=185720&r2=185721&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenTBAA.cpp Fri Jul 5 15:27:40 2013
@@ -150,19 +150,11 @@ CodeGenTBAA::getTBAAInfo(QualType QTy) {
// 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()->getTypedefNameForAnonDecl())
- return MetadataCache[Ty] = getChar();
-
// 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()->isExternallyVisible())
+ if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible())
return MetadataCache[Ty] = getChar();
// TODO: This is using the RTTI name. Is there a better way to get
More information about the cfe-commits
mailing list