marxin / cvise

Super-parallel Python port of the C-Reduce
Other
219 stars 25 forks source link

clang_delta: […] clang::Expr::ClassifyImpl(…) const: Assertion `isLValue()' failed. #116

Closed mgorny closed 12 months ago

mgorny commented 12 months ago

While trying to reduce a C file, clang_delta, crashes with the following assertion:

00:00:00 INFO ===< ClangBinarySearchPass::replace-function-def-with-decl (30 T) >===
00:00:00 WARNING clang_delta --query-instances failed with exit code -6: clang_delta: /var/tmp/portage/sys-devel/clang-16.0.6/work/clang/lib/AST/ExprClassification.cpp:57: Cl clang::Expr::ClassifyImpl(clang::ASTContext&, clang::SourceLocation*) const: Assertion `isLValue()' failed.

I was able to reproduce it with 2.8.0 and git (594573e041cc2e906c1a81a4aca81ede93efee4a) built against LLVM 16.0.6 with assertions enabled.

I was able to reduce the C source causing the crash (using --not-c) to:

BlocksOutputBuffer_Grow() {
  *avail_out = (size_t)
marxin commented 12 months ago

I cannot reproduce it w/o assertions enabled. Can you please test the latest LLVM release?

mgorny commented 12 months ago

Are you talking of 17.0.0-rc4? I didn't know 17.x was supported, I'll try.

marxin commented 12 months ago

Yes, I've got a nightly runner that runs against the latest LLVM master branch.

mgorny commented 12 months ago

Same result with 17.0.0-rc4 and 18.x from a ~week ago.

marxin commented 12 months ago

I see. Anyway, my Clang internals knowledge is limited, thus I'm not planning to work on this issue. Sorry.

mgorny commented 12 months ago

That's unfortunate. I guess no cvise on Gentoo then, sigh.

marxin commented 12 months ago

For debugging purposes, can you please provide a back-trace? I can't see a call of ClassifyImpl in C-Vise.

I guess no cvise on Gentoo then, sigh.

How do you mean that?

mgorny commented 12 months ago

For debugging purposes, can you please provide a back-trace? I can't see a call of ClassifyImpl in C-Vise.

(gdb) bt
#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007f2433689e2f in __pthread_kill_internal (signo=6, threadid=<optimized out>) at pthread_kill.c:78
#2  0x00007f2433639cc2 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007f24336224ed in __GI_abort () at abort.c:79
#4  0x00007f2433622415 in __assert_fail_base (fmt=0x7f243379fb98 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x7f24413ad88f "isLValue()", 
    file=file@entry=0x7f2441535c70 "/var/tmp/portage/sys-devel/clang-18.0.0_pre20230906/work/clang/lib/AST/ExprClassification.cpp", 
    line=line@entry=57, 
    function=function@entry=0x7f2441536060 "Cl clang::Expr::ClassifyImpl(clang::ASTContext&, clang::SourceLocation*) const")
    at assert.c:92
#5  0x00007f24336325e2 in __assert_fail (assertion=0x7f24413ad88f "isLValue()", 
    file=0x7f2441535c70 "/var/tmp/portage/sys-devel/clang-18.0.0_pre20230906/work/clang/lib/AST/ExprClassification.cpp", line=57, 
    function=0x7f2441536060 "Cl clang::Expr::ClassifyImpl(clang::ASTContext&, clang::SourceLocation*) const") at assert.c:101
#6  0x00007f243e9e37f0 in clang::Expr::ClassifyImpl(clang::ASTContext&, clang::SourceLocation*) const ()
   from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#7  0x00007f243e9e3965 in clang::Expr::isModifiableLvalue(clang::ASTContext&, clang::SourceLocation*) const ()
   from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#8  0x00007f243f3e384c in ?? () from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#9  0x00007f243f42a9f8 in clang::Sema::CheckAssignmentOperands(clang::Expr*, clang::ActionResult<clang::Expr*, true>&, clang::SourceLocation, clang::QualType, clang::BinaryOperatorKind) () from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#10 0x00007f243f43c428 in clang::Sema::CreateBuiltinBinOp(clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) () from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#11 0x00007f243e696d12 in clang::Parser::ParseRHSOfBinaryExpression(clang::ActionResult<clang::Expr*, true>, clang::prec::Level) ()
   from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#12 0x00007f243e6980c9 in clang::Parser::ParseExpression(clang::Parser::TypeCastState) ()
   from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#13 0x00007f243e7107cb in clang::Parser::ParseExprStatement(clang::Parser::ParsedStmtContext) ()
   from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#14 0x00007f243e708183 in clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) ()
   from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#15 0x00007f243e708b65 in clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) () from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#16 0x00007f243e709628 in clang::Parser::ParseCompoundStatementBody(bool) () from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#17 0x00007f243e709fec in clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) ()
   from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#18 0x00007f243e73cb14 in clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) () from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#19 0x00007f243e667c8b in clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) () from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#20 0x00007f243e73827b in clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) () from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#21 0x00007f243e73ded1 in clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) () from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#22 0x00007f243e73f97d in clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) ()
   from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#23 0x00007f243e73fe3f in clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) () from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#24 0x00007f243e63ae7a in clang::ParseAST(clang::Sema&, bool, bool) () from /usr/lib/llvm/18/lib64/libclang-cpp.so.18git7e5809e7
#25 0x000055e4ece03777 in TransformationManager::doTransformation (this=0x55e4ef180550, ErrorMsg="", ErrorCode=@0x55e4ee7a0ab0: -1)
    at /tmp/cvise/clang_delta/TransformationManager.cpp:360
#26 0x000055e4e972a65a in main (argc=4, argv=0x7ffd951ad528) at /tmp/cvise/clang_delta/ClangDelta.cpp:257

I guess no cvise on Gentoo then, sigh.

How do you mean that?

We support building LLVM with assertions enabled, and this is the version we're using for development purposes to catch broken software. There is really no point in shipping software that is known to be broken and works only when bugs are swept under the carpet.

marxin commented 12 months ago

#25 0x000055e4ece03777 in TransformationManager::doTransformation (this=0x55e4ef180550, ErrorMsg="", ErrorCode=@0x55e4ee7a0ab0: -1) at /tmp/cvise/clang_delta/TransformationManager.cpp:360

Well, there's not much I can do here. clang_delta is provided a source code that is directly passed to Clang and the AST parsing fails. Then, it's reasonable to print an error message ClangBinarySearchPass::replace-function-def-with-decl and continue reducing with another pass. I'm sorry, but I can't do here much.

mgorny commented 12 months ago

It's not "AST parsing fails". Assertions indicate there's something wrong with how you're using the API.

nekopsykose commented 12 months ago

is it not also possible that the assertion is triggered by clang itself, on the weird input code? it's totally possible for an internal assertion to trip even with correct usage (i.e. something that was untested), just an assertion existing doesn't point to who is at fault (it needs deeper analysis and explanation of how it lands at the assertion)

mgorny commented 12 months ago

Hmm, perhaps you're right. I'll file it to clang upstream.

mgorny commented 12 months ago

I'm sorry about the noise.

marxin commented 11 months ago

That's fine..

nickdesaulniers commented 11 months ago

Yeah, looks like the input is failing the parse via this assertion: https://github.com/llvm/llvm-project/blob/c663401f69ecb999eb0c5a2af183b920c6c50a6a/clang/lib/AST/ExprClassification.cpp#L57

(Perhaps one of the passes in clang_delta is leaving behind invalid code?) I doubt this is a cvise issue.