[LLVMbugs] [Bug 13068] New: Returning const reference to element of vector type causes crash

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Jun 9 20:33:44 PDT 2012


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

             Bug #: 13068
           Summary: Returning const reference to element of vector type
                    causes crash
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: fadis at quaternion.sakura.ne.jp
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Feeding following code causes clang++ crash.

$ cat foo.cpp
typedef float float2 __attribute__( ( ext_vector_type( 2 ) ) );

const float &get( const float2 &vec, unsigned int index ) {
  return vec[ index ];
}

int main() {
  float2 a;
  get( a, 1 );
}

$ clang++ foo.cpp 
clang: /home/users/fadis/llvm/tools/clang/lib/Sema/SemaChecking.cpp:3134:
clang::Expr* EvalAddr(clang::Expr*,
llvm::SmallVectorImpl<clang::DeclRefExpr*>&, clang::Decl*): Assertion
`(E->getType()->isAnyPointerType() || E->getType()->isBlockPointerType() ||
E->getType()->isObjCQualifiedIdType()) && "EvalAddr only works on pointers"'
failed.
0  libLLVM-3.2svn.so 0x00007f5043507c8f
1  libLLVM-3.2svn.so 0x00007f50435087da
2  libpthread.so.0   0x00007f5042653310
3  libc.so.6         0x00007f5041945b05 gsignal + 53
4  libc.so.6         0x00007f5041946f86 abort + 390
5  libc.so.6         0x00007f504193e735 __assert_fail + 245
6  clang             0x00000000008e5f7a
7  clang             0x00000000008e65dc
8  clang             0x00000000008e6517
9  clang             0x00000000008e69ff
clang::Sema::CheckReturnStackAddr(clang::Expr*, clang::QualType,
clang::SourceLocation) + 927
10 clang             0x0000000000ae5cb5
clang::Sema::ActOnReturnStmt(clang::SourceLocation, clang::Expr*) + 805
11 clang             0x000000000087d423 clang::Parser::ParseReturnStatement() +
115
12 clang             0x00000000008849d8
clang::Parser::ParseStatementOrDeclarationAfterAttributes(clang::ASTOwningVector<clang::Stmt*,
32u>&, bool, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&)
+ 3128
13 clang             0x0000000000884efe
clang::Parser::ParseStatementOrDeclaration(clang::ASTOwningVector<clang::Stmt*,
32u>&, bool, clang::SourceLocation*) + 142
14 clang             0x000000000088116c
clang::Parser::ParseCompoundStatementBody(bool) + 1836
15 clang             0x0000000000881aea
clang::Parser::ParseFunctionStatementBody(clang::Decl*,
clang::Parser::ParseScope&) + 154
16 clang             0x0000000000821e95
clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&,
clang::Parser::ParsedTemplateInfo const&,
llvm::SmallVector<clang::Parser::LateParsedAttribute*, 2u>*) + 1701
17 clang             0x0000000000836a27
clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, unsigned int, bool,
clang::SourceLocation*, clang::Parser::ForRangeInit*) + 3431
18 clang             0x000000000081c949
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsingDeclSpec&,
clang::AccessSpecifier) + 153
19 clang             0x000000000081d0fe
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&,
clang::AccessSpecifier) + 942
20 clang             0x0000000000820669
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) + 3065
21 clang             0x0000000000820bf4
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 180
22 clang             0x0000000000815885 clang::ParseAST(clang::Sema&, bool,
bool) + 229
23 clang             0x00000000006a0cd4 clang::CodeGenAction::ExecuteAction() +
68
24 clang             0x00000000005535b4
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 340
25 clang             0x0000000000537f84
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1316
26 clang             0x000000000052d4d9 cc1_main(char const**, char const**,
char const*, void*) + 6921
27 clang             0x0000000000536d93 main + 7923
28 libc.so.6         0x00007f504193209d __libc_start_main + 253
29 clang             0x000000000052ae29
Stack dump:
0.    Program arguments: /opt/llvm/bin/clang -cc1 -triple
x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -main-file-name
foo.cpp -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose
-mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-linker-version
2.21.1 -momit-leaf-frame-pointer -resource-dir /opt/llvm/bin/../lib/clang/3.2
-fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem
/usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4 -internal-isystem
/usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4/x86_64-pc-linux-gnu
-internal-isystem
/usr/lib64/gcc/x86_64-pc-linux-gnu/4.5.3/include/g++-v4/backward
-internal-isystem /usr/local/include -internal-isystem
/opt/llvm/bin/../lib/clang/3.2/include -internal-externc-isystem /include
-internal-externc-isystem /usr/include -fdeprecated-macro
-fdebug-compilation-dir /root -ferror-limit 19 -fmessage-length 120
-mstackrealign -fgnu-runtime -fobjc-runtime-has-arc -fobjc-runtime-has-weak
-fobjc-fragile-abi -fcxx-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -o /tmp/foo-nG4Lkw.o -x c++ foo.cpp 
1.    foo.cpp:4:22: current parser token ';'
2.    foo.cpp:3:59: parsing function body 'get'
3.    foo.cpp:3:59: in compound statement ('{}')
clang: error: unable to execute command: Aborted
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang: note: diagnostic msg: Please submit a bug report to
http://llvm.org/bugs/ and include command line arguments and all diagnostic
information.
clang: note: diagnostic msg: Preprocessed source(s) and associated run
script(s) are located at:
clang: note: diagnostic msg: /tmp/foo-WAIg0I.ii
clang: note: diagnostic msg: /tmp/foo-WAIg0I.sh
$ clang++ -v
clang version 3.2 (http://llvm.org/git/clang.git
70fdbc366da85880aae5baebd3351e993ca05603) (http://llvm.org/git/llvm.git
b7454fd9df0b477e3daf2fce6e1d5e1b241562df)
Target: x86_64-unknown-linux-gnu
Thread model: posix

However this problem reproduced on MacOSX too

$ clang++ hoge.cpp
Assertion failed: ((E->getType()->isAnyPointerType() ||
E->getType()->isBlockPointerType() || E->getType()->isObjCQualifiedIdType()) &&
"EvalAddr only works on pointers"), function EvalAddr, file
/Users/matsubayashinaomasa/git/llvm/tools/clang/lib/Sema/SemaChecking.cpp, line
2979.
0  libLLVM-3.1svn.dylib 0x00000001018f7fe2 PrintStackTrace(void*) + 34
1  libLLVM-3.1svn.dylib 0x00000001018f85f9 SignalHandler(int) + 713
2  libSystem.B.dylib    0x00007fff82b601ba _sigtramp + 26
3  libSystem.B.dylib    0x6d65532f616d6553 _sigtramp + 3736560563
4  libLLVM-3.1svn.dylib 0x0000000100df9016 abort + 22
5  libLLVM-3.1svn.dylib 0x0000000100df9068 __assert_rtn + 56
6  clang                0x0000000100311890 std::vector<std::pair<unsigned int,
clang::SourceLocation>, std::allocator<std::pair<unsigned int,
clang::SourceLocation> >
>::_M_insert_aux(__gnu_cxx::__normal_iterator<std::pair<unsigned int,
clang::SourceLocation>*, std::vector<std::pair<unsigned int,
clang::SourceLocation>, std::allocator<std::pair<unsigned int,
clang::SourceLocation> > > >, std::pair<unsigned int, clang::SourceLocation>
const&) + 84000
7  clang                0x00000001003112ed std::vector<std::pair<unsigned int,
clang::SourceLocation>, std::allocator<std::pair<unsigned int,
clang::SourceLocation> >
>::_M_insert_aux(__gnu_cxx::__normal_iterator<std::pair<unsigned int,
clang::SourceLocation>*, std::vector<std::pair<unsigned int,
clang::SourceLocation>, std::allocator<std::pair<unsigned int,
clang::SourceLocation> > > >, std::pair<unsigned int, clang::SourceLocation>
const&) + 82557
8  clang                0x0000000100311a69 std::vector<std::pair<unsigned int,
clang::SourceLocation>, std::allocator<std::pair<unsigned int,
clang::SourceLocation> >
>::_M_insert_aux(__gnu_cxx::__normal_iterator<std::pair<unsigned int,
clang::SourceLocation>*, std::vector<std::pair<unsigned int,
clang::SourceLocation>, std::allocator<std::pair<unsigned int,
clang::SourceLocation> > > >, std::pair<unsigned int, clang::SourceLocation>
const&) + 84473
9  clang                0x00000001004f5ec8
llvm::SmallVectorTemplateBase<clang::BuiltinCandidateTypeSet,
false>::grow(unsigned long) + 46832
10 clang                0x00000001002bdccf
llvm::SmallVectorTemplateBase<clang::LambdaCapture, false>::grow(unsigned long)
+ 76753
11 clang                0x00000001002bc3f6
llvm::SmallVectorTemplateBase<clang::LambdaCapture, false>::grow(unsigned long)
+ 70392
12 clang                0x00000001002c17e2
llvm::SmallVectorTemplateBase<clang::LambdaCapture, false>::grow(unsigned long)
+ 91876
13 clang                0x00000001002c1f5b
llvm::SmallVectorTemplateBase<clang::LambdaCapture, false>::grow(unsigned long)
+ 93789
14 clang                0x00000001002d155d
llvm::SmallVectorTemplateBase<clang::ParsedTemplateArgument,
false>::grow(unsigned long) + 39721
15 clang                0x0000000100283c49
llvm::cast_retty<clang::CXXRecordDecl, clang::RecordDecl*>::ret_type
llvm::dyn_cast<clang::CXXRecordDecl, clang::RecordDecl*>(clang::RecordDecl*
const&) + 54009
16 clang                0x00000001002cd938
llvm::SmallVectorTemplateBase<clang::ParsedTemplateArgument,
false>::grow(unsigned long) + 24324
17 clang                0x00000001002cde32
llvm::SmallVectorTemplateBase<clang::ParsedTemplateArgument,
false>::grow(unsigned long) + 25598
18 clang                0x00000001002cee0c
llvm::SmallVectorTemplateBase<clang::ParsedTemplateArgument,
false>::grow(unsigned long) + 29656
19 clang                0x00000001002cf34e
llvm::SmallVectorTemplateBase<clang::ParsedTemplateArgument,
false>::grow(unsigned long) + 31002
20 clang                0x0000000100276e15
llvm::cast_retty<clang::CXXRecordDecl, clang::RecordDecl*>::ret_type
llvm::dyn_cast<clang::CXXRecordDecl, clang::RecordDecl*>(clang::RecordDecl*
const&) + 1221
21 clang                0x000000010023f543 std::vector<clang::CXXRecordDecl
const*, std::allocator<clang::CXXRecordDecl const*>
>::_M_insert_aux(__gnu_cxx::__normal_iterator<clang::CXXRecordDecl const**,
std::vector<clang::CXXRecordDecl const*, std::allocator<clang::CXXRecordDecl
const*> > >, clang::CXXRecordDecl const* const&) + 6113
22 clang                0x00000001000200b8
std::vector<clang::CompilerInstance*, std::allocator<clang::CompilerInstance*>
>::_M_insert_aux(__gnu_cxx::__normal_iterator<clang::CompilerInstance**,
std::vector<clang::CompilerInstance*, std::allocator<clang::CompilerInstance*>
> >, clang::CompilerInstance* const&) + 8454
23 clang                0x0000000100008771 std::_Rb_tree<std::string,
std::string, std::_Identity<std::string>, std::less<std::string>,
std::allocator<std::string> >::_M_insert_unique(std::string const&) + 2809
24 clang                0x0000000100001cb1
25 clang                0x00000001000056fd
std::vector<llvm::SourceMgr::SrcBuffer,
std::allocator<llvm::SourceMgr::SrcBuffer>
>::_M_insert_aux(__gnu_cxx::__normal_iterator<llvm::SourceMgr::SrcBuffer*,
std::vector<llvm::SourceMgr::SrcBuffer,
std::allocator<llvm::SourceMgr::SrcBuffer> > >, llvm::SourceMgr::SrcBuffer
const&) + 2551
26 clang                0x0000000100001058
Stack dump:
0.    Program arguments: /Users/matsubayashinaomasa/opt/llvm/bin/clang -cc1
-triple x86_64-apple-macosx10.6.0 -emit-obj -mrelax-all -disable-free
-main-file-name hoge.cpp -pic-level 1 -mdisable-fp-elim -masm-verbose
-munwind-tables -target-cpu core2 -resource-dir
/Users/matsubayashinaomasa/opt/llvm/bin/../lib/clang/3.1 -fmodule-cache-path
/var/folders/kf/kfkhrrSdG00RZvCv2pGjr++++TI/-Tmp-/clang-module-cache
-fdeprecated-macro -fdebug-compilation-dir /Users/matsubayashinaomasa
-ferror-limit 19 -fmessage-length 120 -stack-protector 1 -mstackrealign
-fblocks -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties
-fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o
/var/folders/kf/kfkhrrSdG00RZvCv2pGjr++++TI/-Tmp-/hoge-jrBNQG.o -x c++ hoge.cpp 
1.    hoge.cpp:4:22: current parser token ';'
2.    hoge.cpp:3:59: parsing function body 'get'
3.    hoge.cpp:3:59: in compound statement ('{}')
clang: error: unable to execute command: Illegal instruction
clang: error: clang frontend command failed due to signal (use -v to see
invocation)
clang: note: diagnostic msg: Please submit a bug report to
http://llvm.org/bugs/ and include command line arguments and all diagnostic
information.
clang: note: diagnostic msg: Preprocessed source(s) and associated run
script(s) are located at:
clang: note: diagnostic msg:
/var/folders/kf/kfkhrrSdG00RZvCv2pGjr++++TI/-Tmp-/hoge-LKIHgH.ii
clang: note: diagnostic msg:
/var/folders/kf/kfkhrrSdG00RZvCv2pGjr++++TI/-Tmp-/hoge-LKIHgH.sh
$ clang++ -v
clang version 3.1 (http://llvm.org/git/clang.git
6f42669b7c0b81b07a15a0483aa5e897ce57cb45) (http://llvm.org/git/llvm.git
6c0b3ac8ea51d35bbd2565f17f1a73c3bfcb5cdf)
Target: x86_64-apple-darwin10.8.0
Thread model: posix

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list