[LLVMbugs] [Bug 20773] New: Assertion failure during code gen for Block expression in a default argument that captures a parameter

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Aug 27 10:14:29 PDT 2014


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

            Bug ID: 20773
           Summary: Assertion failure during code gen for Block expression
                    in a default argument that captures a parameter
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: thonermann at coverity.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The following test case illustrates an assertion failure that occurs in Clang
code gen when a Block expression is used in a default argument and captures a
parameter.  This was first noticed in Clang 3.4 and reproduces in Clang trunk
(demonstrated below).  No attempt was made to look at Clang releases earlier
than 3.4.

$ cat t.cpp
void f(int i, void(^block)() = ^{ i; }) {
}

int main() {
    f(1);
}

$ clang++ --version
clang version 3.6.0 (trunk 216552) (llvm/trunk 216551)
Target: x86_64-unknown-linux-gnu
Thread model: posix

clang++ -c -fblocks t.cpp
t.cpp:1:35: warning: expression result unused [-Wunused-value]
void f(int i, void(^block)() = ^{ i; }) {
                                  ^
clang: /nfs/thonermann/src/llvm-trunk/tools/clang/lib/Sema/SemaExpr.cpp:4028:
ExprResult clang::Sema::BuildCXXDefaultArgExpr(clang::SourceLocation,
clang::FunctionDecl *, clang::ParmVarDecl *): Assertion
`!cast<ExprWithCleanups>(Param->getInit())->getNumObjects() && "default
argument expression has capturing blocks?"' failed.
0  clang           0x00000000043e004e llvm::sys::PrintStackTrace(_IO_FILE*) +
46
1  clang           0x00000000043e032b
2  clang           0x00000000043e1109
3  libpthread.so.0 0x00007f10a8fe2cb0
4  libc.so.6       0x00007f10a7e45425 gsignal + 53
5  libc.so.6       0x00007f10a7e48b8b abort + 379
6  libc.so.6       0x00007f10a7e3e0ee
7  libc.so.6       0x00007f10a7e3e192
8  clang           0x00000000012e5a8f
clang::Sema::BuildCXXDefaultArgExpr(clang::SourceLocation,
clang::FunctionDecl*, clang::ParmVarDecl*) + 1503
9  clang           0x00000000012e76b6
clang::Sema::GatherArgumentsForCall(clang::SourceLocation,
clang::FunctionDecl*, clang::FunctionProtoType const*, unsigned int,
llvm::ArrayRef<clang::Expr*>, llvm::SmallVectorImpl<clang::Expr*>&,
clang::Sema::VariadicCallType, bool, bool) + 1126
10 clang           0x00000000012e6c15
clang::Sema::ConvertArgumentsForCall(clang::CallExpr*, clang::Expr*,
clang::FunctionDecl*, clang::FunctionProtoType const*,
llvm::ArrayRef<clang::Expr*>, clang::SourceLocation, bool) + 3317
11 clang           0x00000000012e8f1d
clang::Sema::BuildResolvedCallExpr(clang::Expr*, clang::NamedDecl*,
clang::SourceLocation, llvm::ArrayRef<clang::Expr*>, clang::SourceLocation,
clang::Expr*, bool) + 2797
12 clang           0x00000000014ae0f3
13 clang           0x00000000014ade06
clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*,
clang::UnresolvedLookupExpr*, clang::SourceLocation,
llvm::MutableArrayRef<clang::Expr*>, clang::SourceLocation, clang::Expr*, bool)
+ 598
14 clang           0x00000000012d5848 clang::Sema::ActOnCallExpr(clang::Scope*,
clang::Expr*, clang::SourceLocation, llvm::MutableArrayRef<clang::Expr*>,
clang::SourceLocation, clang::Expr*, bool) + 2360
15 clang           0x000000000100a890
clang::Parser::ParsePostfixExpressionSuffix(clang::ActionResult<clang::Expr*,
true>) + 3440
16 clang           0x000000000100db5d clang::Parser::ParseCastExpression(bool,
bool, bool&, clang::Parser::TypeCastState) + 9773
17 clang           0x0000000001009a23 clang::Parser::ParseCastExpression(bool,
bool, clang::Parser::TypeCastState) + 83
18 clang           0x0000000001008918
clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState) + 200
19 clang           0x000000000100881f
clang::Parser::ParseExpression(clang::Parser::TypeCastState) + 31
20 clang           0x000000000104952c clang::Parser::ParseExprStatement() + 60
21 clang           0x00000000010485b7
clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*,
32u>&, bool, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&)
+ 1671
22 clang           0x0000000001047e15
clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*,
32u>&, bool, clang::SourceLocation*) + 133
23 clang           0x000000000104ecf3
clang::Parser::ParseCompoundStatementBody(bool) + 1251
24 clang           0x000000000104fb4f
clang::Parser::ParseFunctionStatementBody(clang::Decl*,
clang::Parser::ParseScope&) + 319
25 clang           0x0000000000fc42c2
clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) +
3538
26 clang           0x0000000000fda503
clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, bool,
clang::SourceLocation*, clang::Parser::ForRangeInit*) + 467
27 clang           0x0000000000fc31ac
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier) + 1228
28 clang           0x0000000000fc2853
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier) + 147
29 clang           0x0000000000fc1d8a
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) + 3578
30 clang           0x0000000000fc0d3f
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 703
31 clang           0x0000000000fba0fd clang::ParseAST(clang::Sema&, bool, bool)
+ 925
32 clang           0x0000000000897d5a clang::ASTFrontendAction::ExecuteAction()
+ 522
33 clang           0x0000000000c5d52b clang::CodeGenAction::ExecuteAction() +
3803
34 clang           0x0000000000896ff8 clang::FrontendAction::Execute() + 120
35 clang           0x000000000083872b
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 891
36 clang           0x00000000007e1938
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 3032
37 clang           0x00000000007c238a cc1_main(llvm::ArrayRef<char const*>,
char const*, void*) + 2330
38 clang           0x00000000007d7d0b
39 clang           0x00000000007d6c83 main + 1139
40 libc.so.6       0x00007f10a7e3076d __libc_start_main + 237
41 clang           0x00000000007c10a5
Stack dump:
0.      Program arguments:
/nfs/thonermann/products/linux-x86/clang-trunk/bin/clang -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name
t.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version
2.22 -dwarf-column-info -coverage-file
/data00/home/thonermann/prevent-blocks/tmp/bug8/t.o -resource-dir
/nfs/thonermann/products/linux-x86/clang-trunk/bin/../lib/clang/3.6.0
-internal-isystem /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/x86_64-linux-gnu
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/backward
-internal-isystem /usr/local/include -internal-isystem
/nfs/thonermann/products/linux-x86/clang-trunk/bin/../lib/clang/3.6.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include
-fdeprecated-macro -fdebug-compilation-dir
/data00/home/thonermann/prevent-blocks/tmp/bug8 -ferror-limit 19
-fmessage-length 197 -mstackrealign -fblocks -fobjc-runtime=gcc
-fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o
t.o -x c++ t.cpp 
1.      t.cpp:5:8: current parser token ')'
2.      t.cpp:4:12: parsing function body 'main'
3.      t.cpp:4:12: in compound statement ('{}')
clang: error: unable to execute command: Aborted (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang version 3.6.0 (trunk 216552) (llvm/trunk 216551)
Target: x86_64-unknown-linux-gnu
Thread model: posix

-- 
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/20140827/ecae1827/attachment.html>


More information about the llvm-bugs mailing list