summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-09-11 01:22:35 +0000
committerAnders Carlsson <andersca@mac.com>2009-09-11 01:22:35 +0000
commit0b209a863208b4a0002f48fc82e514a3012e0593 (patch)
tree08e0557ab443fe203df15626c6dda00ed20e4a84
parent33a004e9eb63929791923b1f96720171f769af87 (diff)
downloadbcm5719-llvm-0b209a863208b4a0002f48fc82e514a3012e0593.tar.gz
bcm5719-llvm-0b209a863208b4a0002f48fc82e514a3012e0593.zip
Instantiate PredefinedExprs correctly. Patch by Sam Weinig!
llvm-svn: 81498
-rw-r--r--clang/include/clang/AST/Expr.h3
-rw-r--r--clang/lib/Sema/SemaExpr.cpp15
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiate.cpp24
3 files changed, 36 insertions, 6 deletions
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 604765f66d7..14e5972f0f6 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -363,7 +363,8 @@ private:
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)
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 53f3dde2831..3f456d4d9b5 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -1157,12 +1157,17 @@ Sema::OwningExprResult Sema::ActOnPredefinedExpr(SourceLocation Loc,
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));
}
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 912b965507e..651d4a50dc8 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -391,6 +391,7 @@ namespace {
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 @@ TemplateInstantiator::RebuildExceptionDecl(VarDecl *ExceptionDecl,
}
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();
OpenPOWER on IntegriCloud