csmith-project / creduce

C-Reduce, a C and C++ program reducer
Other
1.25k stars 123 forks source link

clang_delta remove-unused-function infinite recursion #207

Closed user202729 closed 4 years ago

user202729 commented 4 years ago

(version: latest git master)

The file that crash the the program is rather large, but it can be obtained by preprocessing any file with #include "range/v3/all.hpp".

The infinite recursion happens in lookupFunctionDeclShallow. With this patch applied, the crash doesn't happen: (however the program might be incorrect)

--- a/clang_delta/RemoveUnusedFunction.cpp
+++ b/clang_delta/RemoveUnusedFunction.cpp
@@ -706,7 +706,7 @@ RemoveUnusedFunction::lookupFunctionDeclShallow(const DeclarationName &DName,
   for (auto *I : Ctx->using_directives()) {
     const NamespaceDecl *ND = I->getNominatedNamespace();
     // avoid infinite recursion
-    if (ND->getLookupParent() == Ctx)
+    if (ND == Ctx || ND->getLookupParent() == Ctx)
       return NULL;
     if (const FunctionDecl *FD = lookupFunctionDeclShallow(DName, ND))
       return FD;
marxin commented 4 years ago

Reduced test-case:

namespace a {
inline namespace b {
using namespace a;
}
struct c;
namespace {
using a::c;
}
} // namespace a
chenyang78 commented 4 years ago

@marxin Thank you so much!

chenyang78 commented 4 years ago

I committed the fix in d83cbda. Thanks, @user202729 and @marxin !