[cfe-commits] r81498 - in /cfe/trunk: include/clang/AST/Expr.h lib/Sema/SemaExpr.cpp lib/Sema/SemaTemplateInstantiate.cpp

Anders Carlsson andersca at mac.com
Thu Sep 10 18:22:35 PDT 2009


Author: andersca
Date: Thu Sep 10 20:22:35 2009
New Revision: 81498

URL: http://llvm.org/viewvc/llvm-project?rev=81498&view=rev
Log:
Instantiate PredefinedExprs correctly. Patch by Sam Weinig!

Modified:
    cfe/trunk/include/clang/AST/Expr.h
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=81498&r1=81497&r2=81498&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu Sep 10 20:22:35 2009
@@ -363,7 +363,8 @@
   IdentType Type;
 public:
   PredefinedExpr(SourceLocation l, QualType type, IdentType IT)
-    : Expr(PredefinedExprClass, type), Loc(l), Type(IT) {}
+    : Expr(PredefinedExprClass, type, type->isDependentType(), 
+           type->isDependentType()), Loc(l), Type(IT) {}
 
   /// \brief Construct an empty predefined expression.
   explicit PredefinedExpr(EmptyShell Empty)

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=81498&r1=81497&r2=81498&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 10 20:22:35 2009
@@ -1157,12 +1157,17 @@
     currentDecl = Context.getTranslationUnitDecl();
   }
 
-  unsigned Length =
-    PredefinedExpr::ComputeName(Context, IT, currentDecl).length();
+  QualType ResTy;
+  if (cast<DeclContext>(currentDecl)->isDependentContext()) {
+    ResTy = Context.DependentTy;
+  } else {
+    unsigned Length =
+      PredefinedExpr::ComputeName(Context, IT, currentDecl).length();
 
-  llvm::APInt LengthI(32, Length + 1);
-  QualType ResTy = Context.CharTy.getQualifiedType(QualType::Const);
-  ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal, 0);
+    llvm::APInt LengthI(32, Length + 1);
+    ResTy = Context.CharTy.getQualifiedType(QualType::Const);
+    ResTy = Context.getConstantArrayType(ResTy, LengthI, ArrayType::Normal, 0);
+  }
   return Owned(new (Context) PredefinedExpr(Loc, ResTy, IT));
 }
 

Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=81498&r1=81497&r2=81498&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Thu Sep 10 20:22:35 2009
@@ -391,6 +391,7 @@
                                   IdentifierInfo *Name,
                                   SourceLocation Loc, SourceRange TypeRange);
 
+    Sema::OwningExprResult TransformPredefinedExpr(PredefinedExpr *E);
     Sema::OwningExprResult TransformDeclRefExpr(DeclRefExpr *E);
 
     /// \brief Transforms a template type parameter type by performing
@@ -451,6 +452,29 @@
 }
 
 Sema::OwningExprResult
+TemplateInstantiator::TransformPredefinedExpr(PredefinedExpr *E) {
+  if (!E->isTypeDependent())
+    return SemaRef.Owned(E->Retain());
+
+  FunctionDecl *currentDecl = getSema().getCurFunctionDecl();
+  assert(currentDecl && "Must have current function declaration when "
+                        "instantiating.");
+
+  PredefinedExpr::IdentType IT = E->getIdentType();
+
+  unsigned Length =
+    PredefinedExpr::ComputeName(getSema().Context, IT, currentDecl).length();
+
+  llvm::APInt LengthI(32, Length + 1);
+  QualType ResTy = getSema().Context.CharTy.getQualifiedType(QualType::Const);
+  ResTy = getSema().Context.getConstantArrayType(ResTy, LengthI, 
+                                                 ArrayType::Normal, 0);
+  PredefinedExpr *PE =
+    new (getSema().Context) PredefinedExpr(E->getLocation(), ResTy, IT);
+  return getSema().Owned(PE);
+}
+
+Sema::OwningExprResult
 TemplateInstantiator::TransformDeclRefExpr(DeclRefExpr *E) {
   // FIXME: Clean this up a bit
   NamedDecl *D = E->getDecl();





More information about the cfe-commits mailing list