[clang] 4cb4db1 - Revert "[ASTImporter] Fix crash caused by unset AttributeSpellingListIndex"
Dave Lee via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 14 17:22:04 PDT 2020
Author: Dave Lee
Date: 2020-10-14T17:21:56-07:00
New Revision: 4cb4db11ee1323c5d4bf66d21deb046970f4e516
URL: https://github.com/llvm/llvm-project/commit/4cb4db11ee1323c5d4bf66d21deb046970f4e516
DIFF: https://github.com/llvm/llvm-project/commit/4cb4db11ee1323c5d4bf66d21deb046970f4e516.diff
LOG: Revert "[ASTImporter] Fix crash caused by unset AttributeSpellingListIndex"
This broke the GreenDragon build, due to the following error while running
TestImportBuiltinFileID:
```
Ignored/unknown shouldn't get here
UNREACHABLE executed at tools/clang/include/clang/Sema/AttrSpellingListIndex.inc:13!
```
See http://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/24213/
This reverts commit 73c6beb2f7053fe8b5150072c2b5cd930de38a22.
This reverts https://reviews.llvm.org/D89318
Added:
Modified:
clang/lib/AST/ASTImporter.cpp
clang/unittests/AST/ASTImporterTest.cpp
Removed:
clang/test/ASTMerge/attr/Inputs/RestrictAttr.cpp
clang/test/ASTMerge/attr/testRestrictAttr.cpp
################################################################################
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index a5c3a5eadb48..9efbcf757e99 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -8094,6 +8094,9 @@ Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) {
else
return ToTOrErr.takeError();
}
+ To->setInherited(From->isInherited());
+ To->setPackExpansion(From->isPackExpansion());
+ To->setImplicit(From->isImplicit());
ToAttr = To;
break;
}
@@ -8103,6 +8106,7 @@ Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) {
IdentifierInfo *ToAttrType = Import(From->getType());
To = FormatAttr::Create(ToContext, ToAttrType, From->getFormatIdx(),
From->getFirstArg(), ToRange, From->getSyntax());
+ To->setInherited(From->isInherited());
ToAttr = To;
break;
}
@@ -8113,15 +8117,8 @@ Expected<Attr *> ASTImporter::Import(const Attr *FromAttr) {
ToAttr->setRange(ToRange);
break;
}
-
assert(ToAttr && "Attribute should be created.");
- if (const auto *InheritableFromAttr = dyn_cast<InheritableAttr>(FromAttr))
- cast<InheritableAttr>(ToAttr)->setInherited(
- InheritableFromAttr->isInherited());
- ToAttr->setAttributeSpellingListIndex(
- FromAttr->getAttributeSpellingListIndex());
- ToAttr->setPackExpansion(FromAttr->isPackExpansion());
- ToAttr->setImplicit(FromAttr->isImplicit());
+
return ToAttr;
}
diff --git a/clang/test/ASTMerge/attr/Inputs/RestrictAttr.cpp b/clang/test/ASTMerge/attr/Inputs/RestrictAttr.cpp
deleted file mode 100644
index 2055a23b7c3c..000000000000
--- a/clang/test/ASTMerge/attr/Inputs/RestrictAttr.cpp
+++ /dev/null
@@ -1 +0,0 @@
-void *foo(unsigned, unsigned) __attribute__((__malloc__));
diff --git a/clang/test/ASTMerge/attr/testRestrictAttr.cpp b/clang/test/ASTMerge/attr/testRestrictAttr.cpp
deleted file mode 100644
index 65903d8f66ca..000000000000
--- a/clang/test/ASTMerge/attr/testRestrictAttr.cpp
+++ /dev/null
@@ -1,2 +0,0 @@
-// RUN: %clang -x c++-header -o %t.a.ast %S/Inputs/RestrictAttr.cpp
-// RUN: %clang_cc1 -x c++ -ast-merge %t.a.ast /dev/null -ast-dump
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 209374dd7048..967dc035d11f 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -5767,35 +5767,11 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportExprOfAlignmentAttr) {
EXPECT_TRUE(ToA);
}
-TEST_P(ASTImporterOptionSpecificTestBase, ImportRestrictAttr) {
- Decl *FromTU = getTuDecl(
- R"(
- void *foo(unsigned, unsigned) __attribute__((__malloc__));
- )",
- Lang_CXX03, "input.cc");
- auto *FromD = FirstDeclMatcher<FunctionDecl>().match(
- FromTU, functionDecl(hasName("foo")));
- ASSERT_TRUE(FromD);
-
- auto *ToD = Import(FromD, Lang_CXX03);
- ASSERT_TRUE(ToD);
- ToD->dump(); // Should not crash!
-
- auto *FromAttr = FromD->getAttr<RestrictAttr>();
- auto *ToAttr = ToD->getAttr<RestrictAttr>();
- EXPECT_EQ(FromAttr->isInherited(), ToAttr->isInherited());
- EXPECT_EQ(FromAttr->isPackExpansion(), ToAttr->isPackExpansion());
- EXPECT_EQ(FromAttr->isImplicit(), ToAttr->isImplicit());
- EXPECT_EQ(FromAttr->getSyntax(), ToAttr->getSyntax());
- EXPECT_EQ(FromAttr->getAttributeSpellingListIndex(),
- ToAttr->getAttributeSpellingListIndex());
-}
-
TEST_P(ASTImporterOptionSpecificTestBase, ImportFormatAttr) {
Decl *FromTU = getTuDecl(
R"(
int foo(const char * fmt, ...)
- __attribute__ ((__format__ (__scanf__, 1, 2)));
+ __attribute__ ((__format__ (__scanf__, 1, 2)));
)",
Lang_CXX03, "input.cc");
auto *FromD = FirstDeclMatcher<FunctionDecl>().match(
@@ -5816,7 +5792,6 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportFormatAttr) {
ToAttr->getAttributeSpellingListIndex());
EXPECT_EQ(FromAttr->getType()->getName(), ToAttr->getType()->getName());
}
-
template <typename T>
auto ExtendWithOptions(const T &Values, const std::vector<std::string> &Args) {
auto Copy = Values;
More information about the cfe-commits
mailing list