[llvm-bugs] [Bug 41622] New: Clang crash on C++17 lambda error correction

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Apr 26 20:33:33 PDT 2019


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

            Bug ID: 41622
           Summary: Clang crash on C++17 lambda error correction
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++'17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rtrieu at google.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

In C++17 mode, Clang improperly corrects for an implicitly captured this
pointer in a lambda.  When the lambda is used later, Clang attempts to analyze
the lambda, but fails and crashes.

$ cat test.ii
class S {
  int num;
  void Test() {
    auto lambda = []() { return num; };
    lambda() == 1;
  }
};

$ clang -std=c++17 test.ii
test.ii:4:33: error: 'this' cannot be implicitly captured in this context
    auto lambda = []() { return num; };
                                ^
test.ii:5:14: warning: equality comparison result unused [-Wunused-comparison]
    lambda() == 1;
    ~~~~~~~~~^~~~
Stack dump:
 #4 0x0000000003a85dff HandleLValueMember((anonymous namespace)::EvalInfo&,
clang::Expr const*, (anonymous namespace)::LValue&, clang::FieldDecl const*,
clang::ASTRecordLayout const*) (/usr/local/bin/clang-9+0x3a85dff)
 #5 0x0000000003a7d889 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::PointerExprEvaluator, bool>::Visit(clang::Stmt const*)
(/usr/local/bin/clang-9+0x3a7d889)
 #6 0x0000000003a72ee4 clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::LValueExprEvaluator, bool>::Visit(clang::Stmt const*)
(/usr/local/bin/clang-9+0x3a72ee4)
 #7 0x0000000003aa6323 (anonymous
namespace)::IntExprEvaluator::VisitCastExpr(clang::CastExpr const*)
(/usr/local/bin/clang-9+0x3aa6323)
 #8 0x0000000003a6b90e Evaluate(clang::APValue&, (anonymous
namespace)::EvalInfo&, clang::Expr const*) (/usr/local/bin/clang-9+0x3a6b90e)
 #9 0x0000000003a846fe EvaluateStmt((anonymous namespace)::StmtResult&,
(anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*)
(/usr/local/bin/clang-9+0x3a846fe)
#10 0x0000000003a83dda EvaluateStmt((anonymous namespace)::StmtResult&,
(anonymous namespace)::EvalInfo&, clang::Stmt const*, clang::SwitchCase const*)
(/usr/local/bin/clang-9+0x3a83dda)
#11 0x0000000003a7085e HandleFunctionCall(clang::SourceLocation,
clang::FunctionDecl const*, (anonymous namespace)::LValue const*,
llvm::ArrayRef<clang::Expr const*>, clang::Stmt const*, (anonymous
namespace)::EvalInfo&, clang::APValue&, (anonymous namespace)::LValue const*)
(/usr/local/bin/clang-9+0x3a7085e)
#12 0x0000000003aa59ee (anonymous namespace)::ExprEvaluatorBase<(anonymous
namespace)::IntExprEvaluator>::handleCallExpr(clang::CallExpr const*,
clang::APValue&, (anonymous namespace)::LValue const*)
(/usr/local/bin/clang-9+0x3aa59ee)
#13 0x0000000003a862fb clang::StmtVisitorBase<llvm::make_const_ptr, (anonymous
namespace)::IntExprEvaluator, bool>::Visit(clang::Stmt const*)
(/usr/local/bin/clang-9+0x3a862fb)
#14 0x0000000003a6b90e Evaluate(clang::APValue&, (anonymous
namespace)::EvalInfo&, clang::Expr const*) (/usr/local/bin/clang-9+0x3a6b90e)
#15 0x0000000003a6da06 EvaluateAsRValue((anonymous namespace)::EvalInfo&,
clang::Expr const*, clang::APValue&) (/usr/local/bin/clang-9+0x3a6da06)
#16 0x0000000003a6f2e8 clang::Expr::isCXX11ConstantExpr(clang::ASTContext
const&, clang::APValue*, clang::SourceLocation*) const
(/usr/local/bin/clang-9+0x3a6f2e8)
#17 0x0000000003a6ee5c clang::Expr::isIntegerConstantExpr(llvm::APSInt&,
clang::ASTContext const&, clang::SourceLocation*, bool) const
(/usr/local/bin/clang-9+0x3a6ee5c)
#18 0x00000000032cffc1 AnalyzeImplicitConversions(clang::Sema&, clang::Expr*,
clang::SourceLocation) (/usr/local/bin/clang-9+0x32cffc1)
#19 0x00000000032d33ce clang::Sema::CheckCompletedExpr(clang::Expr*,
clang::SourceLocation, bool) (/usr/local/bin/clang-9+0x32d33ce)
#20 0x000000000356aad8 clang::Sema::ActOnFinishFullExpr(clang::Expr*,
clang::SourceLocation, bool, bool) (/usr/local/bin/clang-9+0x356aad8)
#21 0x00000000036db041
clang::Sema::ActOnExprStmt(clang::ActionResult<clang::Expr*, true>, bool)
(/usr/local/bin/clang-9+0x36db041)
#22 0x0000000003203bbc
clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext)
(/usr/local/bin/clang-9+0x3203bbc)
#23 0x000000000320231c
clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*,
clang::Parser::ParsedAttributesWithRange&) (/usr/local/bin/clang-9+0x320231c)
#24 0x0000000003201e42
clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*)
(/usr/local/bin/clang-9+0x3201e42)
#25 0x00000000032098a1 clang::Parser::ParseCompoundStatementBody(bool)
(/usr/local/bin/clang-9+0x32098a1)

-- 
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/20190427/9a466273/attachment-0001.html>


More information about the llvm-bugs mailing list