Skip to content

Commit c9b14b4

Browse files
committed
Swift: address review comments
1 parent ebc7432 commit c9b14b4

File tree

2 files changed

+81
-72
lines changed

2 files changed

+81
-72
lines changed

swift/extractor/SwiftBuiltinSymbols.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#pragma once
2+
3+
#include <array>
4+
5+
namespace codeql {
6+
constexpr std::array swiftBuiltins = {
7+
"zeroInitializer",
8+
"BridgeObject",
9+
"Word",
10+
"NativeObject",
11+
"RawPointer",
12+
"Executor",
13+
"Job",
14+
"RawUnsafeContinuation",
15+
"addressof",
16+
"initialize",
17+
"reinterpretCast",
18+
"Int1",
19+
"Int8",
20+
"Int16",
21+
"Int32",
22+
"Int64",
23+
"IntLiteral",
24+
"FPIEEE16",
25+
"FPIEEE32",
26+
"FPIEEE64",
27+
"FPIEEE80",
28+
"Vec2xInt8",
29+
"Vec4xInt8",
30+
"Vec8xInt8",
31+
"Vec16xInt8",
32+
"Vec32xInt8",
33+
"Vec64xInt8",
34+
"Vec2xInt16",
35+
"Vec4xInt16",
36+
"Vec8xInt16",
37+
"Vec16xInt16",
38+
"Vec32xInt16",
39+
"Vec64xInt16",
40+
"Vec2xInt32",
41+
"Vec4xInt32",
42+
"Vec8xInt32",
43+
"Vec16xInt32",
44+
"Vec32xInt32",
45+
"Vec64xInt32",
46+
"Vec2xInt64",
47+
"Vec4xInt64",
48+
"Vec8xInt64",
49+
"Vec16xInt64",
50+
"Vec32xInt64",
51+
"Vec64xInt64",
52+
"Vec2xFPIEEE16",
53+
"Vec4xFPIEEE16",
54+
"Vec8xFPIEEE16",
55+
"Vec16xFPIEEE16",
56+
"Vec32xFPIEEE16",
57+
"Vec64xFPIEEE16",
58+
"Vec2xFPIEEE32",
59+
"Vec4xFPIEEE32",
60+
"Vec8xFPIEEE32",
61+
"Vec16xFPIEEE32",
62+
"Vec32xFPIEEE32",
63+
"Vec64xFPIEEE32",
64+
"Vec2xFPIEEE64",
65+
"Vec4xFPIEEE64",
66+
"Vec8xFPIEEE64",
67+
"Vec16xFPIEEE64",
68+
"Vec32xFPIEEE64",
69+
"Vec64xFPIEEE64",
70+
};
71+
}

swift/extractor/SwiftExtractor.cpp

Lines changed: 10 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77

88
#include <swift/AST/SourceFile.h>
99
#include <swift/AST/Builtins.h>
10-
#include <swift/Basic/FileTypes.h>
11-
#include <llvm/ADT/SmallString.h>
12-
#include <llvm/Support/FileSystem.h>
13-
#include <llvm/Support/Path.h>
1410

15-
#include "swift/extractor/trap/generated/TrapClasses.h"
1611
#include "swift/extractor/trap/TrapDomain.h"
1712
#include "swift/extractor/visitors/SwiftVisitor.h"
1813
#include "swift/extractor/TargetTrapFile.h"
14+
#include "swift/extractor/SwiftBuiltinSymbols.h"
1915

2016
using namespace codeql;
2117
using namespace std::string_literals;
@@ -68,9 +64,15 @@ static std::string getFilename(swift::ModuleDecl& module, swift::SourceFile* pri
6864
}
6965
if (module.isBuiltinModule()) {
7066
// The Builtin module has an empty filename, let's fix that
71-
return "/<Builtin>";
67+
return "/__Builtin__";
7268
}
73-
return module.getModuleFilename().str();
69+
auto filename = module.getModuleFilename().str();
70+
// there is a special case of a module without an actual filename reporting `<imports>`: in this
71+
// case we want to avoid the `<>` characters, in case a dirty DB is imported on Windows
72+
if (filename == "<imports>") {
73+
return "/__imports__";
74+
}
75+
return filename;
7476
}
7577

7678
/* The builtin module is special, as it does not publish any top-level declaration
@@ -89,71 +91,7 @@ static std::string getFilename(swift::ModuleDecl& module, swift::SourceFile* pri
8991
static void getBuiltinDecls(swift::ModuleDecl& builtinModule,
9092
llvm::SmallVector<swift::Decl*>& decls) {
9193
llvm::SmallVector<swift::ValueDecl*> values;
92-
for (auto symbol : {
93-
"zeroInitializer",
94-
"BridgeObject",
95-
"Word",
96-
"NativeObject",
97-
"RawPointer",
98-
"Executor",
99-
"Job",
100-
"RawUnsafeContinuation",
101-
"addressof",
102-
"initialize",
103-
"reinterpretCast",
104-
"Int1",
105-
"Int8",
106-
"Int16",
107-
"Int32",
108-
"Int64",
109-
"IntLiteral",
110-
"FPIEEE16",
111-
"FPIEEE32",
112-
"FPIEEE64",
113-
"FPIEEE80",
114-
"Vec2xInt8",
115-
"Vec4xInt8",
116-
"Vec8xInt8",
117-
"Vec16xInt8",
118-
"Vec32xInt8",
119-
"Vec64xInt8",
120-
"Vec2xInt16",
121-
"Vec4xInt16",
122-
"Vec8xInt16",
123-
"Vec16xInt16",
124-
"Vec32xInt16",
125-
"Vec64xInt16",
126-
"Vec2xInt32",
127-
"Vec4xInt32",
128-
"Vec8xInt32",
129-
"Vec16xInt32",
130-
"Vec32xInt32",
131-
"Vec64xInt32",
132-
"Vec2xInt64",
133-
"Vec4xInt64",
134-
"Vec8xInt64",
135-
"Vec16xInt64",
136-
"Vec32xInt64",
137-
"Vec64xInt64",
138-
"Vec2xFPIEEE16",
139-
"Vec4xFPIEEE16",
140-
"Vec8xFPIEEE16",
141-
"Vec16xFPIEEE16",
142-
"Vec32xFPIEEE16",
143-
"Vec64xFPIEEE16",
144-
"Vec2xFPIEEE32",
145-
"Vec4xFPIEEE32",
146-
"Vec8xFPIEEE32",
147-
"Vec16xFPIEEE32",
148-
"Vec32xFPIEEE32",
149-
"Vec64xFPIEEE32",
150-
"Vec2xFPIEEE64",
151-
"Vec4xFPIEEE64",
152-
"Vec8xFPIEEE64",
153-
"Vec16xFPIEEE64",
154-
"Vec32xFPIEEE64",
155-
"Vec64xFPIEEE64",
156-
}) {
94+
for (auto symbol : swiftBuiltins) {
15795
builtinModule.lookupValue(builtinModule.getASTContext().getIdentifier(symbol),
15896
swift::NLKind::QualifiedLookup, values);
15997
}

0 commit comments

Comments
 (0)