logic: implemented handling Microsoft inline assembly statements
This commit is contained in:
+1
-1
@@ -279,7 +279,7 @@ target_include_directories(${LIB_CXX_PROJECT_NAME} SYSTEM
|
||||
)
|
||||
|
||||
link_directories(${LLVM_LIBRARY_DIRS} ${CLANG_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS})
|
||||
llvm_map_components_to_libnames(REQ_LLVM_LIBS support core libdriver passes)
|
||||
llvm_map_components_to_libnames(REQ_LLVM_LIBS support core libdriver passes x86asmparser x86codegen)
|
||||
|
||||
target_link_libraries(${LIB_CXX_PROJECT_NAME} ${CLANG_LIBRARIES} ${REQ_LLVM_LIBS})
|
||||
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
#include "data/parser/cxx/CxxParser.h"
|
||||
|
||||
#include "clang/Tooling/Tooling.h"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
|
||||
#include "data/indexer/IndexerCommandCxxCdb.h"
|
||||
#include "data/indexer/IndexerCommandCxxEmpty.h"
|
||||
@@ -14,6 +10,11 @@
|
||||
#include "data/parser/cxx/CxxCompilationDatabaseSingle.h"
|
||||
#include "data/parser/cxx/CxxDiagnosticConsumer.h"
|
||||
|
||||
#include "utility/file/FilePath.h"
|
||||
#include "utility/file/FileRegister.h"
|
||||
#include "utility/logging/logging.h"
|
||||
#include "utility/text/TextAccess.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
static std::vector<std::string> getSyntaxOnlyToolArgs(const std::vector<std::string> &ExtraArgs, llvm::StringRef FileName)
|
||||
@@ -59,6 +60,8 @@ CxxParser::CxxParser(std::shared_ptr<ParserClient> client, std::shared_ptr<FileR
|
||||
: Parser(client)
|
||||
, m_fileRegister(fileRegister)
|
||||
{
|
||||
llvm::InitializeNativeTarget();
|
||||
llvm::InitializeNativeTargetAsmParser();
|
||||
}
|
||||
|
||||
CxxParser::~CxxParser()
|
||||
@@ -90,14 +93,14 @@ void CxxParser::buildIndex(std::shared_ptr<IndexerCommandCxxEmpty> indexerComman
|
||||
runTool(compilationDatabase.get(), indexerCommand->getSourceFilePath());
|
||||
}
|
||||
|
||||
void CxxParser::buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent)
|
||||
void CxxParser::buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent, std::vector<std::string> compilerFlags)
|
||||
{
|
||||
std::shared_ptr<CanonicalFilePathCache> canonicalFilePathCache = std::make_shared<CanonicalFilePathCache>();
|
||||
|
||||
std::shared_ptr<CxxDiagnosticConsumer> diagnostics = getDiagnostics(canonicalFilePathCache, false);
|
||||
ASTActionFactory actionFactory(m_client, m_fileRegister, canonicalFilePathCache);
|
||||
|
||||
std::vector<std::string> args = getCommandlineArgumentsEssential(std::vector<std::string>(1, "-std=c++1z"), std::vector<FilePath>(), std::vector<FilePath>());
|
||||
std::vector<std::string> args = getCommandlineArgumentsEssential(compilerFlags, std::vector<FilePath>(), std::vector<FilePath>());
|
||||
|
||||
runToolOnCodeWithArgs(
|
||||
diagnostics.get(),
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
|
||||
void buildIndex(std::shared_ptr<IndexerCommandCxxCdb> indexerCommand);
|
||||
void buildIndex(std::shared_ptr<IndexerCommandCxxEmpty> indexerCommand);
|
||||
void buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent);
|
||||
void buildIndex(const std::string& fileName, std::shared_ptr<TextAccess> fileContent, std::vector<std::string> compilerFlags = {});
|
||||
|
||||
private:
|
||||
void runTool(clang::tooling::CompilationDatabase* compilationDatabase, const FilePath& sourceFilePath);
|
||||
|
||||
@@ -1923,8 +1923,7 @@ public:
|
||||
"};\n"
|
||||
"class B : public A {\n"
|
||||
" int foo();\n"
|
||||
"};\n",
|
||||
false
|
||||
"};\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->errors.size(), 1);
|
||||
@@ -3829,6 +3828,30 @@ public:
|
||||
));
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_usage_of_local_variable_in_microsoft_inline_assembly_statement()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"void foo()\n"
|
||||
"{\n"
|
||||
" int x = 2;\n"
|
||||
"__asm\n"
|
||||
"{\n"
|
||||
" mov eax, x\n"
|
||||
" mov x, eax\n"
|
||||
"}\n"
|
||||
"}\n",
|
||||
{ "--target=i686-pc-windows-msvc" }
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<3:6> <6:11 6:11>"
|
||||
));
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->localSymbols, "input.cc<3:6> <7:6 7:6>"
|
||||
));
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_template_argument_of_unresolved_lookup_expression()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
@@ -4010,8 +4033,7 @@ public:
|
||||
void test_cxx_parser_catches_error()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"int a = b;\n",
|
||||
false
|
||||
"int a = b;\n"
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
@@ -4059,12 +4081,12 @@ public:
|
||||
// }
|
||||
|
||||
private:
|
||||
std::shared_ptr<TestParserClient> parseCode(std::string code, bool logErrors = true)
|
||||
std::shared_ptr<TestParserClient> parseCode(std::string code, std::vector<std::string> compilerFlags = {})
|
||||
{
|
||||
std::shared_ptr<TestFileRegister> fileRegister = std::make_shared<TestFileRegister>();
|
||||
std::shared_ptr<TestParserClient> parserClient = std::make_shared<TestParserClient>();
|
||||
CxxParser parser(parserClient, fileRegister);
|
||||
parser.buildIndex("input.cc", TextAccess::createFromString(code));
|
||||
parser.buildIndex("input.cc", TextAccess::createFromString(code), utility::concat(compilerFlags, std::vector<std::string>(1, "-std=c++1z")));
|
||||
return parserClient;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user