1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug 393129 - Do not give "unused symbol" warning for file-scope variable

used in an asm block

Change-Id: I2088bed2dd26af1220069dbdf18fda17d32fdf21
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
Reviewed-on: https://git.eclipse.org/r/14608
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
IP-Clean: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Nathan Ridge 2013-07-16 21:32:29 -04:00 committed by Sergey Prigogin
parent ad080ac26c
commit 55872baeae
2 changed files with 41 additions and 0 deletions

View file

@ -25,6 +25,7 @@ import org.eclipse.cdt.codan.core.model.IProblem;
import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
import org.eclipse.cdt.codan.core.param.ListProblemPreference;
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
import org.eclipse.cdt.core.dom.ast.IASTASMDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
@ -226,6 +227,7 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker {
ast.accept(new ASTVisitor() {
{
shouldVisitNames = true;
shouldVisitDeclarations = true;
}
@Override
@ -266,7 +268,36 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker {
return PROCESS_CONTINUE;
}
@Override
public int visit(IASTDeclaration declaration) {
// Bug 393129: A variable could be used inside assembly code.
if (declaration instanceof IASTASMDeclaration) {
String assembly = ((IASTASMDeclaration) declaration).getAssembly();
filterOutByAssembly(externFunctionDeclarations, assembly);
filterOutByAssembly(staticFunctionDeclarations, assembly);
filterOutByAssembly(staticFunctionDefinitions, assembly);
filterOutByAssembly(externVariableDeclarations, assembly);
filterOutByAssembly(staticVariableDeclarations, assembly);
}
if (!isAnyCandidate())
return PROCESS_ABORT;
return PROCESS_CONTINUE;
}
private void filterOutByAssembly(Map<IBinding, IASTDeclarator> declarators, String assembly) {
Iterator<Entry<IBinding, IASTDeclarator>> iter = declarators.entrySet().iterator();
while (iter.hasNext()) {
Entry<IBinding, IASTDeclarator> entry = iter.next();
IASTDeclarator decl = entry.getValue();
IASTName astName = getAstName(decl);
if (assembly.contains(astName.toString()))
iter.remove();
}
}
private void filterOutByPlainName(Map<IBinding, IASTDeclarator> declarators, String id) {
Iterator<Entry<IBinding, IASTDeclarator>> iter = declarators.entrySet().iterator();
while (iter.hasNext()) {

View file

@ -317,4 +317,14 @@ public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
// extern int* pxCurrentTCB;
//
// int main() {
// asm ("lds r26, pxCurrentTCB\n\t");
// }
public void testUseInAsm_bug393129() throws IOException {
loadCodeAndRun(getAboveComment());
checkNoErrors();
}
}