[cfe-commits] r139442 - in /cfe/trunk: include/clang/Serialization/ASTBitCodes.h lib/Serialization/ASTReader.cpp test/Modules/load_failure.c

Douglas Gregor dgregor at apple.com
Fri Sep 9 17:30:18 PDT 2011


Author: dgregor
Date: Fri Sep  9 19:30:18 2011
New Revision: 139442

URL: http://llvm.org/viewvc/llvm-project?rev=139442&view=rev
Log:
Don't crash when we fail to load a module. It's unbecoming of a
well-bred compiler like Clang.

Modified:
    cfe/trunk/include/clang/Serialization/ASTBitCodes.h
    cfe/trunk/lib/Serialization/ASTReader.cpp
    cfe/trunk/test/Modules/load_failure.c

Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=139442&r1=139441&r2=139442&view=diff
==============================================================================
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Fri Sep  9 19:30:18 2011
@@ -666,6 +666,9 @@
       /// \brief Objective-C "SEL" redefinition type
       SPECIAL_TYPE_OBJC_SEL_REDEFINITION       = 8
     };
+    
+    /// \brief The number of special type IDs.
+    const unsigned NumSpecialTypeIDs = 0;
 
     /// \brief Predefined declaration IDs.
     ///

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=139442&r1=139441&r2=139442&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Fri Sep  9 19:30:18 2011
@@ -2788,99 +2788,101 @@
   // built-in types. Right now, we just ignore the problem.
   
   // Load the special types.
-  if (Context.getBuiltinVaListType().isNull()) {
-    Context.setBuiltinVaListType(
-      GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST]));
-  }
-  
-  if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) {
-    if (Context.ObjCProtoType.isNull())
-      Context.ObjCProtoType = GetType(Proto);
-  }
-  
-  if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
-    if (!Context.CFConstantStringTypeDecl)
-      Context.setCFConstantStringType(GetType(String));
-  }
-  
-  if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) {
-    QualType FileType = GetType(File);
-    if (FileType.isNull()) {
-      Error("FILE type is NULL");
-      return;
+  if (SpecialTypes.size() > NumSpecialTypeIDs) {
+    if (Context.getBuiltinVaListType().isNull()) {
+      Context.setBuiltinVaListType(
+        GetType(SpecialTypes[SPECIAL_TYPE_BUILTIN_VA_LIST]));
     }
     
-    if (!Context.FILEDecl) {
-      if (const TypedefType *Typedef = FileType->getAs<TypedefType>())
-        Context.setFILEDecl(Typedef->getDecl());
-      else {
-        const TagType *Tag = FileType->getAs<TagType>();
-        if (!Tag) {
-          Error("Invalid FILE type in AST file");
-          return;
-        }
-        Context.setFILEDecl(Tag->getDecl());
-      }
+    if (unsigned Proto = SpecialTypes[SPECIAL_TYPE_OBJC_PROTOCOL]) {
+      if (Context.ObjCProtoType.isNull())
+        Context.ObjCProtoType = GetType(Proto);
     }
-  }
-  
-  if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) {
-    QualType Jmp_bufType = GetType(Jmp_buf);
-    if (Jmp_bufType.isNull()) {
-      Error("jmp_buf type is NULL");
-      return;
+    
+    if (unsigned String = SpecialTypes[SPECIAL_TYPE_CF_CONSTANT_STRING]) {
+      if (!Context.CFConstantStringTypeDecl)
+        Context.setCFConstantStringType(GetType(String));
     }
     
-    if (!Context.jmp_bufDecl) {
-      if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>())
-        Context.setjmp_bufDecl(Typedef->getDecl());
-      else {
-        const TagType *Tag = Jmp_bufType->getAs<TagType>();
-        if (!Tag) {
-          Error("Invalid jmp_buf type in AST file");
-          return;
+    if (unsigned File = SpecialTypes[SPECIAL_TYPE_FILE]) {
+      QualType FileType = GetType(File);
+      if (FileType.isNull()) {
+        Error("FILE type is NULL");
+        return;
+      }
+      
+      if (!Context.FILEDecl) {
+        if (const TypedefType *Typedef = FileType->getAs<TypedefType>())
+          Context.setFILEDecl(Typedef->getDecl());
+        else {
+          const TagType *Tag = FileType->getAs<TagType>();
+          if (!Tag) {
+            Error("Invalid FILE type in AST file");
+            return;
+          }
+          Context.setFILEDecl(Tag->getDecl());
         }
-        Context.setjmp_bufDecl(Tag->getDecl());
       }
     }
-  }
-  
-  if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) {
-    QualType Sigjmp_bufType = GetType(Sigjmp_buf);
-    if (Sigjmp_bufType.isNull()) {
-      Error("sigjmp_buf type is NULL");
-      return;
+    
+    if (unsigned Jmp_buf = SpecialTypes[SPECIAL_TYPE_jmp_buf]) {
+      QualType Jmp_bufType = GetType(Jmp_buf);
+      if (Jmp_bufType.isNull()) {
+        Error("jmp_buf type is NULL");
+        return;
+      }
+      
+      if (!Context.jmp_bufDecl) {
+        if (const TypedefType *Typedef = Jmp_bufType->getAs<TypedefType>())
+          Context.setjmp_bufDecl(Typedef->getDecl());
+        else {
+          const TagType *Tag = Jmp_bufType->getAs<TagType>();
+          if (!Tag) {
+            Error("Invalid jmp_buf type in AST file");
+            return;
+          }
+          Context.setjmp_bufDecl(Tag->getDecl());
+        }
+      }
     }
     
-    if (!Context.sigjmp_bufDecl) {
-      if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>())
-        Context.setsigjmp_bufDecl(Typedef->getDecl());
-      else {
-        const TagType *Tag = Sigjmp_bufType->getAs<TagType>();
-        assert(Tag && "Invalid sigjmp_buf type in AST file");
-        Context.setsigjmp_bufDecl(Tag->getDecl());
+    if (unsigned Sigjmp_buf = SpecialTypes[SPECIAL_TYPE_sigjmp_buf]) {
+      QualType Sigjmp_bufType = GetType(Sigjmp_buf);
+      if (Sigjmp_bufType.isNull()) {
+        Error("sigjmp_buf type is NULL");
+        return;
+      }
+      
+      if (!Context.sigjmp_bufDecl) {
+        if (const TypedefType *Typedef = Sigjmp_bufType->getAs<TypedefType>())
+          Context.setsigjmp_bufDecl(Typedef->getDecl());
+        else {
+          const TagType *Tag = Sigjmp_bufType->getAs<TagType>();
+          assert(Tag && "Invalid sigjmp_buf type in AST file");
+          Context.setsigjmp_bufDecl(Tag->getDecl());
+        }
       }
     }
-  }
 
-  if (unsigned ObjCIdRedef
-        = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) {
-    if (Context.ObjCIdRedefinitionType.isNull())
-      Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef);
-  }
-
-  if (unsigned ObjCClassRedef
-        = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) {
-    if (Context.ObjCClassRedefinitionType.isNull())
-      Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef);
-  }
-
-  if (unsigned ObjCSelRedef
-        = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) {
-    if (Context.ObjCSelRedefinitionType.isNull())
-      Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef);
+    if (unsigned ObjCIdRedef
+          = SpecialTypes[SPECIAL_TYPE_OBJC_ID_REDEFINITION]) {
+      if (Context.ObjCIdRedefinitionType.isNull())
+        Context.ObjCIdRedefinitionType = GetType(ObjCIdRedef);
+    }
+
+    if (unsigned ObjCClassRedef
+          = SpecialTypes[SPECIAL_TYPE_OBJC_CLASS_REDEFINITION]) {
+      if (Context.ObjCClassRedefinitionType.isNull())
+        Context.ObjCClassRedefinitionType = GetType(ObjCClassRedef);
+    }
+
+    if (unsigned ObjCSelRedef
+          = SpecialTypes[SPECIAL_TYPE_OBJC_SEL_REDEFINITION]) {
+      if (Context.ObjCSelRedefinitionType.isNull())
+        Context.ObjCSelRedefinitionType = GetType(ObjCSelRedef);
+    }
   }
-
+  
   ReadPragmaDiagnosticMappings(Context.getDiagnostics());
 
   // If there were any CUDA special declarations, deserialize them.

Modified: cfe/trunk/test/Modules/load_failure.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/load_failure.c?rev=139442&r1=139441&r2=139442&view=diff
==============================================================================
--- cfe/trunk/test/Modules/load_failure.c (original)
+++ cfe/trunk/test/Modules/load_failure.c Fri Sep  9 19:30:18 2011
@@ -10,7 +10,9 @@
 // RUN: %clang_cc1 -I %T %s -DNONEXISTENT 2>&1 | FileCheck -check-prefix=CHECK-NONEXISTENT %s
 // CHECK-NONEXISTENT: load_failure.c:2:19: fatal error: module 'load_nonexistent' not found
 
-// RUN: %clang_cc1 -I %T %s -DFAILURE 2>&1 | FileCheck -check-prefix=CHECK-FAILURE %s
+// RUN: not %clang_cc1 -I %T %s -DFAILURE 2> %t
+// RUN: FileCheck -check-prefix=CHECK-FAILURE %s < %t
+
 // FIXME: Clean up diagnostic text below and give it a location
 // CHECK-FAILURE: error: C99 support was disabled in PCH file but is currently enabled
 





More information about the cfe-commits mailing list