[LLVMbugs] [Bug 12960] New: Use of name `begin' with an invalid range-based for causes segfault

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun May 27 03:57:51 PDT 2012


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

             Bug #: 12960
           Summary: Use of name `begin' with an invalid range-based for
                    causes segfault
           Product: clang
           Version: trunk
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: tim.dawborn at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Created attachment 8652
  --> http://llvm.org/bugs/attachment.cgi?id=8652
error case

When (incorrectly) providing a pointer on the rhs of a range-based for loop,
clang correctly produces a compile error. However, if the scope has the name
`begin' defined, clang segfaults.


Correct case:

20:56:13 tim at tim-macbook tmp$ cat test.cc
class A {
public:
  int *begin(void) const { return nullptr; }
  int *end(void) const { return nullptr; }
};

class X {
private:
  A *const _a;
public:
  X(A *const a) : _a(a) { }
  void foo(void) {
    for (auto &it : _a) { }
  }
};
20:56:15 tim at tim-macbook tmp$
/Users/tim/repos/llvm/build/Debug+Asserts/bin/clang++ -std=c++11 -c -o test.o
test.cc
test.cc:13:19: error: use of undeclared identifier 'begin'
    for (auto &it : _a) { }
                  ^
test.cc:13:19: note: range has type 'A *const'
1 error generated.


Invalid case (adding a private member variable `int begin'):

20:56:56 tim at tim-macbook tmp$ cat test.cc
class A {
public:
  int *begin(void) const { return nullptr; }
  int *end(void) const { return nullptr; }
};

class X {
private:
  A *const _a;
  int begin;
public:
  X(A *const a) : _a(a) { }
  void foo(void) {
    for (auto &it : _a) { }
  }
};
20:56:58 tim at tim-macbook tmp$
/Users/tim/repos/llvm/build/Debug+Asserts/bin/clang++ -std=c++11 -c -o test.o
test.cc
0  clang             0x000000010e8b74ee _ZL15PrintStackTracePv + 46
1  clang             0x000000010e8b7a99 _ZL13SignalHandleri + 297
2  libsystem_c.dylib 0x00007fff8c922cfa _sigtramp + 26
3  libsystem_c.dylib 000000000000000000 _sigtramp + 18446603338157773600
4  clang             0x000000010cb9de2e
clang::Sema::DiagnoseEmptyLookup(clang::Scope*, clang::CXXScopeSpec&,
clang::LookupResult&, clang::CorrectionCandidateCallback&,
clang::TemplateArgumentListInfo*, llvm::ArrayRef<clang::Expr*>) + 670
5  clang             0x000000010ccded04
_ZN5clangL21BuildRecoveryCallExprERNS_4SemaEPNS_5ScopeEPNS_4ExprEPNS_20UnresolvedLookupExprENS_14SourceLocationEN4llvm15MutableArrayRefIS5_EES8_bb
+ 724
6  clang             0x000000010ccde1bc
clang::Sema::BuildOverloadedCallExpr(clang::Scope*, clang::Expr*,
clang::UnresolvedLookupExpr*, clang::SourceLocation, clang::Expr**, unsigned
int, clang::SourceLocation, clang::Expr*, bool) + 1580
7  clang             0x000000010cd0d323
_ZN12_GLOBAL__N_1L25BuildForRangeBeginEndCallERN5clang4SemaEPNS0_5ScopeENS0_14SourceLocationEPNS0_7VarDeclENS_16BeginEndFunctionERKNS0_19DeclarationNameInfoERNS0_12LookupResultEPNS0_4ExprE
+ 1043
8  clang             0x000000010cd0c2a8
clang::Sema::BuildCXXForRangeStmt(clang::SourceLocation, clang::SourceLocation,
clang::Stmt*, clang::Stmt*, clang::Expr*, clang::Expr*, clang::Stmt*,
clang::SourceLocation) + 2616
9  clang             0x000000010cd0b54d
clang::Sema::ActOnCXXForRangeStmt(clang::SourceLocation, clang::SourceLocation,
clang::Stmt*, clang::SourceLocation, clang::Expr*, clang::SourceLocation) + 861
10 clang             0x000000010c9aa6c2
clang::Parser::ParseForStatement(clang::SourceLocation*) + 4194
11 clang             0x000000010c9a68e1
clang::Parser::ParseStatementOrDeclarationAfterAttributes(clang::ASTOwningVector<clang::Stmt*,
32u>&, bool, clang::SourceLocation*, clang::Parser::ParsedAttributesWithRange&)
+ 3041
12 clang             0x000000010c9a5bc5
clang::Parser::ParseStatementOrDeclaration(clang::ASTOwningVector<clang::Stmt*,
32u>&, bool, clang::SourceLocation*) + 133
13 clang             0x000000010c9acbb0
clang::Parser::ParseCompoundStatementBody(bool) + 1440
14 clang             0x000000010c9ae3fc
clang::Parser::ParseFunctionStatementBody(clang::Decl*,
clang::Parser::ParseScope&) + 284
15 clang             0x000000010c955a3f
clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) + 1359
16 clang             0x000000010c9554e4
clang::Parser::LexedMethod::ParseLexedMethodDefs() + 36
17 clang             0x000000010c954db5
clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) + 277
18 clang             0x000000010c97350d
clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, unsigned int,
clang::Decl*) + 3245
19 clang             0x000000010c97219c
clang::Parser::ParseClassSpecifier(clang::tok::TokenKind,
clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo
const&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext) + 8140
20 clang             0x000000010c95dc62
clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&,
clang::Parser::ParsedTemplateInfo const&, clang::AccessSpecifier,
clang::Parser::DeclSpecContext,
llvm::SmallVector<clang::Parser::LateParsedAttribute*, 2u>*) + 7938
21 clang             0x000000010c9bebb2
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsingDeclSpec&,
clang::AccessSpecifier) + 98
22 clang             0x000000010c9bf00c
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&,
clang::AccessSpecifier) + 108
23 clang             0x000000010c9be3d4
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
clang::ParsingDeclSpec*) + 3060
24 clang             0x000000010c9bd76d
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 461
25 clang             0x000000010c9523d0 clang::ParseAST(clang::Sema&, bool,
bool) + 336
26 clang             0x000000010c60f8a8
clang::ASTFrontendAction::ExecuteAction() + 312
27 clang             0x000000010c8e66c2 clang::CodeGenAction::ExecuteAction() +
1266
28 clang             0x000000010c60f4c7 clang::FrontendAction::Execute() + 231
29 clang             0x000000010c5da4ec
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 860
30 clang             0x000000010c5ad721
clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 961
31 clang             0x000000010c597029 cc1_main(char const**, char const**,
char const*, void*) + 969
32 clang             0x000000010c5a74dd main + 477
33 clang             0x000000010c596c34 start + 52
34 clang             0x0000000000000031 start + 18446744069207397425
Stack dump:
0.    Program arguments: /Users/tim/repos/llvm/build/Debug+Asserts/bin/clang
-cc1 -triple x86_64-apple-macosx10.7.0 -emit-obj -mrelax-all -disable-free
-main-file-name test.cc -pic-level 2 -mdisable-fp-elim -masm-verbose
-munwind-tables -target-cpu core2 -target-linker-version 128.2 -coverage-file
test.o -resource-dir
/Users/tim/repos/llvm/build/Debug+Asserts/bin/../lib/clang/3.2
-fmodule-cache-path
/var/folders/76/bdy90sw10xzctyv_bkt_p79c0000gn/T/clang-module-cache -std=c++11
-fdeprecated-macro -fdebug-compilation-dir /tmp -ferror-limit 19
-fmessage-length 272 -stack-protector 1 -mstackrealign -fblocks
-fobjc-runtime-has-arc -fobjc-runtime-has-weak -fobjc-dispatch-method=mixed
-fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions
-fdiagnostics-show-option -fcolor-diagnostics -o test.o -x c++ test.cc 
1.    test.cc:14:25: current parser token '{'
2.    test.cc:7:1: parsing struct/union/class body 'X'
3.    test.cc:13:18: parsing function body 'foo'
4.    test.cc:13:18: in compound statement ('{}')
clang: error: unable to execute command: Segmentation fault: 11
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 version 3.2 (trunk 157525)
Target: x86_64-apple-darwin11.4.0
Thread model: posix
clang: note: diagnostic msg: Preprocessed source(s) and associated run
script(s) are located at:
clang: note: diagnostic msg:
/var/folders/76/bdy90sw10xzctyv_bkt_p79c0000gn/T/test-xws6S2.ii
clang: note: diagnostic msg:
/var/folders/76/bdy90sw10xzctyv_bkt_p79c0000gn/T/test-xws6S2.sh

-- 
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