<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Clang crashes when casting an OpenCL block."
   href="https://llvm.org/bugs/show_bug.cgi?id=28602">28602</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Clang crashes when casting an OpenCL block.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>OpenCL
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>george.burgess.iv@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Found on r275848.

This contains two bugs that look like they share the same root cause. If I'm
wrong, I'm happy to file a separate bug. :)


Repro #1:
```
$ echo '
void foo() {
  void *p = ^(void) {
    return;
  };
}
' | $clang -cc1 -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -x
cl -
```

Complaint:
wrong cast for pointers in different address spaces(must be an address space
cast)!
UNREACHABLE executed at ../../tools/clang/lib/CodeGen/CGExprScalar.cpp:1383!
#0 0x000000000285885c llvm::sys::PrintStackTrace(llvm::raw_ostream&)
~/llvm/llvm/build/debug/../../lib/Support/Unix/Signals.inc:402:11
#1 0x0000000002858d49 PrintStackTraceSignalHandler(void*)
~/llvm/llvm/build/debug/../../lib/Support/Unix/Signals.inc:470:1
#2 0x0000000002857423 llvm::sys::RunSignalHandlers()
~/llvm/llvm/build/debug/../../lib/Support/Signals.cpp:45:5
#3 0x0000000002859094 SignalHandler(int)
~/llvm/llvm/build/debug/../../lib/Support/Unix/Signals.inc:256:1
#4 0x00007f6d840c2330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#5 0x00007f6d82cb5c37 gsignal
/build/eglibc-oGUzwX/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#6 0x00007f6d82cb9028 abort
/build/eglibc-oGUzwX/eglibc-2.19/stdlib/abort.c:91:0
#7 0x00000000027e2f10 LLVMInstallFatalErrorHandler
~/llvm/llvm/build/debug/../../lib/Support/ErrorHandling.cpp:133:0
#8 0x0000000002e857f7 (anonymous
namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGExprScalar.cpp:1382:7
#9 0x0000000002e7e718 clang::StmtVisitorBase<clang::make_ptr, (anonymous
namespace)::ScalarExprEmitter,
llvm::Value*>::VisitImplicitCastExpr(clang::ImplicitCastExpr*)
~/llvm/llvm/build/debug/tools/clang/include/clang/AST/StmtNodes.inc:411:1
#10 0x0000000002e79e43 clang::StmtVisitorBase<clang::make_ptr, (anonymous
namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*)
~/llvm/llvm/build/debug/tools/clang/include/clang/AST/StmtNodes.inc:411:1
#11 0x0000000002e73b89 (anonymous
namespace)::ScalarExprEmitter::Visit(clang::Expr*)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGExprScalar.cpp:205:12
#12 0x0000000002e73ad3
clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGExprScalar.cpp:3446:3
#13 0x0000000002e0b3ab
clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const*,
clang::ValueDecl const*, clang::CodeGen::LValue, bool)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGDecl.cpp:664:18
#14 0x0000000002e0e69b
clang::CodeGen::CodeGenFunction::EmitExprAsInit(clang::Expr const*,
clang::ValueDecl const*, clang::CodeGen::LValue, bool)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGDecl.cpp:1301:5
#15 0x0000000002e0d11d
clang::CodeGen::CodeGenFunction::EmitAutoVarInit(clang::CodeGen::CodeGenFunction::AutoVarEmission
const&)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGDecl.cpp:1222:12
#16 0x0000000002e0a495
clang::CodeGen::CodeGenFunction::EmitAutoVarDecl(clang::VarDecl const&)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGDecl.cpp:906:3
#17 0x0000000002e09f8d
clang::CodeGen::CodeGenFunction::EmitVarDecl(clang::VarDecl const&)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGDecl.cpp:161:1
#18 0x0000000002e09de7 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl
const&) ~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGDecl.cpp:121:5
#19 0x0000000002b55396
clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGStmt.cpp:1071:22
#20 0x0000000002b4f0db
clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGStmt.cpp:306:75
#21 0x0000000002b4e71d clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt
const*) ~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGStmt.cpp:53:7
#22 0x0000000002b55ed8
clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt
const&, bool, clang::CodeGen::AggValueSlot)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CGStmt.cpp:341:42
#23 0x0000000002baea7b
clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::CodeGen::FunctionArgList&,
clang::Stmt const*)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CodeGenFunction.cpp:910:5
#24 0x0000000002baf4a9
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CodeGenFunction.cpp:1057:3
#25 0x0000000002bcce28
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CodeGenModule.cpp:2900:3
#26 0x0000000002bc81c8
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CodeGenModule.cpp:1801:12
#27 0x0000000002bcb578
clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CodeGenModule.cpp:1620:5
#28 0x0000000002bced61
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CodeGenModule.cpp:3761:38
#29 0x00000000035ded32 (anonymous
namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/ModuleBuilder.cpp:147:73
#30 0x00000000035dbb55
clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef)
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CodeGenAction.cpp:119:7
#31 0x0000000004260c80 clang::ParseAST(clang::Sema&, bool, bool)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseAST.cpp:158:11
#32 0x00000000030f5650 clang::ASTFrontendAction::ExecuteAction()
~/llvm/llvm/build/debug/../../tools/clang/lib/Frontend/FrontendAction.cpp:558:1
#33 0x00000000035da9a5 clang::CodeGenAction::ExecuteAction()
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CodeGenAction.cpp:854:1
#34 0x00000000030f5130 clang::FrontendAction::Execute()
~/llvm/llvm/build/debug/../../tools/clang/lib/Frontend/FrontendAction.cpp:461:7
#35 0x000000000309a091
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
~/llvm/llvm/build/debug/../../tools/clang/lib/Frontend/CompilerInstance.cpp:868:7
#36 0x0000000003247211
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
~/llvm/llvm/build/debug/../../tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:241:8
#37 0x0000000000c35228 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*)
~/llvm/llvm/build/debug/../../tools/clang/tools/driver/cc1_main.cpp:116:11
#38 0x0000000000c2927d ExecuteCC1Tool(llvm::ArrayRef<char const*>,
llvm::StringRef)
~/llvm/llvm/build/debug/../../tools/clang/tools/driver/driver.cpp:301:5
#39 0x0000000000c28132 main
~/llvm/llvm/build/debug/../../tools/clang/tools/driver/driver.cpp:382:5
#40 0x00007f6d82ca0f45 __libc_start_main
/build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:321:0
#41 0x0000000000c27594 _start (~/llvm/llvm/build/debug/bin/clang+0xc27594)
Stack dump:
0.      Program arguments: ~/llvm/llvm/build/debug/bin/clang -cc1 -cl-std=CL2.0
-ffake-address-space-map -emit-llvm -o - -x cl -
1.      <eof> parser at end of file
2.      <stdin>:2:6: LLVM IR generation of declaration 'foo'
3.      <stdin>:2:6: Generating code for declaration 'foo'




