<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Fixed by <a href="https://reviews.llvm.org/D71748" class="">https://reviews.llvm.org/D71748</a>. Will land this today.<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 18. Dec 2019, at 23:03, Raphael “Teemperor” Isemann <<a href="mailto:teemperor@gmail.com" class="">teemperor@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><span class="">I’m actually already investigating that because I see the same failure when I moved the ::Initialize and ::Terminate calls to SetUp and TearDown as part </span><span class=""></span><span class="">of </span><span class="">D71630. I’ll reply here when I have a fix, thanks!</span><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 18, 2019, at 10:54 PM, Jordan Rupprecht <<a href="mailto:rupprecht@google.com" class="">rupprecht@google.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">We're seeing some odd test failures internally caused by this patch. For whatever reason (test ordering based on hashing, I guess), we're running the tests in a different order than upstream, and TestClangASTContext crashes when TestClangASTImporter runs first.<div class=""><br class=""></div><div class="">By default, it seems like TestClangASTContext happens to run first so the failure isn't usually seen, but the failure can be reproduced with --gtest_repeat=2</div><div class="">$ ninja SymbolTests && tools/lldb/unittests/Symbol/SymbolTests '--gtest_filter=TestClangAST*' --gtest_repeat=2</div><div class="">Repeating all tests (iteration 1) . . .<br class=""><br class="">Note: Google Test filter = TestClangAST*<br class=""></div><div class="">[[ TestClangASTContext passes ]]</div><div class="">[[ TestClangASTImporter passes ]]</div><div class=""><br class=""></div><div class="">Repeating all tests (iteration 2) . . .<br class=""><br class="">Note: Google Test filter = TestClangAST*<br class="">[==========] Running 21 tests from 2 test cases.<br class="">[----------] Global test environment set-up.<br class="">[----------] 13 tests from TestClangASTContext<br class="">[ RUN      ] TestClangASTContext.TestGetBasicTypeFromEnum<br class="">SymbolTests: /src/llvm-project/llvm/../clang/include/clang/AST/Type.h:669: const clang::ExtQualsTypeCommonBase *clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.<br class=""> #0 0x000000000215e5a7 llvm::sys::PrintStackTrace(llvm::raw_ostream&) /src/llvm-project/llvm/lib/Support/Unix/Signals.inc:548:11<br class=""> #1 0x000000000215e749 PrintStackTraceSignalHandler(void*) /src/llvm-project/llvm/lib/Support/Unix/Signals.inc:609:1<br class=""> #2 0x000000000215d02b llvm::sys::RunSignalHandlers() /src/llvm-project/llvm/lib/Support/Signals.cpp:67:5<br class=""> #3 0x000000000215eec5 SignalHandler(int) /src/llvm-project/llvm/lib/Support/Unix/Signals.inc:390:1<br class=""> #4 0x00007f819b4523a0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x123a0)<br class=""> #5 0x00007f819a3decfb gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x36cfb)<br class=""> #6 0x00007f819a3c98ad abort (/lib/x86_64-linux-gnu/libc.so.6+0x218ad)<br class=""> #7 0x00007f819a3c977f __tls_get_addr (/lib/x86_64-linux-gnu/libc.so.6+0x2177f)<br class=""> #8 0x00007f819a3d7542 (/lib/x86_64-linux-gnu/libc.so.6+0x2f542)<br class=""> #9 0x00000000020531d7 clang::QualType::getCommonPtr() const /src/llvm-project/llvm/../clang/include/clang/AST/Type.h:0:5<br class="">#10 0x00000000020529cc clang::QualType::getCanonicalType() const /src/llvm-project/llvm/../clang/include/clang/AST/Type.h:6231:20<br class="">#11 0x0000000002052879 clang::ASTContext::getCanonicalType(clang::QualType) const /src/llvm-project/llvm/../clang/include/clang/AST/ASTContext.h:2296:40<br class="">#12 0x0000000002050960 clang::ASTContext::hasSameType(clang::QualType, clang::QualType) const /src/llvm-project/llvm/../clang/include/clang/AST/ASTContext.h:2312:12<br class="">#13 0x0000000002047365 TestClangASTContext_TestGetBasicTypeFromEnum_Test::TestBody() /src/llvm-project/lldb/unittests/Symbol/TestClangASTContext.cpp:57:3<br class=""></div><div class=""><...></div><div class=""><br class=""></div><div class="">Does the failure make sense to you?</div><div class="">No need to revert the patch -- we already have the test disabled internally, though we would like to re-enable it</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Dec 16, 2019 at 3:44 AM Raphael Isemann via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org" class="">lldb-commits@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br class="">
Author: Raphael Isemann<br class="">
Date: 2019-12-16T12:43:55+01:00<br class="">
New Revision: 22caa3cfbcf5762a47acc40c425d9fe0c40da621<br class="">
<br class="">
URL: <a href="https://github.com/llvm/llvm-project/commit/22caa3cfbcf5762a47acc40c425d9fe0c40da621" rel="noreferrer" target="_blank" class="">https://github.com/llvm/llvm-project/commit/22caa3cfbcf5762a47acc40c425d9fe0c40da621</a><br class="">
DIFF: <a href="https://github.com/llvm/llvm-project/commit/22caa3cfbcf5762a47acc40c425d9fe0c40da621.diff" rel="noreferrer" target="_blank" class="">https://github.com/llvm/llvm-project/commit/22caa3cfbcf5762a47acc40c425d9fe0c40da621.diff</a><br class="">
<br class="">
LOG: [lldb] Add unit test for ClangASTImporter<br class="">
<br class="">
Added: <br class="">
    lldb/unittests/Symbol/TestClangASTImporter.cpp<br class="">
<br class="">
Modified: <br class="">
    lldb/unittests/Symbol/CMakeLists.txt<br class="">
<br class="">
Removed: <br class="">
<br class="">
<br class="">
<br class="">
################################################################################<br class="">
diff  --git a/lldb/unittests/Symbol/CMakeLists.txt b/lldb/unittests/Symbol/CMakeLists.txt<br class="">
index aa86986f4e0e..02875b8b53c1 100644<br class="">
--- a/lldb/unittests/Symbol/CMakeLists.txt<br class="">
+++ b/lldb/unittests/Symbol/CMakeLists.txt<br class="">
@@ -2,6 +2,7 @@ add_lldb_unittest(SymbolTests<br class="">
   LocateSymbolFileTest.cpp<br class="">
   PostfixExpressionTest.cpp<br class="">
   TestClangASTContext.cpp<br class="">
+  TestClangASTImporter.cpp<br class="">
   TestDWARFCallFrameInfo.cpp<br class="">
   TestType.cpp<br class="">
   TestLineEntry.cpp<br class="">
<br class="">
diff  --git a/lldb/unittests/Symbol/TestClangASTImporter.cpp b/lldb/unittests/Symbol/TestClangASTImporter.cpp<br class="">
new file mode 100644<br class="">
index 000000000000..17a0dfb6a348<br class="">
--- /dev/null<br class="">
+++ b/lldb/unittests/Symbol/TestClangASTImporter.cpp<br class="">
@@ -0,0 +1,220 @@<br class="">
+//===-- TestClangASTImporter.cpp --------------------------------*- C++ -*-===//<br class="">
+//<br class="">
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.<br class="">
+// See <a href="https://llvm.org/LICENSE.txt" rel="noreferrer" target="_blank" class="">https://llvm.org/LICENSE.txt</a> for license information.<br class="">
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception<br class="">
+//<br class="">
+//===----------------------------------------------------------------------===//<br class="">
+<br class="">
+#include "gtest/gtest.h"<br class="">
+<br class="">
+#include "lldb/Host/FileSystem.h"<br class="">
+#include "lldb/Host/HostInfo.h"<br class="">
+#include "lldb/Symbol/ClangASTContext.h"<br class="">
+#include "lldb/Symbol/ClangASTImporter.h"<br class="">
+#include "lldb/Symbol/ClangASTMetadata.h"<br class="">
+#include "lldb/Symbol/ClangUtil.h"<br class="">
+#include "lldb/Symbol/Declaration.h"<br class="">
+#include "clang/AST/DeclCXX.h"<br class="">
+<br class="">
+using namespace clang;<br class="">
+using namespace lldb;<br class="">
+using namespace lldb_private;<br class="">
+<br class="">
+class TestClangASTImporter : public testing::Test {<br class="">
+public:<br class="">
+  static void SetUpTestCase() {<br class="">
+    FileSystem::Initialize();<br class="">
+    HostInfo::Initialize();<br class="">
+  }<br class="">
+<br class="">
+  static void TearDownTestCase() {<br class="">
+    HostInfo::Terminate();<br class="">
+    FileSystem::Terminate();<br class="">
+  }<br class="">
+<br class="">
+protected:<br class="">
+  std::unique_ptr<ClangASTContext> createAST() {<br class="">
+    return std::make_unique<ClangASTContext>(HostInfo::GetTargetTriple());<br class="">
+  }<br class="">
+<br class="">
+  CompilerType createRecord(ClangASTContext &ast, const char *name) {<br class="">
+    return ast.CreateRecordType(ast.getASTContext()->getTranslationUnitDecl(),<br class="">
+                                lldb::AccessType::eAccessPublic, name, 0,<br class="">
+                                lldb::LanguageType::eLanguageTypeC);<br class="">
+  }<br class="">
+};<br class="">
+<br class="">
+TEST_F(TestClangASTImporter, CanImportInvalidType) {<br class="">
+  ClangASTImporter importer;<br class="">
+  EXPECT_FALSE(importer.CanImport(CompilerType()));<br class="">
+}<br class="">
+<br class="">
+TEST_F(TestClangASTImporter, ImportInvalidType) {<br class="">
+  ClangASTImporter importer;<br class="">
+  EXPECT_FALSE(importer.Import(CompilerType()));<br class="">
+}<br class="">
+<br class="">
+TEST_F(TestClangASTImporter, CopyDeclTagDecl) {<br class="">
+  // Tests that the ClangASTImporter::CopyDecl can copy TagDecls.<br class="">
+  std::unique_ptr<ClangASTContext> source_ast = createAST();<br class="">
+  CompilerType source_type = createRecord(*source_ast, "Source");<br class="">
+  clang::TagDecl *source = ClangUtil::GetAsTagDecl(source_type);<br class="">
+<br class="">
+  std::unique_ptr<ClangASTContext> target_ast = createAST();<br class="">
+<br class="">
+  ClangASTImporter importer;<br class="">
+  clang::Decl *imported = importer.CopyDecl(<br class="">
+      target_ast->getASTContext(), source_ast->getASTContext(), source);<br class="">
+  ASSERT_NE(nullptr, imported);<br class="">
+<br class="">
+  // Check that we got the correct decl by just comparing their qualified name.<br class="">
+  clang::TagDecl *imported_tag_decl = llvm::cast<clang::TagDecl>(imported);<br class="">
+  EXPECT_EQ(source->getQualifiedNameAsString(),<br class="">
+            imported_tag_decl->getQualifiedNameAsString());<br class="">
+<br class="">
+  // Check that origin was set for the imported declaration.<br class="">
+  ClangASTImporter::DeclOrigin origin = importer.GetDeclOrigin(imported);<br class="">
+  EXPECT_TRUE(origin.Valid());<br class="">
+  EXPECT_EQ(origin.ctx, source_ast->getASTContext());<br class="">
+  EXPECT_EQ(origin.decl, source);<br class="">
+}<br class="">
+<br class="">
+TEST_F(TestClangASTImporter, CopyTypeTagDecl) {<br class="">
+  // Tests that the ClangASTImporter::CopyType can copy TagDecls types.<br class="">
+  std::unique_ptr<ClangASTContext> source_ast = createAST();<br class="">
+  CompilerType source_type = createRecord(*source_ast, "Source");<br class="">
+  clang::TagDecl *source = ClangUtil::GetAsTagDecl(source_type);<br class="">
+<br class="">
+  std::unique_ptr<ClangASTContext> target_ast = createAST();<br class="">
+<br class="">
+  ClangASTImporter importer;<br class="">
+  CompilerType imported = importer.CopyType(*target_ast, source_type);<br class="">
+  ASSERT_TRUE(imported.IsValid());<br class="">
+<br class="">
+  // Check that we got the correct decl by just comparing their qualified name.<br class="">
+  clang::TagDecl *imported_tag_decl = ClangUtil::GetAsTagDecl(imported);<br class="">
+  EXPECT_EQ(source->getQualifiedNameAsString(),<br class="">
+            imported_tag_decl->getQualifiedNameAsString());<br class="">
+<br class="">
+  // Check that origin was set for the imported declaration.<br class="">
+  ClangASTImporter::DeclOrigin origin =<br class="">
+      importer.GetDeclOrigin(imported_tag_decl);<br class="">
+  EXPECT_TRUE(origin.Valid());<br class="">
+  EXPECT_EQ(origin.ctx, source_ast->getASTContext());<br class="">
+  EXPECT_EQ(origin.decl, source);<br class="">
+}<br class="">
+<br class="">
+TEST_F(TestClangASTImporter, MetadataPropagation) {<br class="">
+  // Tests that AST metadata is propagated when copying declarations.<br class="">
+<br class="">
+  std::unique_ptr<ClangASTContext> source_ast = createAST();<br class="">
+  CompilerType source_type = createRecord(*source_ast, "Source");<br class="">
+  clang::TagDecl *source = ClangUtil::GetAsTagDecl(source_type);<br class="">
+  const lldb::user_id_t metadata = 123456;<br class="">
+  source_ast->SetMetadataAsUserID(source, metadata);<br class="">
+<br class="">
+  std::unique_ptr<ClangASTContext> target_ast = createAST();<br class="">
+<br class="">
+  ClangASTImporter importer;<br class="">
+  clang::Decl *imported = importer.CopyDecl(<br class="">
+      target_ast->getASTContext(), source_ast->getASTContext(), source);<br class="">
+  ASSERT_NE(nullptr, imported);<br class="">
+<br class="">
+  // Check that we got the same Metadata.<br class="">
+  ASSERT_NE(nullptr, importer.GetDeclMetadata(imported));<br class="">
+  EXPECT_EQ(metadata, importer.GetDeclMetadata(imported)->GetUserID());<br class="">
+}<br class="">
+<br class="">
+TEST_F(TestClangASTImporter, MetadataPropagationIndirectImport) {<br class="">
+  // Tests that AST metadata is propagated when copying declarations when<br class="">
+  // importing one declaration into a temporary context and then to the<br class="">
+  // actual destination context.<br class="">
+<br class="">
+  std::unique_ptr<ClangASTContext> source_ast = createAST();<br class="">
+  CompilerType source_type = createRecord(*source_ast, "Source");<br class="">
+  clang::TagDecl *source = ClangUtil::GetAsTagDecl(source_type);<br class="">
+  const lldb::user_id_t metadata = 123456;<br class="">
+  source_ast->SetMetadataAsUserID(source, metadata);<br class="">
+<br class="">
+  std::unique_ptr<ClangASTContext> temporary_ast = createAST();<br class="">
+<br class="">
+  ClangASTImporter importer;<br class="">
+  clang::Decl *temporary_imported = importer.CopyDecl(<br class="">
+      temporary_ast->getASTContext(), source_ast->getASTContext(), source);<br class="">
+  ASSERT_NE(nullptr, temporary_imported);<br class="">
+<br class="">
+  std::unique_ptr<ClangASTContext> target_ast = createAST();<br class="">
+  clang::Decl *imported =<br class="">
+      importer.CopyDecl(target_ast->getASTContext(),<br class="">
+                        temporary_ast->getASTContext(), temporary_imported);<br class="">
+  ASSERT_NE(nullptr, imported);<br class="">
+<br class="">
+  // Check that we got the same Metadata.<br class="">
+  ASSERT_NE(nullptr, importer.GetDeclMetadata(imported));<br class="">
+  EXPECT_EQ(metadata, importer.GetDeclMetadata(imported)->GetUserID());<br class="">
+}<br class="">
+<br class="">
+TEST_F(TestClangASTImporter, MetadataPropagationAfterCopying) {<br class="">
+  // Tests that AST metadata is propagated when copying declarations even<br class="">
+  // when the metadata was set after the declaration has already been copied.<br class="">
+<br class="">
+  std::unique_ptr<ClangASTContext> source_ast = createAST();<br class="">
+  CompilerType source_type = createRecord(*source_ast, "Source");<br class="">
+  clang::TagDecl *source = ClangUtil::GetAsTagDecl(source_type);<br class="">
+  const lldb::user_id_t metadata = 123456;<br class="">
+<br class="">
+  std::unique_ptr<ClangASTContext> target_ast = createAST();<br class="">
+<br class="">
+  ClangASTImporter importer;<br class="">
+  clang::Decl *imported = importer.CopyDecl(<br class="">
+      target_ast->getASTContext(), source_ast->getASTContext(), source);<br class="">
+  ASSERT_NE(nullptr, imported);<br class="">
+<br class="">
+  // The TagDecl has been imported. Now set the metadata of the source and<br class="">
+  // make sure the imported one will directly see it.<br class="">
+  source_ast->SetMetadataAsUserID(source, metadata);<br class="">
+<br class="">
+  // Check that we got the same Metadata.<br class="">
+  ASSERT_NE(nullptr, importer.GetDeclMetadata(imported));<br class="">
+  EXPECT_EQ(metadata, importer.GetDeclMetadata(imported)->GetUserID());<br class="">
+}<br class="">
+<br class="">
+TEST_F(TestClangASTImporter, RecordLayout) {<br class="">
+  // Test that it is possible to register RecordDecl layouts and then later<br class="">
+  // correctly retrieve them.<br class="">
+<br class="">
+  std::unique_ptr<ClangASTContext> source_ast = createAST();<br class="">
+  CompilerType source_type = createRecord(*source_ast, "Source");<br class="">
+  ClangASTContext::StartTagDeclarationDefinition(source_type);<br class="">
+  clang::FieldDecl *field = source_ast->AddFieldToRecordType(<br class="">
+      source_type, "a_field",<br class="">
+      source_ast->GetBasicType(lldb::BasicType::eBasicTypeChar),<br class="">
+      lldb::AccessType::eAccessPublic, 7);<br class="">
+  ClangASTContext::CompleteTagDeclarationDefinition(source_type);<br class="">
+<br class="">
+  clang::TagDecl *source_tag = ClangUtil::GetAsTagDecl(source_type);<br class="">
+  clang::RecordDecl *source_record = llvm::cast<clang::RecordDecl>(source_tag);<br class="">
+<br class="">
+  ClangASTImporter importer;<br class="">
+  ClangASTImporter::LayoutInfo layout_info;<br class="">
+  layout_info.bit_size = 15;<br class="">
+  layout_info.alignment = 2;<br class="">
+  layout_info.field_offsets[field] = 1;<br class="">
+  importer.InsertRecordDecl(source_record, layout_info);<br class="">
+<br class="">
+  uint64_t bit_size;<br class="">
+  uint64_t alignment;<br class="">
+  llvm::DenseMap<const clang::FieldDecl *, uint64_t> field_offsets;<br class="">
+  llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> base_offsets;<br class="">
+  llvm::DenseMap<const clang::CXXRecordDecl *, clang::CharUnits> vbase_offsets;<br class="">
+  importer.LayoutRecordType(source_record, bit_size, alignment, field_offsets,<br class="">
+                            base_offsets, vbase_offsets);<br class="">
+<br class="">
+  EXPECT_EQ(15U, bit_size);<br class="">
+  EXPECT_EQ(2U, alignment);<br class="">
+  EXPECT_EQ(1U, field_offsets.size());<br class="">
+  EXPECT_EQ(1U, field_offsets[field]);<br class="">
+  EXPECT_EQ(0U, base_offsets.size());<br class="">
+  EXPECT_EQ(0U, vbase_offsets.size());<br class="">
+}<br class="">
<br class="">
<br class="">
<br class="">
_______________________________________________<br class="">
lldb-commits mailing list<br class="">
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank" class="">lldb-commits@lists.llvm.org</a><br class="">
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank" class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></body></html>