[cfe-commits] r100907 - in /cfe/trunk/lib/CodeGen: CodeGenModule.cpp Mangle.cpp Mangle.h

John McCall rjmccall at apple.com
Fri Apr 9 15:26:14 PDT 2010


Author: rjmccall
Date: Fri Apr  9 17:26:14 2010
New Revision: 100907

URL: http://llvm.org/viewvc/llvm-project?rev=100907&view=rev
Log:
Provide an extremely unsatisfactory diagnostic (instead of crashing) when
mangling an unknown expression kind.  Also conveniently tells the user what
kind of expression they should add to the mangler!


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

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=100907&r1=100906&r2=100907&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Apr  9 17:26:14 2010
@@ -47,7 +47,8 @@
     Features(C.getLangOptions()), CodeGenOpts(CGO), TheModule(M),
     TheTargetData(TD), TheTargetCodeGenInfo(0), Diags(diags),
     Types(C, M, TD, getTargetCodeGenInfo().getABIInfo()),
-    MangleCtx(C), VTables(*this), Runtime(0), CFConstantStringClassRef(0),
+    MangleCtx(C, diags), VTables(*this), Runtime(0),
+    CFConstantStringClassRef(0),
     VMContext(M.getContext()) {
 
   if (!Features.ObjC1)

Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=100907&r1=100906&r2=100907&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Fri Apr  9 17:26:14 2010
@@ -1279,10 +1279,24 @@
   //                ::= L <type <value float> E      # floating literal
   //                ::= L <mangled-name> E           # external name
   switch (E->getStmtClass()) {
-  default:
+  case Expr::NoStmtClass:
+#define EXPR(Type, Base)
+#define STMT(Type, Base) \
+  case Expr::Type##Class:
+#include "clang/AST/StmtNodes.def"
     llvm_unreachable("unexpected statement kind");
     break;
 
+  default: {
+    // As bad as this diagnostic is, it's better than crashing.
+    Diagnostic &Diags = Context.getDiags();
+    unsigned DiagID = Diags.getCustomDiagID(Diagnostic::Error,
+                                     "cannot yet mangle expression type %0");
+    Diags.Report(FullSourceLoc(), DiagID)
+      << E->getStmtClassName();
+    break;
+  }
+
   case Expr::CallExprClass: {
     const CallExpr *CE = cast<CallExpr>(E);
     Out << "cl";

Modified: cfe/trunk/lib/CodeGen/Mangle.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.h?rev=100907&r1=100906&r2=100907&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.h (original)
+++ cfe/trunk/lib/CodeGen/Mangle.h Fri Apr  9 17:26:14 2010
@@ -68,17 +68,21 @@
 /// calls to the C++ name mangler.
 class MangleContext {
   ASTContext &Context;
+  Diagnostic &Diags;
 
   llvm::DenseMap<const TagDecl *, uint64_t> AnonStructIds;
   unsigned Discriminator;
   llvm::DenseMap<const NamedDecl*, unsigned> Uniquifier;
   
 public:
-  explicit MangleContext(ASTContext &Context)
-    : Context(Context) { }
+  explicit MangleContext(ASTContext &Context,
+                         Diagnostic &Diags)
+    : Context(Context), Diags(Diags) { }
 
   ASTContext &getASTContext() const { return Context; }
 
+  Diagnostic &getDiags() const { return Diags; }
+
   uint64_t getAnonymousStructId(const TagDecl *TD) {
     std::pair<llvm::DenseMap<const TagDecl *,
       uint64_t>::iterator, bool> Result =





More information about the cfe-commits mailing list