[cfe-commits] r127111 - in /cfe/trunk: include/clang/Sema/DeclSpec.h lib/Parse/ParseDecl.cpp lib/Parse/ParseExpr.cpp lib/Sema/DeclSpec.cpp lib/Sema/SemaDecl.cpp lib/Sema/SemaType.cpp

Sebastian Redl sebastian.redl at getdesigned.at
Sat Mar 5 14:42:13 PST 2011


Author: cornedbee
Date: Sat Mar  5 16:42:13 2011
New Revision: 127111

URL: http://llvm.org/viewvc/llvm-project?rev=127111&view=rev
Log:
Propagate new-style exception spec information to Declarator.

Modified:
    cfe/trunk/include/clang/Sema/DeclSpec.h
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/lib/Parse/ParseExpr.cpp
    cfe/trunk/lib/Sema/DeclSpec.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Sema/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/DeclSpec.h?rev=127111&r1=127110&r2=127111&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Sema/DeclSpec.h Sat Mar  5 16:42:13 2011
@@ -1028,11 +1028,8 @@
     /// The qualifier bitmask values are the same as in QualType.
     unsigned TypeQuals : 3;
 
-    /// hasExceptionSpec - True if the function has an exception specification.
-    unsigned hasExceptionSpec : 1;
-
-    /// hasAnyExceptionSpec - True if the function has a throw(...) specifier.
-    unsigned hasAnyExceptionSpec : 1;
+    /// ExceptionSpecType - An ExceptionSpecificationType value.
+    unsigned ExceptionSpecType : 3;
 
     /// DeleteArgInfo - If this is true, we need to delete[] ArgInfo.
     unsigned DeleteArgInfo : 1;
@@ -1044,28 +1041,34 @@
     /// declarator.
     unsigned NumArgs;
 
-    /// NumExceptions - This is the number of types in the exception-decl, if
-    /// the function has one.
+    /// NumExceptions - This is the number of types in the dynamic-exception-
+    /// decl, if the function has one.
     unsigned NumExceptions;
 
     /// \brief The location of the ref-qualifier, if any.
     ///
     /// If this is an invalid location, there is no ref-qualifier.
     unsigned RefQualifierLoc;
-    
-    /// ThrowLoc - When hasExceptionSpec is true, the location of the throw
+
+    /// \brief When ExceptionSpecType isn't EST_None, the location of the
     /// keyword introducing the spec.
-    unsigned ThrowLoc;
+    unsigned ExceptionSpecLoc;
 
     /// ArgInfo - This is a pointer to a new[]'d array of ParamInfo objects that
     /// describe the arguments for this function declarator.  This is null if
     /// there are no arguments specified.
     ParamInfo *ArgInfo;
 
-    /// Exceptions - This is a pointer to a new[]'d array of TypeAndRange
-    /// objects that contain the types in the function's exception
-    /// specification and their locations.
-    TypeAndRange *Exceptions;
+    union {
+      /// \brief Pointer to a new[]'d array of TypeAndRange objects that
+      /// contain the types in the function's dynamic exception specification
+      /// and their locations, if there is one.
+      TypeAndRange *Exceptions;
+
+      /// \brief Pointer to the expression in the noexcept-specifier of this
+      /// function, if it has one.
+      Expr *NoexceptExpr;
+    };
 
     /// TrailingReturnType - If this isn't null, it's the trailing return type
     /// specified. This is actually a ParsedType, but stored as void* to
@@ -1085,7 +1088,8 @@
     void destroy() {
       if (DeleteArgInfo)
         delete[] ArgInfo;
-      delete[] Exceptions;
+      if (getExceptionSpecType() == EST_Dynamic)
+        delete[] Exceptions;
     }
 
     /// isKNRPrototype - Return true if this is a K&R style identifier list,
@@ -1098,18 +1102,23 @@
     SourceLocation getEllipsisLoc() const {
       return SourceLocation::getFromRawEncoding(EllipsisLoc);
     }
