This is an archive of the discontinued LLVM Phabricator instance.

[clang][AST] Add support for ShuffleVectorExpr to ASTImporter
ClosedPublic

Authored by steakhal on Sep 20 2021, 1:23 AM.

Diff Detail

Event Timeline

steakhal created this revision.Sep 20 2021, 1:23 AM
steakhal requested review of this revision.Sep 20 2021, 1:23 AM
steakhal edited the summary of this revision. (Show Details)
shafik accepted this revision.Sep 20 2021, 9:52 AM

LGTM

This revision is now accepted and ready to land.Sep 20 2021, 9:52 AM
shafik added inline comments.Sep 20 2021, 9:55 AM
clang/unittests/AST/ASTImporterTest.cpp
304

Can we get at the SubExprs and verify them as well?

steakhal planned changes to this revision.Sep 20 2021, 10:10 AM
steakhal added inline comments.
clang/unittests/AST/ASTImporterTest.cpp
304

Sure!

What's the policy on this? I can see test, just like ImportChooseExpr that simply checks for the existence of the node.
Presumably we simply raised the bar for such tests by the time.
In the future I won't copy-paste one already existing one :D

martong added inline comments.Sep 21 2021, 2:33 AM
clang/unittests/AST/ASTImporterTest.cpp
304

The best if we can check as much constituent of the AST node as possible in the test. Historically, testImport is among the first testing facilities. Later, we developed ASTImporterTestBase::Import that provides you the imported decl and from that point you can formulate any kind of expectations on that decl. I'd like to advise you to not use testImport unless the node is trivial.

Here is a good and simple example for Import:

TEST_P(ASTImporterOptionSpecificTestBase, ImportEnumMemberSpecialization) {
  Decl *FromTU = getTuDecl(
      R"(
      template <class T> struct A {
        enum tagname { enumerator };
      };
      template struct A<int>;
      )",
      Lang_CXX03);
  auto *FromD = FirstDeclMatcher<EnumDecl>().match(
      FromTU, enumDecl(hasName("tagname"),
                       hasParent(classTemplateSpecializationDecl())));
  ASSERT_TRUE(FromD);
  ASSERT_TRUE(FromD->getMemberSpecializationInfo());

  auto *ToD = Import(FromD, Lang_CXX03);
  EXPECT_TRUE(ToD);
  EXPECT_TRUE(ToD->getMemberSpecializationInfo());
  EXPECT_EQ(FromD->getTemplateSpecializationKind(),
            ToD->getTemplateSpecializationKind());
}
martong added inline comments.Sep 21 2021, 2:40 AM
clang/unittests/AST/ASTImporterTest.cpp
304

Uhh, ohh, I see that Import is implemented for Decls only, perhaps we should have something similar to Stmts as well ...

teemperor added inline comments.Sep 21 2021, 3:26 AM
clang/unittests/AST/ASTImporterTest.cpp
304

Uhh, ohh, I see that Import is implemented for Decls only, perhaps we should have something similar to Stmts as well ...

I don't think Stmt's have a reference to their containing function so I don't think that can be implemented?

steakhal updated this revision to Diff 373836.Sep 21 2021, 3:31 AM
steakhal marked 2 inline comments as done.

Use a more elaborate matcher to verify subexpressions.
Also fix a bug: reserve() -> resize() on the destination vector.

This revision is now accepted and ready to land.Sep 21 2021, 3:31 AM

This patch breaks no lldb tests.

This patch breaks no lldb tests.

I don't think there is a great (or any) benefit for running tests on patches like this so don't feel obligated to run the tests. LLDB doesn't construct Stmts from debug info, so the only way we could even encounter most of these specialized Stmts in LLDB is if 1. we have a dedicated test for it (which is easy to grep for but as there are no similar tests I doubt you'll find results for that) 2. They show up in a system header which LLDB parses during runtime. All the tests that do this on Linux are in the import-std-module directory so you could just run that if you really want to run the tests before. But as those are system headers you would anyway also rely on the bots to discover different versions of system headers.

I would just grep for the class/source representation in the LLDB directory and if they aren't explicitly referenced in a test/source then I would just leave it up to the bots to run the tests.

This patch breaks no lldb tests.

I don't think there is a great (or any) benefit for running tests on patches like this so don't feel obligated to run the tests. LLDB doesn't construct Stmts from debug info, so the only way we could even encounter most of these specialized Stmts in LLDB is if 1. we have a dedicated test for it (which is easy to grep for but as there are no similar tests I doubt you'll find results for that) 2. They show up in a system header which LLDB parses during runtime. All the tests that do this on Linux are in the import-std-module directory so you could just run that if you really want to run the tests before. But as those are system headers you would anyway also rely on the bots to discover different versions of system headers.

I would just grep for the class/source representation in the LLDB directory and if they aren't explicitly referenced in a test/source then I would just leave it up to the bots to run the tests.

Okay, that seems reasonable. Thanks.

Do you think it's good enough to land? @all

This patch breaks no lldb tests.

I don't think there is a great (or any) benefit for running tests on patches like this so don't feel obligated to run the tests. LLDB doesn't construct Stmts from debug info, so the only way we could even encounter most of these specialized Stmts in LLDB is if 1. we have a dedicated test for it (which is easy to grep for but as there are no similar tests I doubt you'll find results for that) 2. They show up in a system header which LLDB parses during runtime. All the tests that do this on Linux are in the import-std-module directory so you could just run that if you really want to run the tests before. But as those are system headers you would anyway also rely on the bots to discover different versions of system headers.

I would just grep for the class/source representation in the LLDB directory and if they aren't explicitly referenced in a test/source then I would just leave it up to the bots to run the tests.

Okay, that seems reasonable. Thanks.

Do you think it's good enough to land? @all

Looks good! Thanks!

clang/unittests/AST/ASTImporterTest.cpp
304

I don't think Stmt's have a reference to their containing function

That's right, but I think we could implement a convenience function in the ASTImporterTestBase that can return the imported Stmt*, i.e. Stmt* ASTImporterTestBase::Import(Stmt*). And once we have that then we can check all the needed properties and we don't have to formulate complex matchers.

martong accepted this revision.Sep 21 2021, 4:39 AM
teemperor added inline comments.Sep 21 2021, 7:19 AM
clang/unittests/AST/ASTImporterTest.cpp
304

I probably should have phrased 'can't be implemented' as 'can't be implemented nicely'.

My point was more that the Import(Stmt *) implementation would either

  1. randomly (depending on whether any Stmt references the surrounding Function) produce free-floating Stmts without the containing function which seems weird
  2. or has to traverse the AST *again* to find the containing FunctionDecl/etc. which seems kinda inefficient.
This revision was landed with ongoing or failed builds.Sep 27 2021, 1:17 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2021, 1:17 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript