[PATCH] D99576: [ASTImporter][NFC] Improve test coverage
Balázs Benics via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 30 03:34:16 PDT 2021
steakhal created this revision.
steakhal added reviewers: martong, teemperor, shafik, balazske, a.sidorin.
Herald added subscribers: whisperity, rnkovacs, kristof.beyls.
steakhal requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
All three cases were imported //correctly//.
For BlockDecls, //correctly// means that we don't support importing them, thus an error is the expected behaviour.
- BlockDecls were not yet covered. I know that they are not imported but the test at least documents it.
- Default values for ParmVarDecls were also uncovered.
- Importing bitfield FieldDecls were imported correctly.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D99576
Files:
clang/unittests/AST/ASTImporterTest.cpp
Index: clang/unittests/AST/ASTImporterTest.cpp
===================================================================
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -3064,6 +3064,65 @@
EXPECT_EQ(ToF1, ToF2);
}
+TEST_P(ASTImporterOptionSpecificTestBase, ImportBitfields) {
+ Decl *FromTU = getTuDecl("struct A { unsigned x : 3; };", Lang_CXX03);
+ auto *FromF =
+ FirstDeclMatcher<FieldDecl>().match(FromTU, fieldDecl(hasName("x")));
+
+ ASSERT_TRUE(FromF->isBitField());
+ ASSERT_EQ(3u, FromF->getBitWidthValue(FromTU->getASTContext()));
+ auto *ToField = Import(FromF, Lang_CXX03);
+ auto *ToTU = ToField->getTranslationUnitDecl();
+
+ EXPECT_TRUE(ToField->isBitField());
+ EXPECT_EQ(3u, ToField->getBitWidthValue(ToTU->getASTContext()));
+}
+
+struct ImportBlock : ASTImporterOptionSpecificTestBase {};
+const internal::VariadicDynCastAllOfMatcher<Decl, BlockDecl> blockDecl;
+TEST_P(ImportBlock, ImportBlocksAreUnsupported) {
+ const auto *Code = R"(
+ void test_block__capture_null() {
+ int *p = 0;
+ ^(){
+ *p = 1;
+ }();
+ })";
+ Decl *FromTU = getTuDecl(Code, Lang_CXX03);
+ auto *FromBlock = FirstDeclMatcher<BlockDecl>().match(FromTU, blockDecl());
+ ASSERT_TRUE(FromBlock);
+
+ auto ToBlockOrError = importOrError(FromBlock, Lang_CXX03);
+
+ const auto ExpectUnsupportedConstructError = [](const ImportError &Error) {
+ EXPECT_EQ(ImportError::UnsupportedConstruct, Error.Error);
+ };
+ llvm::handleAllErrors(ToBlockOrError.takeError(),
+ ExpectUnsupportedConstructError);
+}
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportParmVarDecl) {
+ const auto *Code = R"(
+ template <typename T> struct Wrapper {
+ Wrapper(T Value = {}) {}
+ };
+ template class Wrapper<int>;
+ )";
+ Decl *FromTU = getTuDecl(Code, Lang_CXX11);
+ auto *FromVar = FirstDeclMatcher<ParmVarDecl>().match(
+ FromTU, parmVarDecl(hasType(asString("int"))));
+ ASSERT_TRUE(FromVar);
+ ASSERT_TRUE(FromVar->hasUninstantiatedDefaultArg());
+ ASSERT_TRUE(FromVar->getUninstantiatedDefaultArg());
+
+ const auto *ToVar = Import(FromVar, Lang_CXX11);
+ EXPECT_TRUE(ToVar);
+ EXPECT_TRUE(ToVar->hasUninstantiatedDefaultArg());
+ EXPECT_TRUE(ToVar->getUninstantiatedDefaultArg());
+ EXPECT_NE(FromVar->getUninstantiatedDefaultArg(),
+ ToVar->getUninstantiatedDefaultArg());
+}
+
TEST_P(ASTImporterOptionSpecificTestBase, ImportOfNonEquivalentField) {
Decl *ToF1;
{
@@ -6250,6 +6309,11 @@
std::vector<std::string>{
"-ffixed-point"}), );
+INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportBlock,
+ ExtendWithOptions(DefaultTestArrayForRunOptions,
+ std::vector<std::string>{
+ "-fblocks"}), );
+
INSTANTIATE_TEST_CASE_P(ParameterizedTests, ImportType,
DefaultTestValuesForRunOptions, );
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99576.334101.patch
Type: text/x-patch
Size: 3061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210330/34bfac33/attachment.bin>
More information about the cfe-commits
mailing list