-    SourceLocation getThrowLoc() const {
-      return SourceLocation::getFromRawEncoding(ThrowLoc);
+    SourceLocation getExceptionSpecLoc() const {
+      return SourceLocation::getFromRawEncoding(ExceptionSpecLoc);
     }
-    
+
     /// \brief Retrieve the location of the ref-qualifier, if any.
     SourceLocation getRefQualifierLoc() const {
       return SourceLocation::getFromRawEncoding(RefQualifierLoc);
     }
-    
+
     /// \brief Determine whether this function declaration contains a 
     /// ref-qualifier.
     bool hasRefQualifier() const { return getRefQualifierLoc().isValid(); }
+
+    /// \brief Get the type of exception specification this function has.
+    ExceptionSpecificationType getExceptionSpecType() const {
+      return static_cast<ExceptionSpecificationType>(ExceptionSpecType);
+    }
   };
 
   struct BlockPointerTypeInfo : TypeInfoCommon {
@@ -1233,15 +1242,16 @@
                                      unsigned TypeQuals, 
                                      bool RefQualifierIsLvalueRef,
                                      SourceLocation RefQualifierLoc,
-                                     bool hasExceptionSpec,
-                                     SourceLocation ThrowLoc,
-                                     bool hasAnyExceptionSpec,
+                                     ExceptionSpecificationType ESpecType,
+                                     SourceLocation ESpecLoc,
                                      ParsedType *Exceptions,
                                      SourceRange *ExceptionRanges,
                                      unsigned NumExceptions,
+                                     Expr *NoexceptExpr,
                                      SourceLocation LPLoc, SourceLocation RPLoc,
                                      Declarator &TheDeclarator,
-                                     ParsedType TrailingReturnType = ParsedType());
+                                     ParsedType TrailingReturnType =
+                                                    ParsedType());
 
   /// getBlockPointer - Return a DeclaratorChunk for a block.
   ///

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=127111&r1=127110&r2=127111&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Sat Mar  5 16:42:13 2011
@@ -3197,13 +3197,12 @@
                                                DS.getTypeQualifiers(),
                                                RefQualifierIsLValueRef,
                                                RefQualifierLoc,
-                                               ESpecType == EST_Dynamic ||
-                                                 ESpecType == EST_DynamicAny,
-                                               ESpecRange.getBegin(),
-                                               ESpecType == EST_DynamicAny,
+                                               ESpecType, ESpecRange.getBegin(),
                                                DynamicExceptions.data(),
                                                DynamicExceptionRanges.data(),
                                                DynamicExceptions.size(),
+                                               NoexceptExpr.isUsable() ?
+                                                 NoexceptExpr.get() : 0,
                                                LParenLoc, RParenLoc, D,
                                                TrailingReturnType),
                   EndLoc);
@@ -3453,13 +3452,12 @@
                                              DS.getTypeQualifiers(),
                                              RefQualifierIsLValueRef,
                                              RefQualifierLoc,
-                                             ESpecType == EST_Dynamic ||
-                                               ESpecType == EST_DynamicAny,
-                                             ESpecRange.getBegin(),
-                                             ESpecType == EST_DynamicAny,
+                                             ESpecType, ESpecRange.getBegin(),
                                              DynamicExceptions.data(),
                                              DynamicExceptionRanges.data(),
                                              DynamicExceptions.size(),
+                                             NoexceptExpr.isUsable() ?
+                                               NoexceptExpr.get() : 0,
                                              LParenLoc, RParenLoc, D,
                                              TrailingReturnType),
                 EndLoc);
@@ -3537,9 +3535,8 @@
                                              &ParamInfo[0], ParamInfo.size(),
                                              /*TypeQuals*/0,
                                              true, SourceLocation(),
