[cfe-commits] r84763 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaDeclCXX.cpp lib/Sema/SemaExprCXX.cpp lib/Sema/SemaOverload.cpp lib/Sema/SemaTemplate.cpp test/CodeGenCXX/address-of-fntemplate.cpp
Anders Carlsson
andersca at mac.com
Wed Oct 21 10:16:24 PDT 2009
Author: andersca
Date: Wed Oct 21 12:16:23 2009
New Revision: 84763
URL: http://llvm.org/viewvc/llvm-project?rev=84763&view=rev
Log:
Change FixOverloadedFunctionReference to return a (possibly new) expression. Substitute TemplateIdRefExprs with DeclRefExprs. Doug, plz review :)
Modified:
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/test/CodeGenCXX/address-of-fntemplate.cpp
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=84763&r1=84762&r2=84763&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Oct 21 12:16:23 2009
@@ -929,7 +929,7 @@
FunctionDecl *ResolveAddressOfOverloadedFunction(Expr *From, QualType ToType,
bool Complain);
- bool FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
+ Expr *FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn);
void AddOverloadedCallCandidates(NamedDecl *Callee,
DeclarationName &UnqualifiedName,
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=84763&r1=84762&r2=84763&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Oct 21 12:16:23 2009
@@ -3569,7 +3569,7 @@
if (DiagnoseUseOfDecl(Fn, DeclLoc))
return true;
- FixOverloadedFunctionReference(Init, Fn);
+ Init = FixOverloadedFunctionReference(Init, Fn);
}
T2 = Fn->getType();
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=84763&r1=84762&r2=84763&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Wed Oct 21 12:16:23 2009
@@ -1226,12 +1226,13 @@
if (DiagnoseUseOfDecl(Fn, From->getSourceRange().getBegin()))
return true;
- bool WasAddrOf = FixOverloadedFunctionReference(From, Fn);
+ From = FixOverloadedFunctionReference(From, Fn);
FromType = From->getType();
+
// If there's already an address-of operator in the expression, we have
// the right type already, and the code below would just introduce an
// invalid additional pointer level.
- if (WasAddrOf)
+ if (FromType->isPointerType() || FromType->isMemberFunctionPointerType())
break;
}
FromType = Context.getPointerType(FromType);
Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=84763&r1=84762&r2=84763&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Oct 21 12:16:23 2009
@@ -5368,13 +5368,12 @@
/// a C++ overloaded function (possibly with some parentheses and
/// perhaps a '&' around it). We have resolved the overloaded function
/// to the function declaration Fn, so patch up the expression E to
-/// refer (possibly indirectly) to Fn.
-/// Returns true if the function reference used an explicit address-of operator.
-bool Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn) {
+/// refer (possibly indirectly) to Fn. Returns the new expr.
+Expr *Sema::FixOverloadedFunctionReference(Expr *E, FunctionDecl *Fn) {
if (ParenExpr *PE = dyn_cast<ParenExpr>(E)) {
- bool ret = FixOverloadedFunctionReference(PE->getSubExpr(), Fn);
- E->setType(PE->getSubExpr()->getType());
- return ret;
+ Expr *NewExpr = FixOverloadedFunctionReference(PE->getSubExpr(), Fn);
+ NewExpr->setType(PE->getSubExpr()->getType());
+ return NewExpr;
} else if (UnaryOperator *UnOp = dyn_cast<UnaryOperator>(E)) {
assert(UnOp->getOpcode() == UnaryOperator::AddrOf &&
"Can only take the address of an overloaded function");
@@ -5393,12 +5392,14 @@
= Context.getTypeDeclType(cast<RecordDecl>(Method->getDeclContext()));
E->setType(Context.getMemberPointerType(Fn->getType(),
ClassType.getTypePtr()));
- return true;
+ return E;
}
}
- FixOverloadedFunctionReference(UnOp->getSubExpr(), Fn);
- E->setType(Context.getPointerType(UnOp->getSubExpr()->getType()));
- return true;
+ Expr *NewExpr = FixOverloadedFunctionReference(UnOp->getSubExpr(), Fn);
+ UnOp->setSubExpr(NewExpr);
+ UnOp->setType(Context.getPointerType(NewExpr->getType()));
+
+ return UnOp;
} else if (DeclRefExpr *DR = dyn_cast<DeclRefExpr>(E)) {
assert((isa<OverloadedFunctionDecl>(DR->getDecl()) ||
isa<FunctionTemplateDecl>(DR->getDecl())) &&
@@ -5408,10 +5409,17 @@
} else if (MemberExpr *MemExpr = dyn_cast<MemberExpr>(E)) {
MemExpr->setMemberDecl(Fn);
E->setType(Fn->getType());
+ } else if (TemplateIdRefExpr *TID = dyn_cast<TemplateIdRefExpr>(E)) {
+ // FIXME: Should we create QualifiedDeclRefExprs here too?
+ // FIXME: We should capture the template arguments here.
+ E = new (Context) DeclRefExpr(Fn, Fn->getType(),
+ TID->getSourceRange().getBegin());
+ TID->Destroy(Context);
} else {
assert(false && "Invalid reference to overloaded function");
}
- return false;
+
+ return E;
}
} // end namespace clang
Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=84763&r1=84762&r2=84763&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Wed Oct 21 12:16:23 2009
@@ -2037,7 +2037,7 @@
if (DiagnoseUseOfDecl(Fn, Arg->getSourceRange().getBegin()))
return true;
- FixOverloadedFunctionReference(Arg, Fn);
+ Arg = FixOverloadedFunctionReference(Arg, Fn);
ArgType = Arg->getType();
if (ArgType->isFunctionType() && ParamType->isPointerType()) {
ArgType = Context.getPointerType(Arg->getType());
Modified: cfe/trunk/test/CodeGenCXX/address-of-fntemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/address-of-fntemplate.cpp?rev=84763&r1=84762&r2=84763&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/address-of-fntemplate.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/address-of-fntemplate.cpp Wed Oct 21 12:16:23 2009
@@ -1,8 +1,13 @@
// RUN: clang-cc %s -emit-llvm -o - | FileCheck %s
template <typename T> void f(T) {}
+template <typename T> void f() { }
void test() {
// CHECK: @_Z1fIiEvT_
void (*p)(int) = &f;
+
+ // CHECK: @_Z1fIiEvv
+ void (*p2)() = f<int>;
}
// CHECK: define linkonce_odr void @_Z1fIiEvT_
+// CHECK: define linkonce_odr void @_Z1fIiEvv
More information about the cfe-commits
mailing list