]> granicus.if.org Git - clang/commitdiff
Improve some comments, shrink FunctionType::ExtInfo, and fix a bug found
authorJohn McCall <rjmccall@apple.com>
Tue, 14 Dec 2010 16:45:57 +0000 (16:45 +0000)
committerJohn McCall <rjmccall@apple.com>
Tue, 14 Dec 2010 16:45:57 +0000 (16:45 +0000)
by valgrind where we were doing the wrong thing in the presence of invalid
exception specs.

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

include/clang/AST/Type.h
lib/Sema/SemaType.cpp

index 686331f44cbdccdf03495f3ce8f4f70d2b5c13f7..229119c78127eb17ac9b50176a1e0fbaa7927fe8 100644 (file)
@@ -2125,9 +2125,13 @@ class FunctionType : public Type {
   QualType ResultType;
 
  public:
-  // This class is used for passing around the information needed to
-  // construct a call. It is not actually used for storage, just for
-  // factoring together common arguments.
+  /// ExtInfo - A class which abstracts out some details necessary for
+  /// making a call.
+  ///
+  /// It is not actually used directly for storing this information in
+  /// a FunctionType, although FunctionType does currently use the
+  /// same bit-pattern.
+  ///
   // If you add a field (say Foo), other than the obvious places (both,
   // constructors, compile failures), what you need to update is
   // * Operator==
@@ -2141,16 +2145,21 @@ class FunctionType : public Type {
   // * TypePrinter::PrintFunctionProto
   // * AST read and write
   // * Codegen
-
   class ExtInfo {
+    // Feel free to rearrange or add bits, but if you go over 8,
+    // you'll need to adjust both the Bits field below and
+    // Type::FunctionTypeBitfields.
+
+    //   |  CC  |noreturn|regparm
+    //   |0 .. 2|   3    |4 ..  6
     enum { CallConvMask = 0x7 };
     enum { NoReturnMask = 0x8 };
     enum { RegParmMask = ~(CallConvMask | NoReturnMask),
            RegParmOffset = 4 };
 
-    unsigned Bits;
+    unsigned char Bits;
 
-    ExtInfo(unsigned Bits) : Bits(Bits) {}
+    ExtInfo(unsigned Bits) : Bits(static_cast<unsigned char>(Bits)) {}
 
     friend class FunctionType;
 
index 2a75ff0b34063a6073456c912ad4dfbb5a085926..04440ef9a5de13843b2efd30e388ce545554c291 100644 (file)
@@ -1327,7 +1327,6 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
         if (FTI.hasExceptionSpec) {
           EPI.HasExceptionSpec = FTI.hasExceptionSpec;
           EPI.HasAnyExceptionSpec = FTI.hasAnyExceptionSpec;
-          EPI.NumExceptions = FTI.NumExceptions;
           Exceptions.reserve(FTI.NumExceptions);
           for (unsigned ei = 0, ee = FTI.NumExceptions; ei != ee; ++ei) {
             // FIXME: Preserve type source info.
@@ -1337,6 +1336,7 @@ TypeSourceInfo *Sema::GetTypeForDeclarator(Declarator &D, Scope *S,
             if (!CheckSpecifiedExceptionType(ET, FTI.Exceptions[ei].Range))
               Exceptions.push_back(ET);
           }
+          EPI.NumExceptions = Exceptions.size();
           EPI.Exceptions = Exceptions.data();
         }