-                                             /*exception*/false,
-                                             SourceLocation(), false, 0, 0, 0,
-                                             LParenLoc, RLoc, D),
+                                             EST_None, SourceLocation(), 0, 0,
+                                             0, 0, LParenLoc, RLoc, D),
                 RLoc);
 }
 

Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=127111&r1=127110&r2=127111&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Sat Mar  5 16:42:13 2011
@@ -1918,8 +1918,9 @@
                                                        SourceLocation(),
                                                        0, 0, 0,
                                                        true, SourceLocation(),
-                                                       false, SourceLocation(),
-                                                       false, 0, 0, 0,
+                                                       EST_None,
+                                                       SourceLocation(),
+                                                       0, 0, 0, 0,
                                                        CaretLoc, CaretLoc,
                                                        ParamInfo),
                           CaretLoc);

Modified: cfe/trunk/lib/Sema/DeclSpec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=127111&r1=127110&r2=127111&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Sema/DeclSpec.cpp Sat Mar  5 16:42:13 2011
@@ -142,35 +142,36 @@
                                              unsigned TypeQuals,
                                              bool RefQualifierIsLvalueRef,
                                              SourceLocation RefQualifierLoc,
-                                             bool hasExceptionSpec,
-                                             SourceLocation ThrowLoc,
-                                             bool hasAnyExceptionSpec,
+                                             ExceptionSpecificationType
+                                                 ESpecType,
+                                             SourceLocation ESpecLoc,
                                              ParsedType *Exceptions,
                                              SourceRange *ExceptionRanges,
                                              unsigned NumExceptions,
+                                             Expr *NoexceptExpr,
                                              SourceLocation LPLoc,
                                              SourceLocation RPLoc,
                                              Declarator &TheDeclarator,
                                              ParsedType TrailingReturnType) {
   DeclaratorChunk I;
-  I.Kind                 = Function;
-  I.Loc                  = LPLoc;
-  I.EndLoc               = RPLoc;
-  I.Fun.AttrList         = attrs.getList();
-  I.Fun.hasPrototype     = hasProto;
-  I.Fun.isVariadic       = isVariadic;
-  I.Fun.EllipsisLoc      = EllipsisLoc.getRawEncoding();
-  I.Fun.DeleteArgInfo    = false;
-  I.Fun.TypeQuals        = TypeQuals;
-  I.Fun.NumArgs          = NumArgs;
-  I.Fun.ArgInfo          = 0;
+  I.Kind                        = Function;
+  I.Loc                         = LPLoc;
+  I.EndLoc                      = RPLoc;
+  I.Fun.AttrList                = attrs.getList();
+  I.Fun.hasPrototype            = hasProto;
+  I.Fun.isVariadic              = isVariadic;
+  I.Fun.EllipsisLoc             = EllipsisLoc.getRawEncoding();
+  I.Fun.DeleteArgInfo           = false;
+  I.Fun.TypeQuals               = TypeQuals;
+  I.Fun.NumArgs                 = NumArgs;
+  I.Fun.ArgInfo                 = 0;
   I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
-  I.Fun.RefQualifierLoc = RefQualifierLoc.getRawEncoding();
-  I.Fun.hasExceptionSpec = hasExceptionSpec;
-  I.Fun.ThrowLoc         = ThrowLoc.getRawEncoding();
-  I.Fun.hasAnyExceptionSpec = hasAnyExceptionSpec;
-  I.Fun.NumExceptions    = NumExceptions;
-  I.Fun.Exceptions       = 0;
+  I.Fun.RefQualifierLoc         = RefQualifierLoc.getRawEncoding();
+  I.Fun.ExceptionSpecType       = ESpecType;
+  I.Fun.ExceptionSpecLoc        = ESpecLoc.getRawEncoding();
+  I.Fun.NumExceptions           = 0;
+  I.Fun.Exceptions              = 0;
+  I.Fun.NoexceptExpr            = 0;
   I.Fun.TrailingReturnType   = TrailingReturnType.getAsOpaquePtr();
 
   // new[] an argument array if needed.
@@ -190,13 +191,25 @@
     }
     memcpy(I.Fun.ArgInfo, ArgInfo, sizeof(ArgInfo[0])*NumArgs);
   }
