[cfe-commits] r120706 - in /cfe/trunk/include/clang/AST: TemplateBase.h TypeLoc.h

Douglas Gregor dgregor at apple.com
Thu Dec 2 08:14:14 PST 2010


Author: dgregor
Date: Thu Dec  2 10:14:14 2010
New Revision: 120706

URL: http://llvm.org/viewvc/llvm-project?rev=120706&view=rev
Log:
Remove NDEBUG-controlled extra data from
TemplateArgumentLocInfo. Unfortunately, this means that we lose some
internal consistency checking when building a debug Clang. However,
having data structures change size/layout depending on NDEBUG causes
pain for clients of the Clang API.

Modified:
    cfe/trunk/include/clang/AST/TemplateBase.h
    cfe/trunk/include/clang/AST/TypeLoc.h

Modified: cfe/trunk/include/clang/AST/TemplateBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TemplateBase.h?rev=120706&r1=120705&r2=120706&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TemplateBase.h (original)
+++ cfe/trunk/include/clang/AST/TemplateBase.h Thu Dec  2 10:14:14 2010
@@ -283,42 +283,15 @@
     } Template;
   };
 
-#ifndef NDEBUG
-  enum Kind {
-    K_None,
-    K_TypeSourceInfo,
-    K_Expression,
-    K_Template
-  } Kind;
-#endif
-
 public:
-  TemplateArgumentLocInfo()
-    : Expression(0)
-#ifndef NDEBUG
-      , Kind(K_None) 
-#endif
-    {}
+  TemplateArgumentLocInfo() : Expression(0) {}
   
-  TemplateArgumentLocInfo(TypeSourceInfo *TInfo)
-    : Declarator(TInfo)
-#ifndef NDEBUG
-      , Kind(K_TypeSourceInfo) 
-#endif
-    {}
+  TemplateArgumentLocInfo(TypeSourceInfo *TInfo) : Declarator(TInfo) {}
   
-  TemplateArgumentLocInfo(Expr *E)
-    : Expression(E)
-#ifndef NDEBUG
-      , Kind(K_Expression) 
-#endif
-    {}
+  TemplateArgumentLocInfo(Expr *E) : Expression(E) {}
   
   TemplateArgumentLocInfo(SourceRange QualifierRange, 
                           SourceLocation TemplateNameLoc)
-#ifndef NDEBUG
-    : Kind(K_Template)
-#endif
   {
     Template.QualifierRange[0] = QualifierRange.getBegin().getRawEncoding();
     Template.QualifierRange[1] = QualifierRange.getEnd().getRawEncoding();
@@ -326,49 +299,22 @@
   }
 
   TypeSourceInfo *getAsTypeSourceInfo() const {
-    assert(Kind == K_TypeSourceInfo);
     return Declarator;
   }
 
   Expr *getAsExpr() const {
-    assert(Kind == K_Expression);
     return Expression;
   }
 
   SourceRange getTemplateQualifierRange() const {
-    assert(Kind == K_Template);
     return SourceRange(
                 SourceLocation::getFromRawEncoding(Template.QualifierRange[0]),
                 SourceLocation::getFromRawEncoding(Template.QualifierRange[1]));
   }
   
   SourceLocation getTemplateNameLoc() const {
-    assert(Kind == K_Template);
     return SourceLocation::getFromRawEncoding(Template.TemplateNameLoc);
   }
-  
-#ifndef NDEBUG
-  void validateForArgument(const TemplateArgument &Arg) {
-    switch (Arg.getKind()) {
-    case TemplateArgument::Type:
-      assert(Kind == K_TypeSourceInfo);
-      break;
-    case TemplateArgument::Expression:
-    case TemplateArgument::Declaration:
-      assert(Kind == K_Expression);
-      break;
-    case TemplateArgument::Template:
-      assert(Kind == K_Template);
-      break;
-    case TemplateArgument::Integral:
-    case TemplateArgument::Pack:
-      assert(Kind == K_None);
-      break;
-    case TemplateArgument::Null:
-      llvm_unreachable("source info for null template argument?");
-    }
-  }
-#endif
 };
 
 /// Location wrapper for a TemplateArgument.  TemplateArgument is to

Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=120706&r1=120705&r2=120706&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Thu Dec  2 10:14:14 2010
@@ -1013,9 +1013,6 @@
     return getTypePtr()->getNumArgs();
   }
   void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
-#ifndef NDEBUG
-    AI.validateForArgument(getTypePtr()->getArg(i));
-#endif
     getArgInfos()[i] = AI;
   }
   TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {
@@ -1061,34 +1058,8 @@
                                 const TemplateArgument *Args,
                                 TemplateArgumentLocInfo *ArgInfos,
                                 SourceLocation Loc) {
-    for (unsigned i = 0, e = NumArgs; i != e; ++i) {
-      TemplateArgumentLocInfo Info;
-#ifndef NDEBUG
-      // If asserts are enabled, be sure to initialize the argument
-      // loc with the right kind of pointer.
-      switch (Args[i].getKind()) {
-      case TemplateArgument::Expression:
-      case TemplateArgument::Declaration:
-        Info = TemplateArgumentLocInfo((Expr*) 0);
-        break;
-
-      case TemplateArgument::Type:
-        Info = TemplateArgumentLocInfo((TypeSourceInfo*) 0);
-        break;
-
-      case TemplateArgument::Template:
-        Info = TemplateArgumentLocInfo(SourceRange(Loc), Loc);
-        break;
-          
-      case TemplateArgument::Integral:
-      case TemplateArgument::Pack:
-      case TemplateArgument::Null:
-        // K_None is fine.
-        break;
-      }
-#endif
-      ArgInfos[i] = Info;
-    }
+    for (unsigned i = 0, e = NumArgs; i != e; ++i)
+      ArgInfos[i] = TemplateArgumentLocInfo();
   }
 
   unsigned getExtraLocalDataSize() const {
@@ -1384,9 +1355,6 @@
   }
 
   void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI) {
-#ifndef NDEBUG
-    AI.validateForArgument(getTypePtr()->getArg(i));
-#endif
     getArgInfos()[i] = AI;
   }
   TemplateArgumentLocInfo getArgLocInfo(unsigned i) const {





More information about the cfe-commits mailing list