----------

Repro #2:
```
$ echo '
void foo() {
  (void *) ^(void) {
    return;
  };
}
' | $clang -cc1 -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o - -x
cl -
```

(N.B. The same assertion fails given `void *p = (void *) ^(void) { ...`)

Complaint:
clang: ../../tools/clang/lib/AST/Expr.cpp:1540: bool
clang::CastExpr::CastConsistency() const: Assertion
`getSubExpr()->getType()->isPointerType()' failed.
#0 0x000000000285885c llvm::sys::PrintStackTrace(llvm::raw_ostream&)
~/llvm/llvm/build/debug/../../lib/Support/Unix/Signals.inc:402:11
#1 0x0000000002858d49 PrintStackTraceSignalHandler(void*)
~/llvm/llvm/build/debug/../../lib/Support/Unix/Signals.inc:470:1
#2 0x0000000002857423 llvm::sys::RunSignalHandlers()
~/llvm/llvm/build/debug/../../lib/Support/Signals.cpp:45:5
#3 0x0000000002859094 SignalHandler(int)
~/llvm/llvm/build/debug/../../lib/Support/Unix/Signals.inc:256:1
#4 0x00007f4564ac2330 __restore_rt
(/lib/x86_64-linux-gnu/libpthread.so.0+0x10330)
#5 0x00007f45636b5c37 gsignal
/build/eglibc-oGUzwX/eglibc-2.19/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:56:0
#6 0x00007f45636b9028 abort
/build/eglibc-oGUzwX/eglibc-2.19/stdlib/abort.c:91:0
#7 0x00007f45636aebf6 __assert_fail_base
/build/eglibc-oGUzwX/eglibc-2.19/assert/assert.c:92:0
#8 0x00007f45636aeca2 (/lib/x86_64-linux-gnu/libc.so.6+0x2fca2)
#9 0x000000000566a396 clang::CastExpr::CastConsistency() const
~/llvm/llvm/build/debug/../../tools/clang/lib/AST/Expr.cpp:1541:5
#10 0x0000000002db5bf3 clang::CastExpr::CastExpr(clang::Stmt::StmtClass,
clang::QualType, clang::ExprValueKind, clang::CastKind, clang::Expr*, unsigned
int) ~/llvm/llvm/build/debug/../../tools/clang/include/clang/AST/Expr.h:2670:5
#11 0x0000000004a9748b
clang::ExplicitCastExpr::ExplicitCastExpr(clang::Stmt::StmtClass,
clang::QualType, clang::ExprValueKind, clang::CastKind, clang::Expr*, unsigned
int, clang::TypeSourceInfo*)
~/llvm/llvm/build/debug/../../tools/clang/include/clang/AST/Expr.h:2809:59 #12
0x000000000567dc72 clang::CStyleCastExpr::CStyleCastExpr(clang::QualType,
clang::ExprValueKind, clang::CastKind, clang::Expr*, unsigned int,
clang::TypeSourceInfo*, clang::SourceLocation, clang::SourceLocation)
~/llvm/llvm/build/debug/../../tools/clang/include/clang/AST/Expr.h:2844:36     
                                                                               
                                                                               
                                                                               
         #13 0x000000000566af0d clang::CStyleCastExpr::Create(clang::ASTContext
const&, clang::QualType, clang::ExprValueKind, clang::CastKind, clang::Expr*,
llvm::SmallVector<clang::CXXBaseSpecifier*, 4u> const*, clang::TypeSourceInfo*,
clang::SourceLocation, clang::SourceLocation)
~/llvm/llvm/build/debug/../../tools/clang/lib/AST/Expr.cpp:1681:5              
                                                                               
                                                                               
                             #14 0x0000000004648469
clang::Sema::BuildCStyleCastExpr(clang::SourceLocation, clang::TypeSourceInfo*,
clang::SourceLocation, clang::Expr*)
~/llvm/llvm/build/debug/../../tools/clang/lib/Sema/SemaCast.cpp:2611:22
#15 0x00000000048cda88 clang::Sema::ActOnCastExpr(clang::Scope*,
clang::SourceLocation, clang::Declarator&, clang::OpaquePtr<clang::QualType>&,
clang::SourceLocation, clang::Expr*)
~/llvm/llvm/build/debug/../../tools/clang/lib/Sema/SemaExpr.cpp:6005:10
#16 0x00000000042d0cec
clang::Parser::ParseParenExpression(clang::Parser::ParenParseOption&, bool,
bool, clang::OpaquePtr<clang::QualType>&, clang::SourceLocation&)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseExpr.cpp:2378:20
#17 0x00000000042cbd2c clang::Parser::ParseCastExpression(bool, bool, bool&,
clang::Parser::TypeCastState)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseExpr.cpp:722:11
#18 0x00000000042c99a3 clang::Parser::ParseCastExpression(bool, bool,
clang::Parser::TypeCastState)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseExpr.cpp:478:20
#19 0x00000000042c8490
clang::Parser::ParseAssignmentExpression(clang::Parser::TypeCastState)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseExpr.cpp:169:20
#20 0x000000000429c230 clang::Parser::ParseInitializer()
~/llvm/llvm/build/debug/../../tools/clang/include/clang/Parse/Parser.h:1620:14
#21 0x000000000428d882
clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseDecl.cpp:2056:23
#22 0x000000000428bcdc clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&,
unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseDecl.cpp:1844:21
#23 0x0000000004286b9d clang::Parser::ParseSimpleDeclaration(unsigned int,
clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&, bool,
clang::Parser::ForRangeInit*)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseDecl.cpp:1576:10
#24 0x000000000428686b clang::Parser::ParseDeclaration(unsigned int,
clang::SourceLocation&, clang::Parser::ParsedAttributesWithRange&)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseDecl.cpp:1516:12
#25 0x000000000431e3f1
clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::AllowedContsructsKind, clang::SourceLocation*,
clang::Parser::ParsedAttributesWithRange&)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseStmt.cpp:215:29
#26 0x000000000431dbf0
clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*,
32u>&, clang::Parser::AllowedContsructsKind, clang::SourceLocation*)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseStmt.cpp:113:20
#27 0x0000000004324e34 clang::Parser::ParseCompoundStatementBody(bool)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseStmt.cpp:987:11
#28 0x0000000004325984 clang::Parser::ParseFunctionStatementBody(clang::Decl*,
clang::Parser::ParseScope&)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseStmt.cpp:1951:21
#29 0x0000000004267ea3
clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&,
clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/Parser.cpp:1173:3
#30 0x000000000428b8f8 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&,
unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseDecl.cpp:1791:11
#31 0x0000000004266f2f
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec&, clang::AccessSpecifier)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/Parser.cpp:940:10
#32 0x00000000042666b0
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*, clang::AccessSpecifier)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/Parser.cpp:956:12
#33 0x0000000004265f77
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/Parser.cpp:808:12
#34 0x000000000426500b
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/Parser.cpp:595:12
#35 0x0000000004260bd3 clang::ParseAST(clang::Sema&, bool, bool)
~/llvm/llvm/build/debug/../../tools/clang/lib/Parse/ParseAST.cpp:150:7
#36 0x00000000030f5650 clang::ASTFrontendAction::ExecuteAction()
~/llvm/llvm/build/debug/../../tools/clang/lib/Frontend/FrontendAction.cpp:558:1
#37 0x00000000035da9a5 clang::CodeGenAction::ExecuteAction()
~/llvm/llvm/build/debug/../../tools/clang/lib/CodeGen/CodeGenAction.cpp:854:1
#38 0x00000000030f5130 clang::FrontendAction::Execute()
~/llvm/llvm/build/debug/../../tools/clang/lib/Frontend/FrontendAction.cpp:461:7
#39 0x000000000309a091
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
~/llvm/llvm/build/debug/../../tools/clang/lib/Frontend/CompilerInstance.cpp:868:7
#40 0x0000000003247211
clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
~/llvm/llvm/build/debug/../../tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:241:8
#41 0x0000000000c35228 cc1_main(llvm::ArrayRef<char const*>, char const*,
void*)
~/llvm/llvm/build/debug/../../tools/clang/tools/driver/cc1_main.cpp:116:11
#42 0x0000000000c2927d ExecuteCC1Tool(llvm::ArrayRef<char const*>,
llvm::StringRef)
~/llvm/llvm/build/debug/../../tools/clang/tools/driver/driver.cpp:301:5
#43 0x0000000000c28132 main
~/llvm/llvm/build/debug/../../tools/clang/tools/driver/driver.cpp:382:5
#44 0x00007f45636a0f45 __libc_start_main
/build/eglibc-oGUzwX/eglibc-2.19/csu/libc-start.c:321:0
#45 0x0000000000c27594 _start (~/llvm/llvm/build/debug/bin/clang+0xc27594)
Stack dump:
0.      Program arguments: ~/llvm/llvm/build/debug/bin/clang -cc1 -cl-std=CL2.0
-ffake-address-space-map -emit-llvm -o - -x cl -
1.      <stdin>:5:4: current parser token ';'
2.      <stdin>:2:13: parsing function body 'foo'
3.      <stdin>:2:13: in compound statement ('{}')</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>