-  // new[] an exception array if needed
-  if (NumExceptions) {
-    I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions];
-    for (unsigned i = 0; i != NumExceptions; ++i) {
-      I.Fun.Exceptions[i].Ty = Exceptions[i];
-      I.Fun.Exceptions[i].Range = ExceptionRanges[i];
+
+  // Check what exception specification information we should actually store.
+  switch (ESpecType) {
+  default: break; // By default, save nothing.
+  case EST_Dynamic:
+    // new[] an exception array if needed
+    if (NumExceptions) {
+      I.Fun.NumExceptions = NumExceptions;
+      I.Fun.Exceptions = new DeclaratorChunk::TypeAndRange[NumExceptions];
+      for (unsigned i = 0; i != NumExceptions; ++i) {
+        I.Fun.Exceptions[i].Ty = Exceptions[i];
+        I.Fun.Exceptions[i].Range = ExceptionRanges[i];
+      }
     }
+    break;
+
+  case EST_ComputedNoexcept:
+    I.Fun.NoexceptExpr = NoexceptExpr;
+    break;
   }
   return I;
 }

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=127111&r1=127110&r2=127111&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sat Mar  5 16:42:13 2011
@@ -5758,8 +5758,8 @@
   D.AddTypeInfo(DeclaratorChunk::getFunction(ParsedAttributes(),
                                              false, false, SourceLocation(), 0,
                                              0, 0, true, SourceLocation(),
-                                             false, SourceLocation(),
-                                             false, 0,0,0, Loc, Loc, D),
+                                             EST_None, SourceLocation(),
+                                             0, 0, 0, 0, Loc, Loc, D),
                 SourceLocation());
   D.SetIdentifier(&II, Loc);
 

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=127111&r1=127110&r2=127111&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sat Mar  5 16:42:13 2011
@@ -511,7 +511,7 @@
                              /*args*/ 0, 0,
                              /*type quals*/ 0,
                              /*ref-qualifier*/true, SourceLocation(),
-                             /*EH*/ false, SourceLocation(), false, 0, 0, 0,
+                             /*EH*/ EST_None, SourceLocation(), 0, 0, 0, 0,
                              /*parens*/ loc, loc,
                              declarator));
 
@@ -1764,9 +1764,9 @@
 
       // Exception specs are not allowed in typedefs. Complain, but add it
       // anyway.
-      if (FTI.hasExceptionSpec &&
+      if (FTI.getExceptionSpecType() != EST_None &&
           D.getDeclSpec().getStorageClassSpec() == DeclSpec::SCS_typedef)
-        Diag(FTI.getThrowLoc(), diag::err_exception_spec_in_typedef);
+        Diag(FTI.getExceptionSpecLoc(), diag::err_exception_spec_in_typedef);
 
       if (!FTI.NumArgs && !FTI.isVariadic && !getLangOptions().CPlusPlus) {
         // Simple void foo(), where the incoming T is the result type.
@@ -1855,9 +1855,11 @@
         }
 
         llvm::SmallVector<QualType, 4> Exceptions;
-        if (FTI.hasExceptionSpec) {
-          EPI.HasExceptionSpec = FTI.hasExceptionSpec;
-          EPI.HasAnyExceptionSpec = FTI.hasAnyExceptionSpec;
+        if (FTI.getExceptionSpecType() == EST_Dynamic ||
+            FTI.getExceptionSpecType() == EST_DynamicAny) {
+          EPI.HasExceptionSpec = true;
+          EPI.HasAnyExceptionSpec =
+              FTI.getExceptionSpecType() == EST_DynamicAny;
           Exceptions.reserve(FTI.NumExceptions);
           for (unsigned ei = 0, ee = FTI.NumExceptions; ei != ee; ++ei) {
             // FIXME: Preserve type source info.





More information about the cfe-commits mailing list