summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2013-07-16 21:32:29 (EDT)
committerSergey Prigogin2013-07-17 14:57:53 (EDT)
commit111a01f5a66eb8a8c4ac8fe1c1359404132ac46a (patch)
treeb15dfd96ceae676d2c4255cab0ba856b865704c1
parent34341139d975fecad466c8e2bb02974add40b23c (diff)
downloadorg.eclipse.cdt-111a01f5a66eb8a8c4ac8fe1c1359404132ac46a.zip
org.eclipse.cdt-111a01f5a66eb8a8c4ac8fe1c1359404132ac46a.tar.gz
org.eclipse.cdt-111a01f5a66eb8a8c4ac8fe1c1359404132ac46a.tar.bz2
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>
-rw-r--r--codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java31
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java10
2 files changed, 41 insertions, 0 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java
index 9c34d78..37a94f8 100644
--- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java
+++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/UnusedSymbolInFileScopeChecker.java
@@ -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()) {
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java
index 7bb967e..4849df4 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/UnusedSymbolInFileScopeCheckerTest.java
@@ -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();
+ }
}