mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Fix for 203050: [bindings] StackOverflowError resolving K&R function
This commit is contained in:
parent
9497a4150a
commit
269734c953
2 changed files with 51 additions and 3 deletions
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Rational Software - Initial API and implementation
|
* IBM Rational Software - Initial API and implementation
|
||||||
|
* Anton Leherbauer (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.parser.tests.ast2;
|
package org.eclipse.cdt.core.parser.tests.ast2;
|
||||||
|
|
||||||
|
@ -19,8 +20,10 @@ import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarationStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
import org.eclipse.cdt.core.dom.ast.IASTElaboratedTypeSpecifier;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTExpressionStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
import org.eclipse.cdt.core.dom.ast.IASTFieldReference;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionCallExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTIdExpression;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
import org.eclipse.cdt.core.dom.ast.IASTLiteralExpression;
|
||||||
|
@ -654,4 +657,43 @@ public class AST2KnRTests extends AST2BaseTest {
|
||||||
assertTrue( stmts[2] instanceof IASTCompoundStatement );
|
assertTrue( stmts[2] instanceof IASTCompoundStatement );
|
||||||
assertTrue( stmts[3] instanceof IASTNullStatement );
|
assertTrue( stmts[3] instanceof IASTNullStatement );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=203050
|
||||||
|
public void testBug203050() throws Exception {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append("typedef long time_t;\n" + //$NON-NLS-1$
|
||||||
|
"\n" + //$NON-NLS-1$
|
||||||
|
"void (foo)(timep)\n" + //$NON-NLS-1$
|
||||||
|
" const time_t * const timep;\n" + //$NON-NLS-1$
|
||||||
|
"{\n" + //$NON-NLS-1$
|
||||||
|
" struct tm tmp;\n" + //$NON-NLS-1$
|
||||||
|
" bar(timep, &tmp);\n" + //$NON-NLS-1$
|
||||||
|
"}\n" + //$NON-NLS-1$
|
||||||
|
"int (bar)(timep, tmp)\n" + //$NON-NLS-1$
|
||||||
|
" const time_t * const timep;\n" + //$NON-NLS-1$
|
||||||
|
" struct tm * tmp;\n" + //$NON-NLS-1$
|
||||||
|
"{\n" + //$NON-NLS-1$
|
||||||
|
" return 0;\n" + //$NON-NLS-1$
|
||||||
|
"}\n"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
IASTTranslationUnit tu = parse(buffer.toString(), ParserLanguage.C, true, true);
|
||||||
|
assertTrue( tu.getDeclarations()[0] instanceof IASTSimpleDeclaration );
|
||||||
|
assertTrue( tu.getDeclarations()[1] instanceof IASTFunctionDefinition );
|
||||||
|
assertTrue( tu.getDeclarations()[2] instanceof IASTFunctionDefinition );
|
||||||
|
IASTStatement[] stmts = ((IASTCompoundStatement)((IASTFunctionDefinition)tu.getDeclarations()[1]).getBody()).getStatements();
|
||||||
|
assertTrue( stmts[0] instanceof IASTDeclarationStatement );
|
||||||
|
assertTrue( stmts[1] instanceof IASTExpressionStatement );
|
||||||
|
IASTExpression expr= ((IASTExpressionStatement)stmts[1]).getExpression();
|
||||||
|
assertTrue(expr instanceof IASTFunctionCallExpression);
|
||||||
|
IASTIdExpression fnameExpr= (IASTIdExpression)((IASTFunctionCallExpression)expr).getFunctionNameExpression();
|
||||||
|
fnameExpr.getName().resolveBinding();
|
||||||
|
|
||||||
|
IASTName fname= ((IASTFunctionDefinition)tu.getDeclarations()[2]).getDeclarator().getName();
|
||||||
|
try {
|
||||||
|
fname.resolveBinding();
|
||||||
|
} catch (StackOverflowError e) {
|
||||||
|
fail(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,10 +70,16 @@ public class CFunction extends PlatformObject implements IFunction, ICInternalFu
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public void addDeclarator( IASTFunctionDeclarator fnDeclarator ){
|
public void addDeclarator( IASTFunctionDeclarator fnDeclarator ){
|
||||||
updateParameterBindings( fnDeclarator );
|
if( fnDeclarator.getParent() instanceof IASTFunctionDefinition || fnDeclarator instanceof ICASTKnRFunctionDeclarator ) {
|
||||||
if( fnDeclarator.getParent() instanceof IASTFunctionDefinition || fnDeclarator instanceof ICASTKnRFunctionDeclarator )
|
if (definition == fnDeclarator) {
|
||||||
|
// recursion?
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
updateParameterBindings( fnDeclarator );
|
||||||
definition = fnDeclarator;
|
definition = fnDeclarator;
|
||||||
else {
|
return;
|
||||||
|
} else {
|
||||||
|
updateParameterBindings( fnDeclarator );
|
||||||
if( declarators == null ){
|
if( declarators == null ){
|
||||||
declarators = new IASTStandardFunctionDeclarator[] { (IASTStandardFunctionDeclarator) fnDeclarator };
|
declarators = new IASTStandardFunctionDeclarator[] { (IASTStandardFunctionDeclarator) fnDeclarator };
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue