]> granicus.if.org Git - clang/commitdiff
Provide an extremely unsatisfactory diagnostic (instead of crashing) when
authorJohn McCall <rjmccall@apple.com>
Fri, 9 Apr 2010 22:26:14 +0000 (22:26 +0000)
committerJohn McCall <rjmccall@apple.com>
Fri, 9 Apr 2010 22:26:14 +0000 (22:26 +0000)
mangling an unknown expression kind.  Also conveniently tells the user what
kind of expression they should add to the mangler!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@100907 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
lib/CodeGen/Mangle.cpp
lib/CodeGen/Mangle.h

index 1cb7089210cdc4230d3926600bb704d6936fa754..01c4f4e57ba92eaf3d94f462b6c51b248d0afc28 100644 (file)
@@ -47,7 +47,8 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
     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)
index 649e848c99600886bcd21ee6d5a0f045cadd9cc6..b052f86c1eb29bec3313360f068444f9b6c574ef 100644 (file)
@@ -1279,10 +1279,24 @@ void CXXNameMangler::mangleExpression(const Expr *E) {
   //                ::= 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";
index 91a5e97b69c98d4ee4fc61bc8c6074952f36c4a0..dc1673012b17ceeb5f7d3577294599d03d2dfc5c 100644 (file)
@@ -68,17 +68,21 @@ private:
 /// 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 =