[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-commits
Subject: [PATCH] Sema: Fix spurious 'infinite recursion' warning for overloaded functions
From: Vedant Kumar <vsk () apple ! com>
Date: 2015-07-29 23:41:48
Message-ID: 4754560F-CC21-49CC-9CB1-263F31D75857 () apple ! com
[Download RAW message or body]
Sema::checkRecursiveFunction() currently cannot tell overloaded =
functions apart.
This results in spurious warnings -- clang claims that a function is =
infinitely recursive when it in fact just calls a different function. =
The attached patch fixes the problem by keeping the original =
FunctionDecl around, instead of switching to the 'canonical' decl.
I don't have commit rights, so I'd appreciate someone taking a look at =
the patch and guiding it into trunk :).
vedant
["infinite-recursion-overload.patch" (infinite-recursion-overload.patch)]
diff --git a/lib/Sema/AnalysisBasedWarnings.cpp b/lib/Sema/AnalysisBasedWarnings.cpp
index 59c25d2..5688aac 100644
--- a/lib/Sema/AnalysisBasedWarnings.cpp
+++ b/lib/Sema/AnalysisBasedWarnings.cpp
@@ -180,8 +180,7 @@ static bool hasRecursiveCallInPath(const FunctionDecl *FD, CFGBlock &Block) {
continue;
const CallExpr *CE = dyn_cast<CallExpr>(B.getAs<CFGStmt>()->getStmt());
- if (!CE || !CE->getCalleeDecl() ||
- CE->getCalleeDecl()->getCanonicalDecl() != FD)
+ if (!CE || !CE->getCalleeDecl() || CE->getCalleeDecl() != FD)
continue;
// Skip function calls which are qualified with a templated class.
@@ -241,8 +240,6 @@ static void checkForFunctionCall(Sema &S, const FunctionDecl *FD,
static void checkRecursiveFunction(Sema &S, const FunctionDecl *FD,
const Stmt *Body,
AnalysisDeclContext &AC) {
- FD = FD->getCanonicalDecl();
-
// Only run on non-templated functions and non-templated members of
// templated classes.
if (FD->getTemplatedKind() != FunctionDecl::TK_NonTemplate &&
diff --git a/test/SemaCXX/warn-infinite-recursion.cpp b/test/SemaCXX/warn-infinite-recursion.cpp
index e1b7c54..f45d1bd 100644
--- a/test/SemaCXX/warn-infinite-recursion.cpp
+++ b/test/SemaCXX/warn-infinite-recursion.cpp
@@ -150,3 +150,11 @@ int test_wrapper() {
}
int wrapper_sum = test_wrapper<2>(); // expected-note{{instantiation}}
+
+int test_overload(int x) {
+ return 0;
+}
+
+int test_overload(int *p) {
+ return test_overload(*p);
+}
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic