Skip to content

Commit 405d0fc

Browse files
committed
Merge branch 'main' into redsun82/swift-precompiled-modules-are-not-extracted
2 parents 099ab0e + 593ce01 commit 405d0fc

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

java/ql/test/TestUtilities/InlineExpectationsTestPrivate.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ private class KtExpectationComment extends KtComment, ExpectationComment {
2020

2121
override string getContents() { result = this.getText().suffix(2).trim() }
2222
}
23+
24+
private class XmlExpectationComment extends ExpectationComment instanceof XMLComment {
25+
override string getContents() { result = this.(XMLComment).getText().trim() }
26+
27+
override Location getLocation() { result = this.(XMLComment).getLocation() }
28+
29+
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
30+
this.(XMLComment).hasLocationInfo(path, sl, sc, el, ec)
31+
}
32+
33+
override string toString() { result = this.(XMLComment).toString() }
34+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Test {
2+
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test.xml:4:5:4:32 | attribute=value | Unexpected result: hasXmlResult= |
2+
| test.xml:5:29:5:52 | $ hasXmlResult | Missing result:hasXmlResult= |
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import semmle.code.xml.XML
2+
import TestUtilities.InlineExpectationsTest
3+
4+
class XmlTest extends InlineExpectationsTest {
5+
XmlTest() { this = "XmlTest" }
6+
7+
override string getARelevantTag() { result = "hasXmlResult" }
8+
9+
override predicate hasActualResult(Location location, string element, string tag, string value) {
10+
tag = "hasXmlResult" and
11+
exists(XMLAttribute a |
12+
a.getLocation() = location and
13+
element = a.toString() and
14+
value = ""
15+
)
16+
}
17+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document>
3+
<element attribute="value">Text</element> <!-- $ hasXmlResult -->
4+
<element attribute="value">Text</element> <!-- Missing -->
5+
<element>Text</element> <!-- $ hasXmlResult --> <!-- Spurious -->
6+
</document>

swift/extractor/visitors/DeclVisitor.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ codeql::PatternBindingDecl DeclVisitor::translatePatternBindingDecl(
115115

116116
std::optional<codeql::ConcreteVarDecl> DeclVisitor::translateVarDecl(const swift::VarDecl& decl) {
117117
std::optional<codeql::ConcreteVarDecl> entry;
118-
if (decl.getDeclContext()->isLocalContext()) {
118+
// We do not deduplicate variables from non-swift (PCM, clang modules) modules as the mangler
119+
// crashes sometimes
120+
if (decl.getDeclContext()->isLocalContext() || decl.getModuleContext()->isNonSwiftModule()) {
119121
entry.emplace(dispatcher_.assignNewLabel(decl));
120122
} else {
121123
entry = createNamedEntry(decl);
@@ -296,6 +298,14 @@ std::string DeclVisitor::mangledName(const swift::ValueDecl& decl) {
296298
if (decl.getKind() == swift::DeclKind::Module) {
297299
return static_cast<const swift::ModuleDecl&>(decl).getRealName().str().str();
298300
}
301+
// In cases like this (when coming from PCM)
302+
// typealias CFXMLTree = CFTree
303+
// typealias CFXMLTreeRef = CFXMLTree
304+
// mangleAnyDecl mangles both CFXMLTree and CFXMLTreeRef into 'So12CFXMLTreeRefa'
305+
// which is not correct and causes inconsistencies. mangleEntity makes these two distinct
306+
if (decl.getKind() == swift::DeclKind::TypeAlias) {
307+
return mangler.mangleEntity(&decl);
308+
}
299309
// prefix adds a couple of special symbols, we don't necessary need them
300310
return mangler.mangleAnyDecl(&decl, /* prefix = */ false);
301311
}

0 commit comments

Comments
 (0)