Swift: address review comments

This commit is contained in:
Paolo Tranquilli
2022-08-26 12:49:19 +02:00
parent ebc7432f46
commit c9b14b4459
2 changed files with 81 additions and 72 deletions

View File

@@ -0,0 +1,71 @@
#pragma once
#include <array>
namespace codeql {
constexpr std::array swiftBuiltins = {
"zeroInitializer",
"BridgeObject",
"Word",
"NativeObject",
"RawPointer",
"Executor",
"Job",
"RawUnsafeContinuation",
"addressof",
"initialize",
"reinterpretCast",
"Int1",
"Int8",
"Int16",
"Int32",
"Int64",
"IntLiteral",
"FPIEEE16",
"FPIEEE32",
"FPIEEE64",
"FPIEEE80",
"Vec2xInt8",
"Vec4xInt8",
"Vec8xInt8",
"Vec16xInt8",
"Vec32xInt8",
"Vec64xInt8",
"Vec2xInt16",
"Vec4xInt16",
"Vec8xInt16",
"Vec16xInt16",
"Vec32xInt16",
"Vec64xInt16",
"Vec2xInt32",
"Vec4xInt32",
"Vec8xInt32",
"Vec16xInt32",
"Vec32xInt32",
"Vec64xInt32",
"Vec2xInt64",
"Vec4xInt64",
"Vec8xInt64",
"Vec16xInt64",
"Vec32xInt64",
"Vec64xInt64",
"Vec2xFPIEEE16",
"Vec4xFPIEEE16",
"Vec8xFPIEEE16",
"Vec16xFPIEEE16",
"Vec32xFPIEEE16",
"Vec64xFPIEEE16",
"Vec2xFPIEEE32",
"Vec4xFPIEEE32",
"Vec8xFPIEEE32",
"Vec16xFPIEEE32",
"Vec32xFPIEEE32",
"Vec64xFPIEEE32",
"Vec2xFPIEEE64",
"Vec4xFPIEEE64",
"Vec8xFPIEEE64",
"Vec16xFPIEEE64",
"Vec32xFPIEEE64",
"Vec64xFPIEEE64",
};
}

View File

@@ -7,15 +7,11 @@
#include <swift/AST/SourceFile.h>
#include <swift/AST/Builtins.h>
#include <swift/Basic/FileTypes.h>
#include <llvm/ADT/SmallString.h>
#include <llvm/Support/FileSystem.h>
#include <llvm/Support/Path.h>
#include "swift/extractor/trap/generated/TrapClasses.h"
#include "swift/extractor/trap/TrapDomain.h"
#include "swift/extractor/visitors/SwiftVisitor.h"
#include "swift/extractor/TargetTrapFile.h"
#include "swift/extractor/SwiftBuiltinSymbols.h"
using namespace codeql;
using namespace std::string_literals;
@@ -68,9 +64,15 @@ static std::string getFilename(swift::ModuleDecl& module, swift::SourceFile* pri
}
if (module.isBuiltinModule()) {
// The Builtin module has an empty filename, let's fix that
return "/<Builtin>";
return "/__Builtin__";
}
return module.getModuleFilename().str();
auto filename = module.getModuleFilename().str();
// there is a special case of a module without an actual filename reporting `<imports>`: in this
// case we want to avoid the `<>` characters, in case a dirty DB is imported on Windows
if (filename == "<imports>") {
return "/__imports__";
}
return filename;
}
/* 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
static void getBuiltinDecls(swift::ModuleDecl& builtinModule,
llvm::SmallVector<swift::Decl*>& decls) {
llvm::SmallVector<swift::ValueDecl*> values;
for (auto symbol : {
"zeroInitializer",
"BridgeObject",
"Word",
"NativeObject",
"RawPointer",
"Executor",
"Job",
"RawUnsafeContinuation",
"addressof",
"initialize",
"reinterpretCast",
"Int1",
"Int8",
"Int16",
"Int32",
"Int64",
"IntLiteral",
"FPIEEE16",
"FPIEEE32",
"FPIEEE64",
"FPIEEE80",
"Vec2xInt8",
"Vec4xInt8",
"Vec8xInt8",
"Vec16xInt8",
"Vec32xInt8",
"Vec64xInt8",
"Vec2xInt16",
"Vec4xInt16",
"Vec8xInt16",
"Vec16xInt16",
"Vec32xInt16",
"Vec64xInt16",
"Vec2xInt32",
"Vec4xInt32",
"Vec8xInt32",
"Vec16xInt32",
"Vec32xInt32",
"Vec64xInt32",
"Vec2xInt64",
"Vec4xInt64",
"Vec8xInt64",
"Vec16xInt64",
"Vec32xInt64",
"Vec64xInt64",
"Vec2xFPIEEE16",
"Vec4xFPIEEE16",
"Vec8xFPIEEE16",
"Vec16xFPIEEE16",
"Vec32xFPIEEE16",
"Vec64xFPIEEE16",
"Vec2xFPIEEE32",
"Vec4xFPIEEE32",
"Vec8xFPIEEE32",
"Vec16xFPIEEE32",
"Vec32xFPIEEE32",
"Vec64xFPIEEE32",
"Vec2xFPIEEE64",
"Vec4xFPIEEE64",
"Vec8xFPIEEE64",
"Vec16xFPIEEE64",
"Vec32xFPIEEE64",
"Vec64xFPIEEE64",
}) {
for (auto symbol : swiftBuiltins) {
builtinModule.lookupValue(builtinModule.getASTContext().getIdentifier(symbol),
swift::NLKind::QualifiedLookup, values);
}