Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 312198 - Infinite loop in TemplateArgumentDeduction.fromType
Summary: Infinite loop in TemplateArgumentDeduction.fromType
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-parser (show other bugs)
Version: 7.0   Edit
Hardware: PC Linux
: P3 critical (vote)
Target Milestone: 7.0   Edit
Assignee: Markus Schorn CLA
QA Contact: Mike Kucera CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-09 21:03 EDT by Sergey Prigogin CLA
Modified: 2010-05-30 22:39 EDT (History)
0 users

See Also:


Attachments
Annotated call stack (11.40 KB, text/plain)
2010-05-09 21:03 EDT, Sergey Prigogin CLA
eclipse.sprigogin: iplog-
Details
workaround (1.08 KB, patch)
2010-05-10 05:05 EDT, Markus Schorn CLA
mschorn.eclipse: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Prigogin CLA 2010-05-09 21:03:47 EDT
Created attachment 167645 [details]
Annotated call stack

CDT HEAD:
The infinite loop is due to 'a' and 'p' variables in TemplateArgumentDeduction.fromType method wrapping null type:

        p	CPPQualifierType  (id=9805)	
        	isConst	true	
        	isVolatile	false	
        	type	null	
        a	CPPQualifierType  (id=9806)	
        	isConst	true	
        	isVolatile	false	
        	type	null	

SemanticUtil.getNestedType returns an unchanged argument in such cases.
I've attached a call stack annotated with values of local variables.

Will try to reproduce the problem on a small example, but it may not be easy.
Comment 1 Markus Schorn CLA 2010-05-10 05:05:35 EDT
Created attachment 167668 [details]
workaround

The attached patch should work around the issue. 

However, I think this is not a complete fix. Type containers pointing to null-types cause all sorts of problems. I think we should introduce a special problem-type to be used instead of null-types. That's probably something we should do in the next release.

It'd be interesting to understand why the qualified types point to null (could be an unresolved typedef or some type we fail to store in the index).
Comment 2 Sergey Prigogin CLA 2010-05-10 17:15:08 EDT
(In reply to comment #1)
I completely agree that null types are evil and should be replaced by ProblemType.
 
I'm not sure if it's the only source of CPPQualifierType wrapping null type, but one such source is marshaling/unmarshaling of a CPPQualifierType wrapping a type for which fLinkage.addTypeBinding((IBinding) type) inside TypeMarshallBuffer.marshalType(IType type) return null. This seems to happen always for ProblemBinding's and quite often for CPPTemplateTypeParameter's.
Comment 3 Sergey Prigogin CLA 2010-05-11 01:31:55 EDT
(In reply to comment #1)
> The attached patch should work around the issue. 

It does indeed.
Comment 4 Markus Schorn CLA 2010-05-11 09:41:47 EDT
(In reply to comment #2)
> (In reply to comment #1)
> I completely agree that null types are evil and should be replaced by
> ProblemType.
I have created bug 312423 for that.
>
> I'm not sure if it's the only source of CPPQualifierType wrapping null type,
> but one such source is marshaling/unmarshaling of a CPPQualifierType wrapping a
> type for which fLinkage.addTypeBinding((IBinding) type) inside
> TypeMarshallBuffer.marshalType(IType type) return null. This seems to happen
> always for ProblemBinding's and quite often for CPPTemplateTypeParameter's.

I am not aware of problems with adding template type parameters to the index. If possible, please provide an example. We must make sure that these parameters
can properly be represented in the index.

(In reply to comment #3)
> (In reply to comment #1)
> > The attached patch should work around the issue. 
> It does indeed.
Let's apply the patch as a fix for 7.0 and deal with the larger issue via bug 312423. If you agree, please go ahead and commit the workaround.
Comment 5 Sergey Prigogin CLA 2010-05-11 21:36:28 EDT
Markus' workaround submitted.