[LLVMbugs] [Bug 21193] New: Out of line template function declaration not matching any declaration causing null deference at clang/lib/Sema/SemaExpr.cpp:1786

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Oct 7 12:12:21 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=21193

            Bug ID: 21193
           Summary: Out of line template function declaration not matching
                    any declaration causing null deference at
                    clang/lib/Sema/SemaExpr.cpp:1786
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rtrieu at google.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

a.cc:
class Bar {
 public:
  template <typename U>
  void A(U u) {
    B(u);
  }
};

template <typename U>
void Bar::B(U u);

void test() {
  Bar().A(0);
}

commandline:
clang -cc1 -fsyntax-only a.cc

output:
a.cc:10:11: error: out-of-line declaration of 'B' does not match any
declaration in 'Bar'
void Bar::B(U u);
          ^
a.cc:5:5: error: use of undeclared identifier 'B'
    B(u);
    ^
    this->
a.cc:13:9: note: in instantiation of function template specialization
'Bar::A<int>' requested here
  Bar().A(0);
        ^
0  clang           0x00000000011c2495 llvm::sys::PrintStackTrace(_IO_FILE*) +
37
1  clang           0x00000000011c2853
2  libpthread.so.0 0x00007f36a4b73cb0
3  clang           0x0000000001cc821c
clang::Sema::DiagnoseEmptyLookup(clang::Scope*, clang::CXXScopeSpec&,
clang::LookupResult&, clang::CorrectionCandidateCallback&,
clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>) + 2796
4  clang           0x0000000001df9a0c
5  clang           0x0000000001dee713
6  clang           0x0000000001dee5c4
clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*,
clang::UnresolvedLookupExpr*, clang::SourceLocation,
llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool)
+ 644
7  clang           0x0000000001cc336f clang::Sema::ActOnCallExpr(clang::Scope*,
clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation, clang::Expr*, bool) + 1295
8  clang           0x0000000001eb9f07
9  clang           0x0000000001ea9e79
10 clang           0x0000000001ea9614
11 clang           0x0000000001eb8281
12 clang           0x0000000001ea95c1 clang::Sema::SubstStmt(clang::Stmt*,
clang::MultiLevelTemplateArgumentList const&) + 65
13 clang           0x0000000001ecebae
clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation,
clang::FunctionDecl*, bool, bool) + 1950
14 clang           0x0000000001ecf9ca
clang::Sema::PerformPendingInstantiations(bool) + 138
15 clang           0x0000000001b3ab6d clang::Sema::ActOnEndOfTranslationUnit()
+ 525
16 clang           0x00000000019a6a98
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 168
17 clang           0x00000000019a34d6 clang::ParseAST(clang::Sema&, bool, bool)
+ 422
18 clang           0x000000000132e329 clang::FrontendAction::Execute() + 57
19 clang           0x00000000013023e3
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 803
20 clang           0x000000000139ab5e
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 2830
21 clang           0x00000000006c7263 cc1_main(llvm::ArrayRef<char const*>,
char const*, void*) + 675
22 clang           0x00000000006c628a main + 12234
23 libc.so.6       0x00007f36a409d76d __libc_start_main + 237
24 clang           0x00000000006c318d
Stack dump:
0.    Program arguments: clang -cc1 -fsyntax-only a.cc 
1.    <eof> parser at end of file
2.    a.cc:4:8: instantiating function definition 'A'
Segmentation fault (core dumped)

Code:
1781              CXXMethodDecl *DepMethod;
1782              if (CurMethod->isDependentContext())
1783                DepMethod = CurMethod;
1784              else if (CurMethod->getTemplatedKind() ==
1785                  FunctionDecl::TK_FunctionTemplateSpecialization)
1786                DepMethod =
cast<CXXMethodDecl>(CurMethod->getPrimaryTemplate()->
1787                   
getInstantiatedFromMemberTemplate()->getTemplatedDecl());
1788              else
1789                DepMethod = cast<CXXMethodDecl>(
1790                    CurMethod->getInstantiatedFromMemberFunction());

On line 1786-87,
CurMethod->getPrimaryTemplate()->getInstantiatedFromMemberTemplate() returns a
null pointer, which gets dereferenced.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20141007/381d8e82/attachment.html>


More information about the llvm-bugs mailing list