Bug 71839 - [Parser] Parser in infinite loop (ExpressionParser.errorHandling())
Summary: [Parser] Parser in infinite loop (ExpressionParser.errorHandling())
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 2.0.1   Edit
Assignee: John Camelon CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-08-11 19:40 EDT by Alain Magloire CLA
Modified: 2004-08-18 23:32 EDT (History)
2 users (show)

See Also:


Attachments
foo.cc (576 bytes, text/plain)
2004-08-11 19:41 EDT, Alain Magloire CLA
no flags Details
header in question (4.47 KB, application/octet-stream)
2004-08-18 19:29 EDT, Chris Wiebe CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alain Magloire CLA 2004-08-11 19:40:50 EDT
Using Cygwin on Windows XP __and__ setting "structural parsing" 
(note the the auto discovery stuff is on to get the right include path), the
below file, also in attachment put the parser in infinite loop
in ExpressionParser.errorHandling(), the swith case never return.

#include <iostream>
#include <string.h>

#include <vector>
using namespace std;
int main()
{
      vector<char> A(10);

      cout << "Tamaño = " << A.size() << endl;
      for(size_t i = 0; i<A.size(); ++i) A[i]= i + 'a';

      cout << "Contenido " << endl;
      for(size_t i = 0; i<A.size(); ++i) cout << A[i];
       cout << endl;

      A.push_back('z');

      cout << "Nuevo Tamaño = " << A.size() << endl;
      cout << "Nuevo Contenido " << endl;
      for(size_t i = 0; i<A.size(); ++i) cout << A[i];
      cout << endl;

      return 0;
}
Comment 1 Alain Magloire CLA 2004-08-11 19:41:42 EDT
Created attachment 13893 [details]
foo.cc
Comment 2 Alain Magloire CLA 2004-08-11 19:42:34 EDT
wrong component should be CDT_parse
Comment 3 John Camelon CLA 2004-08-13 10:23:07 EDT
Are you seeing this w/HEAD or 2_0 branch?
Comment 4 John Camelon CLA 2004-08-13 11:16:44 EDT
I cannot reproduce this with either HEAD or 2_0.  
Can either of you try this again and let me know if it's still reproducible?
Thanks in advance
Comment 5 Alain Magloire CLA 2004-08-13 12:18:26 EDT
I can not test it since all I got now is an ArrayIndexOOBException
See log below.
Let me update again from the repository and I'll get back to you.

Thread [org.eclipse.cdt.internal.ui.text.CSourceViewerConfiguration$1] 
(Suspended (exception ArrayIndexOutOfBoundsException))
	Scanner2.branchState(int) line: 1136
	Scanner2.skipOverConditionalCode(boolean) line: 1766
	Scanner2.handlePPDirective(int) line: 1221
	Scanner2.fetchToken() line: 528
	Scanner2.nextToken() line: 326
	StructuralParser(ExpressionParser).fetchToken() line: 2722
	StructuralParser(ExpressionParser).LA(int) line: 147
	StructuralParser(ExpressionParser).LT(int) line: 165
	StructuralParser(ExpressionParser).consumeTemplateArguments(IASTScope, 
IToken, TemplateParameterManager, IASTCompletionNode$CompletionKind) line: 605
	StructuralParser(ExpressionParser).name(IASTScope, 
IASTCompletionNode$CompletionKind, KeywordSetKey) line: 490
	StructuralParser(ExpressionParser).consumePointerOperators
(IDeclarator) line: 785
	StructuralParser(Parser).declarator(IDeclaratorOwner, IASTScope, 
SimpleDeclarationStrategy, IASTCompletionNode$CompletionKind) line: 2354
	StructuralParser(Parser).initDeclarator(DeclarationWrapper, 
SimpleDeclarationStrategy, IASTCompletionNode$CompletionKind, boolean) line: 
2015
	StructuralParser(Parser).simpleDeclaration(SimpleDeclarationStrategy, 
IASTScope, IASTTemplate, IASTCompletionNode$CompletionKind, boolean, 
KeywordSetKey) line: 1181
	StructuralParser(Parser).simpleDeclarationStrategyUnion(IASTScope, 
IASTTemplate, IASTCompletionNode$CompletionKind, KeywordSetKey) line: 923
	StructuralParser(Parser).declaration(IASTScope, IASTTemplate, 
IASTCompletionNode$CompletionKind, KeywordSetKey) line: 899
	StructuralParser(Parser).linkageSpecification(IASTScope) line: 445
	StructuralParser(Parser).declaration(IASTScope, IASTTemplate, 
IASTCompletionNode$CompletionKind, KeywordSetKey) line: 895
	StructuralParser(Parser).translationUnit() line: 187
	StructuralParser(Parser).parse() line: 140
	CModelBuilder.parse(boolean, boolean) line: 192
	CModelBuilder.parse(boolean) line: 206
	WorkingCopy(TranslationUnit).parse(Map) line: 487
	WorkingCopy(TranslationUnit).buildStructure(OpenableInfo, 
IProgressMonitor, Map, IResource) line: 315
	WorkingCopy(Openable).generateInfos(Object, Map, IProgressMonitor) 
line: 291
	WorkingCopy(CElement).openWhenClosed(CElementInfo, IProgressMonitor) 
line: 403
	WorkingCopy(Openable).makeConsistent(IProgressMonitor, boolean) line: 
217
	WorkingCopy(Openable).makeConsistent(IProgressMonitor) line: 202
	ReconcileWorkingCopyOperation.executeOperation() line: 49
	ReconcileWorkingCopyOperation(CModelOperation).execute() line: 312
	ReconcileWorkingCopyOperation(CModelOperation).run(IProgressMonitor) 
line: 531
	CModelManager.runOperation(CModelOperation, IProgressMonitor) line: 927
	WorkingCopy(CElement).runOperation(CModelOperation, IProgressMonitor) 
line: 346
	WorkingCopy.reconcile(boolean, IProgressMonitor) line: 300
	CReconcilingStrategy.reconcile() line: 72
	CReconcilingStrategy.reconcile(IRegion) line: 54
	CSourceViewerConfiguration$1(Reconciler).process(DirtyRegion) line: 149
	AbstractReconciler$BackgroundThread.run() line: 204
Comment 6 John Camelon CLA 2004-08-13 13:47:14 EDT
Andrew has committed a fix to the ArrayOutOfBoundsException.
He apologizes to all who suffered.
Comment 7 Alain Magloire CLA 2004-08-13 15:14:00 EDT
> He apologizes to all who suffered.

8-)
It is better, meaning that the ArrayIndexOOB and the forever loop
are gone.
You can turn this to "Fixed" as I can now open the file in the ceditor.

The verification was done using the head.

Thanks.

But now I have a new problem .. better use a new PR.
Comment 8 John Camelon CLA 2004-08-13 15:28:34 EDT
Lowering to Major since I cannot reproduce the problem.  
Comment 9 John Camelon CLA 2004-08-13 15:32:18 EDT
Sorry, I didn't see your comment. 
Marking as fixed. 
Thanks Alain!
Comment 10 Alain Magloire CLA 2004-08-18 19:27:13 EDT
Still happens, but not the IndexOOB but the loop
Chris will attach a test case and the debug stack
Comment 11 Chris Wiebe CLA 2004-08-18 19:29:09 EDT
Created attachment 14067 [details]
header in question
Comment 12 Chris Wiebe CLA 2004-08-18 19:29:45 EDT
I'll still getting this problem when opening "cygwin/usr/include/inttypes.h".

Thread [main] (Suspended)
	StructuralParser(ExpressionParser).LA(int) line: 149
	StructuralParser(ExpressionParser).LT(int) line: 165
	StructuralParser(ExpressionParser).errorHandling() line: 2902
	StructuralParser(Parser).failParseWithErrorHandling() line: 283
	StructuralParser(Parser).linkageSpecification(IASTScope) line: 452
	StructuralParser(Parser).declaration(IASTScope, IASTTemplate,
IASTCompletionNode$CompletionKind, KeywordSetKey) line: 896
	StructuralParser(Parser).translationUnit() line: 187
	StructuralParser(Parser).parse() line: 140
	CModelBuilder.parse(boolean, boolean) line: 192
	CModelBuilder.parse(boolean) line: 206
	ExternalTranslationUnit(TranslationUnit).parse(Map) line: 487
	ExternalTranslationUnit(TranslationUnit).buildStructure(OpenableInfo,
IProgressMonitor, Map, IResource) line: 315
	ExternalTranslationUnit(Openable).generateInfos(Object, Map, IProgressMonitor)
line: 291
	ExternalTranslationUnit(CElement).openWhenClosed(CElementInfo,
IProgressMonitor) line: 403
	ExternalTranslationUnit(CElement).getElementInfo(IProgressMonitor) line: 288
	ExternalTranslationUnit(CElement).getElementInfo() line: 278
	ExternalTranslationUnit(Openable).getBuffer() line: 110
	EditorUtility.getStorage(ITranslationUnit) line: 424
	EditorUtility.getEditorInput(ICElement) line: 210
	EditorUtility.getEditorInput(Object) line: 226
	EditorUtility.isOpenInEditor(Object) line: 69
	CView.linkToEditor(IStructuredSelection) line: 871
	CView$5.run() line: 293
	RunnableLock.run() line: 35
	UISynchronizer(Synchronizer).runAsyncMessages() line: 106
	Display.runAsyncMessages() line: 2749
	Display.readAndDispatch() line: 2434
	Workbench.runEventLoop(Window$IExceptionHandler, Display) line: 1377
	Workbench.runUI() line: 1348
	Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 254
	PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 141
	IDEApplication.run(Object) line: 96
	PlatformActivator$1.run(Object) line: 335
	EclipseStarter.run(Object) line: 273
	EclipseStarter.run(String[], Runnable) line: 129
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available
[native method]
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25
	Method.invoke(Object, Object[]) line: 324
	Main.basicRun(String[]) line: 183
	Main.run(String[]) line: 644
	Main.main(String[]) line: 628
Comment 13 John Camelon CLA 2004-08-18 23:03:59 EDT
Something pretty bad has happened here in the scanner ... 
IToken '{''s next token is itself, thus, errorHandling loops forever. 
Comment 14 John Camelon CLA 2004-08-18 23:15:44 EDT
#error was encountered in ieefp.h and caused Scanner2 to get confused.  
Comment 15 John Camelon CLA 2004-08-18 23:32:06 EDT
Fix applied to HEAD & 2_0.  
#error was causing an infinite loop.