Author: Balázs Kéri Date: 2026-06-16T14:31:03+02:00 New Revision: e9cf47b69bd791c70ee15f23f71e0af4d2037ab2
URL: https://github.com/llvm/llvm-project/commit/e9cf47b69bd791c70ee15f23f71e0af4d2037ab2 DIFF: https://github.com/llvm/llvm-project/commit/e9cf47b69bd791c70ee15f23f71e0af4d2037ab2.diff LOG: [clang][ASTImporter] Add import of node 'FileScopeAsmDecl' (#193244) Added: Modified: clang/lib/AST/ASTImporter.cpp clang/unittests/AST/ASTImporterTest.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f5848d154f49e..567d2d07298a3 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -517,6 +517,7 @@ namespace clang { ExpectedDecl VisitAccessSpecDecl(AccessSpecDecl *D); ExpectedDecl VisitStaticAssertDecl(StaticAssertDecl *D); ExpectedDecl VisitTranslationUnitDecl(TranslationUnitDecl *D); + ExpectedDecl VisitFileScopeAsmDecl(FileScopeAsmDecl *D); ExpectedDecl VisitBindingDecl(BindingDecl *D); ExpectedDecl VisitNamespaceDecl(NamespaceDecl *D); ExpectedDecl VisitNamespaceAliasDecl(NamespaceAliasDecl *D); @@ -2787,6 +2788,30 @@ ExpectedDecl ASTNodeImporter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { return ToD; } +ExpectedDecl ASTNodeImporter::VisitFileScopeAsmDecl(FileScopeAsmDecl *D) { + Error Err = Error::success(); + Expr *ToAsmString = importChecked(Err, D->getAsmStringExpr()); + SourceLocation ToAsmLoc = importChecked(Err, D->getAsmLoc()); + SourceLocation ToRParenLoc = importChecked(Err, D->getRParenLoc()); + if (Err) + return std::move(Err); + + auto DCOrErr = Importer.ImportContext(D->getDeclContext()); + if (!DCOrErr) + return DCOrErr.takeError(); + DeclContext *DC = *DCOrErr; + + FileScopeAsmDecl *ToD; + if (GetImportedOrCreateDecl(ToD, D, Importer.getToContext(), DC, ToAsmString, + ToAsmLoc, ToRParenLoc)) + return ToD; + + ToD->setLexicalDeclContext(DC); + DC->addDeclInternal(ToD); + + return ToD; +} + ExpectedDecl ASTNodeImporter::VisitBindingDecl(BindingDecl *D) { DeclContext *DC, *LexicalDC; DeclarationName Name; diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 92085e30ace74..503f5da8af90f 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -1133,6 +1133,16 @@ TEST_P(ImportExpr, DependentSizedExtVectorType) { has(typedefDecl(hasType(dependentSizedExtVectorType()))))))); } +TEST_P(ASTImporterOptionSpecificTestBase, ImportFileScopeAsmDecl) { + Decl *FromTU = getTuDecl("__asm(\"nop\");", Lang_CXX03); + auto From = + FirstDeclMatcher<FileScopeAsmDecl>().match(FromTU, fileScopeAsmDecl()); + ASSERT_TRUE(From); + FileScopeAsmDecl *To = Import(From, Lang_CXX03); + EXPECT_TRUE(To); + EXPECT_EQ(To->getAsmString(), "nop"); +} + TEST_P(ASTImporterOptionSpecificTestBase, ImportUsingPackDecl) { Decl *FromTU = getTuDecl( "struct A { int operator()() { return 1; } };" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
