mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 16:56:04 +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:
parent
ad080ac26c
commit
55872baeae
2 changed files with 41 additions and 0 deletions
|
@ -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.model.IProblemWorkingCopy;
|
||||||
import org.eclipse.cdt.codan.core.param.ListProblemPreference;
|
import org.eclipse.cdt.codan.core.param.ListProblemPreference;
|
||||||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
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.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclarator;
|
||||||
|
@ -226,6 +227,7 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker {
|
||||||
ast.accept(new ASTVisitor() {
|
ast.accept(new ASTVisitor() {
|
||||||
{
|
{
|
||||||
shouldVisitNames = true;
|
shouldVisitNames = true;
|
||||||
|
shouldVisitDeclarations = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -267,6 +269,35 @@ public class UnusedSymbolInFileScopeChecker extends AbstractIndexAstChecker {
|
||||||
return PROCESS_CONTINUE;
|
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) {
|
private void filterOutByPlainName(Map<IBinding, IASTDeclarator> declarators, String id) {
|
||||||
Iterator<Entry<IBinding, IASTDeclarator>> iter = declarators.entrySet().iterator();
|
Iterator<Entry<IBinding, IASTDeclarator>> iter = declarators.entrySet().iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
|
|
|
@ -317,4 +317,14 @@ public class UnusedSymbolInFileScopeCheckerTest extends CheckerTestCase {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
checkNoErrors();
|
checkNoErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extern int* pxCurrentTCB;
|
||||||
|
//
|
||||||
|
// int main() {
|
||||||
|
// asm ("lds r26, pxCurrentTCB\n\t");
|
||||||
|
// }
|
||||||
|
public void testUseInAsm_bug393129() throws IOException {
|
||||||
|
loadCodeAndRun(getAboveComment());
|
||||||
|
checkNoErrors();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue