[llvm-bugs] [Bug 39031] New: Clang crashes in CodeGen on invalid code in a template instantiation

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Sep 20 19:53:31 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=39031

            Bug ID: 39031
           Summary: Clang crashes in CodeGen on invalid code in a template
                    instantiation
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rtrieu at google.com
                CC: llvm-bugs at lists.llvm.org

Expected:
Clang generates an error that an int can not be called.  T() is an int in the
instantation.

Actual:
Clang crashes

$ cat test.cc
template <typename>
struct S { 
  template <typename>
  struct Wrapper;

  template <>
  struct Wrapper<int> {
    template <typename T>
    void operator()(T) {
      T()();
    }
  };
};

void Run() {
  S<int>::Wrapper<int>()(1);
}

$ clang test.cc
...
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      test.cc:9:10: Generating code for declaration
'S<int>::Wrapper<int>::operator()'
...
#4 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr
const*)
#5 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) 
#6 clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*)
#7 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*,
llvm::ArrayRef<clang::Attr const*>)
#8
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
const&, bool, clang::CodeGen::AggValueSlot)
#9
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::CodeGen::FunctionArgList&,
clang::Stmt const*)
#10 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&)
#11
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
#12 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
#13 clang::CodeGen::CodeGenModule::EmitDeferred()
#14 clang::CodeGen::CodeGenModule::Release()
#15 (anonymous
namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&)


Making struct S not a template gives a better error message:
test.cc:10:7: error: called object type 'int' is not a function or function
      pointer
      T()();
      ^~~
test.cc:16:20: note: in instantiation of function template specialization
      'S::Wrapper<int>::operator()<int>' requested here
  S::Wrapper<int>()(1);
                   ^
1 error generated.

-- 
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/20180921/8c214d3b/attachment.html>


More information about the llvm-bugs mailing list