clang-omp / clang_trunk

Other
12 stars 11 forks source link

"distribute parallel for" fails to parse #21

Open metaspace opened 9 years ago

metaspace commented 9 years ago

Hi,

The following program fails to parse and crashes the compiler:

#include <stdlib.h>
#include <time.h>
#include <stdio.h>

void init(float *a, float *b, int n) {
  for(int i=0; i<n; i++) {
    a[i] = (float)drand48();
    b[i] = (float)drand48();
  }
}

void output(float* vec, int n) {
  for(int i=0; i<n; i++) {
    printf("%f\n", vec[i]);
  }
}

void vec_mult(int N)
{
   int i;
   float p[N], v1[N], v2[N];
   init(v1, v2, N);

#pragma omp target map(to: v1[:N], v2[:N]) map(from: p[:N])
#pragma omp teams num_teams(1)
   {
#pragma omp distribute parallel for
     for (i=0; i<N; i++)
       p[i] = v1[i] * v2[i];
   }

   output(p, N);
}

int main(int argc, char **argv) {
  srand48(time(0));
  vec_mult(32);
  return 0;
}

Output from clang:

$ make
clang -g -O0 -fopenmp -target x86_64-linux-gnu -omptargets=nvptx64sm_35-nvidia-cuda parallel_for.c -o parallel_for -save-temps=obj
clang-3.7: /g/g92/hindborg/src/llvm_trunk/tools/clang/include/clang/AST/Type.h:580: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.
#0 0x1f1ac9f llvm::sys::PrintStackTrace(llvm::raw_ostream&) /g/g92/hindborg/src/llvm_trunk/lib/Support/Unix/Signals.inc:437:0
#1 0x1f1b01b PrintStackTraceSignalHandler(void*) /g/g92/hindborg/src/llvm_trunk/lib/Support/Unix/Signals.inc:495:0
#2 0x1f19bf3 SignalHandler(int) /g/g92/hindborg/src/llvm_trunk/lib/Support/Unix/Signals.inc:210:0
#3 0x2aaaab30a710 __restore_rt (/lib64/libpthread.so.0+0xf710)
#4 0x2aaaabcf8625 __GI_raise /usr/src/debug/glibc-2.12-2-gc4ccff1/signal/../nptl/sysdeps/unix/sysv/linux/raise.c:64:0
#5 0x2aaaabcf9e05 __GI_abort /usr/src/debug/glibc-2.12-2-gc4ccff1/stdlib/abort.c:94:0
#6 0x2aaaabcf174e __assert_fail_base /usr/src/debug/glibc-2.12-2-gc4ccff1/assert/assert.c:96:0
#7 0x2aaaabcf1810 __GI___assert_perror_fail /usr/src/debug/glibc-2.12-2-gc4ccff1/assert/assert-perr.c:32:0
#8 0x20bae25 clang::QualType::getCommonPtr() const /g/g92/hindborg/src/llvm_trunk/tools/clang/include/clang/AST/Type.h:582:0
#9 0x20bbe24 clang::QualType::getTypePtr() const /g/g92/hindborg/src/llvm_trunk/tools/clang/include/clang/AST/Type.h:5017:0
#10 0x20baf16 clang::QualType::operator->() const /g/g92/hindborg/src/llvm_trunk/tools/clang/include/clang/AST/Type.h:627:0
#11 0x20c2e25 clang::TypeLoc::getTypeLocClass() const /g/g92/hindborg/src/llvm_trunk/tools/clang/include/clang/AST/TypeLoc.h:92:0
#12 0x40257a2 clang::TypeLoc::initializeImpl(clang::ASTContext&, clang::TypeLoc, clang::SourceLocation) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/AST/TypeLoc.cpp:115:0
#13 0x39cceff clang::TypeLoc::initialize(clang::ASTContext&, clang::SourceLocation) const /g/g92/hindborg/src/llvm_trunk/tools/clang/include/clang/AST/TypeLoc.h:161:0
#14 0x3dc635d clang::ASTContext::getTrivialTypeSourceInfo(clang::QualType, clang::SourceLocation) const /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/AST/ASTContext.cpp:2061:0
#15 0x362c638 captureThis(clang::ASTContext&, clang::RecordDecl*, clang::QualType, clang::SourceLocation) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Sema/SemaExprCXX.cpp:889:0
#16 0x362ca55 clang::Sema::CheckCXXThisCapture(clang::SourceLocation, bool, bool, unsigned int const*) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Sema/SemaExprCXX.cpp:951:0
#17 0x374959e clang::Sema::AddDistributedParallelArgsIntoCapturedStmt(clang::CapturedStmt*, clang::Expr*, clang::Expr*&, clang::Expr*&) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Sema/SemaOpenMP.cpp:3007:0
#18 0x3749dec clang::Sema::ActOnOpenMPDistributeParallelForDirective(clang::OpenMPDirectiveKind, llvm::ArrayRef<clang::OMPClause*>, clang::Stmt*, clang::SourceLocation, clang::SourceLocation) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Sema/SemaOpenMP.cpp:3158:0
#19 0x374636c clang::Sema::ActOnOpenMPExecutableDirective(clang::OpenMPDirectiveKind, clang::DeclarationNameInfo const&, llvm::ArrayRef<clang::OMPClause*>, clang::Stmt*, clang::SourceLocation, clang::SourceLocation, clang::OpenMPDirectiveKind) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Sema/SemaOpenMP.cpp:2396:0
#20 0x31673d1 clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseOpenMP.cpp:841:0
#21 0x31794fc clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:345:0
#22 0x3178924 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:107:0
#23 0x317b852 clang::Parser::ParseCompoundStatementBody(bool) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:955:0
#24 0x317b342 clang::Parser::ParseCompoundStatement(bool, unsigned int) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:841:0
#25 0x317b2c0 clang::Parser::ParseCompoundStatement(bool) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:808:0
#26 0x3178fec clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:226:0
#27 0x3178924 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:107:0
#28 0x3178856 clang::Parser::ParseStatement(clang::SourceLocation*) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:42:0
#29 0x3167286 clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseOpenMP.cpp:827:0
#30 0x31794fc clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:345:0
#31 0x3178924 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:107:0
#32 0x3178856 clang::Parser::ParseStatement(clang::SourceLocation*) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:42:0
#33 0x3167286 clang::Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseOpenMP.cpp:827:0
#34 0x31794fc clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:345:0
#35 0x3178924 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, bool, clang::SourceLocation*) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:107:0
#36 0x317b852 clang::Parser::ParseCompoundStatementBody(bool) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:955:0
#37 0x317ea5a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseStmt.cpp:1870:0
#38 0x30f22e4 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/Parser.cpp:1133:0
#39 0x3102cee clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, clang::SourceLocation*, clang::Parser::ForRangeInit*) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseDecl.cpp:1759:0
#40 0x30f15c4 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/Parser.cpp:923:0
#41 0x30f167c clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/Parser.cpp:938:0
#42 0x30f0de2 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/Parser.cpp:796:0
#43 0x30f0262 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/Parser.cpp:588:0
#44 0x30eca2f clang::ParseAST(clang::Sema&, bool, bool) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Parse/ParseAST.cpp:138:0
#45 0x24b71ba clang::ASTFrontendAction::ExecuteAction() /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Frontend/FrontendAction.cpp:538:0
#46 0x281e709 clang::CodeGenAction::ExecuteAction() /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/CodeGen/CodeGenAction.cpp:745:0
#47 0x24b6c59 clang::FrontendAction::Execute() /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Frontend/FrontendAction.cpp:443:0
#48 0x2478365 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/Frontend/CompilerInstance.cpp:819:0
#49 0x25b5049 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /g/g92/hindborg/src/llvm_trunk/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:222:0
#50 0x1260d39 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /g/g92/hindborg/src/llvm_trunk/tools/clang/tools/driver/cc1_main.cpp:112:0
#51 0x1258301 ExecuteCC1Tool(llvm::ArrayRef<char const*>, llvm::StringRef) /g/g92/hindborg/src/llvm_trunk/tools/clang/tools/driver/driver.cpp:358:0
#52 0x12587e9 main /g/g92/hindborg/src/llvm_trunk/tools/clang/tools/driver/driver.cpp:404:0
#53 0x2aaaabce4d5d __libc_start_main /usr/src/debug/glibc-2.12-2-gc4ccff1/csu/libc-start.c:258:0
#54 0x1256b59 _start (/p/lscratchd/hindborg/llvm-install-795975/bin/clang-3.7+0x1256b59)
Stack dump:
0.      Program arguments: /p/lscratchd/hindborg/llvm-install-795975/bin/clang-3.7 -cc1 -fopenmp -omptargets=nvptx64sm_35-nvidia-cuda -omp-main-file-path parallel_for.c -triple x86_64--linux-gnu -emit-llvm-bc -emit-llvm-uselists -disable-free -main-file-name parallel_for.c -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -g -dwarf-column-info -resource-dir /p/lscratchd/hindborg/llvm-install-795975/bin/../lib/clang/3.7.0 -O0 -fdebug-compilation-dir /g/g92/hindborg/src/omptest -ferror-limit 19 -fmessage-length 181 -fopenmp -mstackrealign -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -disable-llvm-optzns -o parallel_for.bc -x cpp-output parallel_for.i
1.      parallel_for.c:30:4: current parser token '}'
2.      parallel_for.c:19:1: parsing function body 'vec_mult'
3.      parallel_for.c:19:1: in compound statement ('{}')
4.      parallel_for.c:26:2: in compound statement ('{}')
clang-3.7: error: unable to execute command: Aborted (core dumped)
clang-3.7: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 3.7.0 (https://github.com/clang-omp/clang_trunk fa286388c72d17cbfb38073064270c30675d4486) (https://github.com/clang-omp/llvm_trunk.git 0f8da096a0bd5d2f21008cd6583a9b35e7bbd124)
Target: x86_64--linux-gnu
Thread model: posix
clang-3.7: note: diagnostic msg: PLEASE submit a bug report to http://llvm.org/bugs/ and include the crash backtrace, preprocessed source, and associated run script.
clang-3.7: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-3.7: note: diagnostic msg: /var/tmp/hindborg/parallel_for-027ba3.c
clang-3.7: note: diagnostic msg: /var/tmp/hindborg/parallel_for-a69345.c
clang-3.7: note: diagnostic msg: /var/tmp/hindborg/parallel_for-027ba3.sh
clang-3.7: note: diagnostic msg:

********************
make: *** [parallel_for] Error 254

The files parallel_for-027ba3.c, parallel_for-a69345.c and parallel_for-027ba3.sh are too large to be pasted here, and there is no attachment option. I can provide them by email if required.

Best regards, Andreas Hindborg

hahnjo commented 9 years ago

Hi,

I wonder whether this is valid code: I've never seen an array declaration in C with the size being a variable... Replacing it with a compile-time constant or calls to malloc / free works for me.

Greetings, Jonas

sfantao commented 9 years ago

Hi,

I guess this is valid C99 code. Variable-array-size types require special code to be dealt with in several places of the code emission, but in this case this happens in the semantic analyzer. I'll have to investigate to see what's wrong.

Thanks, Samuel