[cfe-commits] r89554 - /cfe/trunk/lib/CodeGen/Mangle.cpp

Daniel Dunbar daniel at zuster.org
Sat Nov 21 01:14:44 PST 2009


Author: ddunbar
Date: Sat Nov 21 03:14:44 2009
New Revision: 89554

URL: http://llvm.org/viewvc/llvm-project?rev=89554&view=rev
Log:
Mangler: Strengthen invariants, MangleContext::mangleName should only be called on var or function decls.

Modified:
    cfe/trunk/lib/CodeGen/Mangle.cpp

Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=89554&r1=89553&r2=89554&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Sat Nov 21 03:14:44 2009
@@ -169,18 +169,15 @@
   if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
     return mangleFunctionDecl(FD);
 
-  if (const VarDecl *VD = dyn_cast<VarDecl>(D)) {
-    if (!Context.getASTContext().getLangOptions().CPlusPlus ||
-        isInCLinkageSpecification(D) ||
-        D->getDeclContext()->isTranslationUnit())
-      return false;
-
-    Out << "_Z";
-    mangleName(VD);
-    return true;
-  }
+  const VarDecl *VD = cast<VarDecl>(D);
+  if (!Context.getASTContext().getLangOptions().CPlusPlus ||
+      isInCLinkageSpecification(D) ||
+      D->getDeclContext()->isTranslationUnit())
+    return false;
 
-  return false;
+  Out << "_Z";
+  mangleName(VD);
+  return true;
 }
 
 void CXXNameMangler::mangleFunctionEncoding(const FunctionDecl *FD) {
@@ -1298,10 +1295,10 @@
 /// name.
 bool MangleContext::mangleName(const NamedDecl *D,
                                llvm::SmallVectorImpl<char> &Res) {
-  assert(!isa<CXXConstructorDecl>(D) &&
-         "Use mangleCXXCtor for constructor decls!");
-  assert(!isa<CXXDestructorDecl>(D) &&
-         "Use mangleCXXDtor for destructor decls!");
+  assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
+          "Invalid mangleName() call, argument is not a variable or function!");
+  assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) &&
+         "Invalid mangleName() call on 'structor decl!");
 
   PrettyStackTraceDecl CrashInfo(D, SourceLocation(),
                                  getASTContext().getSourceManager(),





More information about the cfe-commits mailing list