[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky closed https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/balazske approved this pull request. https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
@@ -3220,6 +3220,12 @@ TEST_P(ImportExpr, UnresolvedMemberExpr) { compoundStmt(has(callExpr(has(unresolvedMemberExpr()); } +TEST_P(ImportExpr, BuiltinBitCastExpr) { + MatchVerifier Verifier; + testImport("void declToImport(int T) { (void)__builtin_bit_cast(float, T); }", + Lang_CXX20, "", Lang_CXX20, Verifier, functionDecl()); +} + jcsxky wrote: Oh, I see. The code has been fixed. https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74813 >From d1f48502c1ec7a58ca18a19dc3631265e5c1b137 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 8 Dec 2023 15:26:01 +0800 Subject: [PATCH] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr --- clang/lib/AST/ASTImporter.cpp | 12 clang/unittests/AST/ASTImporterTest.cpp | 12 2 files changed, 24 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..0edb6930ed0a00 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc()); +if (!ToKWLocOrErr) + return ToKWLocOrErr.takeError(); +ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc()); +if (!ToRParenLocOrErr) + return ToRParenLocOrErr.takeError(); +return new (Importer.getToContext()) BuiltinBitCastExpr( +ToType, E->getValueKind(), E->getCastKind(), ToSubExpr, +ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr); + } default: llvm_unreachable("Cast expression of unsupported type!"); return make_error(ASTImportError::UnsupportedConstruct); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..0941417bd3cfb4 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -561,6 +561,18 @@ TEST_P(ImportExpr, ImportVAArgExpr) { cStyleCastExpr(hasSourceExpression(vaArgExpr()); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ImportExpr, ImportBuiltinBitCastExpr) { + MatchVerifier Verifier; + testImport("void declToImport(int X) {" + " (void)__builtin_bit_cast(float, X); }", + Lang_CXX20, "", Lang_CXX20, Verifier, + functionDecl(hasDescendant( + cStyleCastExpr(hasSourceExpression(builtinBitCastExpr()); +} + TEST_P(ImportExpr, CXXTemporaryObjectExpr) { MatchVerifier Verifier; testImport( ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
@@ -3220,6 +3220,12 @@ TEST_P(ImportExpr, UnresolvedMemberExpr) { compoundStmt(has(callExpr(has(unresolvedMemberExpr()); } +TEST_P(ImportExpr, BuiltinBitCastExpr) { + MatchVerifier Verifier; + testImport("void declToImport(int T) { (void)__builtin_bit_cast(float, T); }", + Lang_CXX20, "", Lang_CXX20, Verifier, functionDecl()); +} + balazske wrote: I did mean to add this test (and the AST matcher) (after test for `ImportVAArgExpr` near line 563), and the other is not needed: ``` TEST_P(ImportExpr, ImportBuiltinBitCastExpr) { MatchVerifier Verifier; testImport("void declToImport(int X) {" " (void)__builtin_bit_cast(float, X); }", Lang_CXX20, "", Lang_CXX20, Verifier, functionDecl(hasDescendant( cStyleCastExpr(hasSourceExpression(builtinBitCastExpr()); } ``` https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
@@ -9284,6 +9284,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} jcsxky wrote: Another testcase has been added to `ImportExpr` https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74813 >From 4e2ac40eece61343b5947ae906e5a4be8a82c823 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 8 Dec 2023 15:26:01 +0800 Subject: [PATCH] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr --- clang/lib/AST/ASTImporter.cpp | 12 clang/unittests/AST/ASTImporterTest.cpp | 24 2 files changed, 36 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..0edb6930ed0a00 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc()); +if (!ToKWLocOrErr) + return ToKWLocOrErr.takeError(); +ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc()); +if (!ToRParenLocOrErr) + return ToRParenLocOrErr.takeError(); +return new (Importer.getToContext()) BuiltinBitCastExpr( +ToType, E->getValueKind(), E->getCastKind(), ToSubExpr, +ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr); + } default: llvm_unreachable("Cast expression of unsupported type!"); return make_error(ASTImportError::UnsupportedConstruct); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..82174ddc07de22 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -3220,6 +3220,12 @@ TEST_P(ImportExpr, UnresolvedMemberExpr) { compoundStmt(has(callExpr(has(unresolvedMemberExpr()); } +TEST_P(ImportExpr, BuiltinBitCastExpr) { + MatchVerifier Verifier; + testImport("void declToImport(int T) { (void)__builtin_bit_cast(float, T); }", + Lang_CXX20, "", Lang_CXX20, Verifier, functionDecl()); +} + class ImportImplicitMethods : public ASTImporterOptionSpecificTestBase { public: static constexpr auto DefaultCode = R"( @@ -9284,6 +9290,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
@@ -9284,6 +9284,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} balazske wrote: Instead of this test a more simple test can be added in the `ImportExpr` section of **ASTImporterTest.cpp**. https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
@@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToLParenLocOrErr = import(BBC->getBeginLoc()); jcsxky wrote: Fixed according to your suggestion and description has been updated. https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74813 >From 53e0a0bb8061e5fbd49c58b30bc1217cbb669352 Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 8 Dec 2023 15:26:01 +0800 Subject: [PATCH] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr --- clang/lib/AST/ASTImporter.cpp | 12 clang/unittests/AST/ASTImporterTest.cpp | 18 ++ 2 files changed, 30 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a..0edb6930ed0a0 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToKWLocOrErr = import(BBC->getBeginLoc()); +if (!ToKWLocOrErr) + return ToKWLocOrErr.takeError(); +ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc()); +if (!ToRParenLocOrErr) + return ToRParenLocOrErr.takeError(); +return new (Importer.getToContext()) BuiltinBitCastExpr( +ToType, E->getValueKind(), E->getCastKind(), ToSubExpr, +ToTypeInfoAsWritten, *ToKWLocOrErr, *ToRParenLocOrErr); + } default: llvm_unreachable("Cast expression of unsupported type!"); return make_error(ASTImportError::UnsupportedConstruct); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf..27137c5b8ad06 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky edited https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
@@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToLParenLocOrErr = import(BBC->getBeginLoc()); shafik wrote: So it looks like this returns `KWLoc` so perhaps `ToKwLocOrErr` makes more sense? https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
shafik wrote: Can you please update the description to explain the problem in more details and why these changes fixes the problem. The description is what ends up in the git log and it is important that those logs provide enough information to understand the changes without having to view the details. https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky updated https://github.com/llvm/llvm-project/pull/74813 >From 0cab02331a5f1eb85649ab381d73ddb71d354b5b Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 8 Dec 2023 15:26:01 +0800 Subject: [PATCH] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr --- clang/lib/AST/ASTImporter.cpp | 12 clang/unittests/AST/ASTImporterTest.cpp | 18 ++ 2 files changed, 30 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a4..79ca48bf9ec0f9 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToLParenLocOrErr = import(BBC->getBeginLoc()); +if (!ToLParenLocOrErr) + return ToLParenLocOrErr.takeError(); +ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc()); +if (!ToRParenLocOrErr) + return ToRParenLocOrErr.takeError(); +return new (Importer.getToContext()) BuiltinBitCastExpr( +ToType, E->getValueKind(), E->getCastKind(), ToSubExpr, +ToTypeInfoAsWritten, *ToLParenLocOrErr, *ToRParenLocOrErr); + } default: llvm_unreachable("Cast expression of unsupported type!"); return make_error(ASTImportError::UnsupportedConstruct); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf8..27137c5b8ad06a 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9284,6 +9284,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Qizhi Hu (jcsxky) Changes This patch aims to fix the [crash](https://github.com/llvm/llvm-project/issues/74774) --- Full diff: https://github.com/llvm/llvm-project/pull/74813.diff 2 Files Affected: - (modified) clang/lib/AST/ASTImporter.cpp (+12) - (modified) clang/unittests/AST/ASTImporterTest.cpp (+20) ``diff diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a..79ca48bf9ec0f 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToLParenLocOrErr = import(BBC->getBeginLoc()); +if (!ToLParenLocOrErr) + return ToLParenLocOrErr.takeError(); +ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc()); +if (!ToRParenLocOrErr) + return ToRParenLocOrErr.takeError(); +return new (Importer.getToContext()) BuiltinBitCastExpr( +ToType, E->getValueKind(), E->getCastKind(), ToSubExpr, +ToTypeInfoAsWritten, *ToLParenLocOrErr, *ToRParenLocOrErr); + } default: llvm_unreachable("Cast expression of unsupported type!"); return make_error(ASTImportError::UnsupportedConstruct); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf..3d9c426e13895 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -10,6 +10,7 @@ // //===--===// +#include "clang/AST/ASTFwd.h" #include "clang/AST/RecordLayout.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Testing/CommandLineArgs.h" @@ -19,6 +20,7 @@ #include "gtest/gtest.h" #include "ASTImporterFixtures.h" +#include "DeclMatcher.h" #include namespace clang { @@ -9284,6 +9286,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); `` https://github.com/llvm/llvm-project/pull/74813 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (PR #74813)
https://github.com/jcsxky created https://github.com/llvm/llvm-project/pull/74813 This patch aims to fix the [crash](https://github.com/llvm/llvm-project/issues/74774) >From 49ec0838ecef753d86562ce4c12b3d84000a859e Mon Sep 17 00:00:00 2001 From: huqizhi Date: Fri, 8 Dec 2023 15:26:01 +0800 Subject: [PATCH] [clang][ASTImporter] Support Importer of BuiltinBitCastExpr --- clang/lib/AST/ASTImporter.cpp | 12 clang/unittests/AST/ASTImporterTest.cpp | 20 2 files changed, 32 insertions(+) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index f1f335118f37a..79ca48bf9ec0f 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -7820,6 +7820,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) { *ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(), *ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr); } + case Stmt::BuiltinBitCastExprClass: { +auto *BBC = cast(E); +ExpectedSLoc ToLParenLocOrErr = import(BBC->getBeginLoc()); +if (!ToLParenLocOrErr) + return ToLParenLocOrErr.takeError(); +ExpectedSLoc ToRParenLocOrErr = import(BBC->getEndLoc()); +if (!ToRParenLocOrErr) + return ToRParenLocOrErr.takeError(); +return new (Importer.getToContext()) BuiltinBitCastExpr( +ToType, E->getValueKind(), E->getCastKind(), ToSubExpr, +ToTypeInfoAsWritten, *ToLParenLocOrErr, *ToRParenLocOrErr); + } default: llvm_unreachable("Cast expression of unsupported type!"); return make_error(ASTImportError::UnsupportedConstruct); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 4dd7510bf8ddf..3d9c426e13895 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -10,6 +10,7 @@ // //===--===// +#include "clang/AST/ASTFwd.h" #include "clang/AST/RecordLayout.h" #include "clang/ASTMatchers/ASTMatchers.h" #include "clang/Testing/CommandLineArgs.h" @@ -19,6 +20,7 @@ #include "gtest/gtest.h" #include "ASTImporterFixtures.h" +#include "DeclMatcher.h" #include namespace clang { @@ -9284,6 +9286,24 @@ TEST_P(ASTImporterOptionSpecificTestBase, // EXPECT_EQ(ToF1Imported->getPreviousDecl(), ToF1); } +const internal::VariadicDynCastAllOfMatcher +builtinBitCastExpr; + +TEST_P(ASTImporterOptionSpecificTestBase, ImportBuiltinBitCastExpr) { + const char *CodeFrom = + R"( + void foo(int T) { (void)__builtin_bit_cast(float, T); } + )"; + Decl *FromTU = getTuDecl(CodeFrom, Lang_CXX20); + auto *FromFoo = FirstDeclMatcher().match( + FromTU, functionDecl(hasName("foo"))); + auto *ToFoo = Import(FromFoo, Lang_CXX20); + EXPECT_TRUE(ToFoo); + auto *ToBuiltinBitCastExpr = + FirstDeclMatcher().match(ToFoo, builtinBitCastExpr()); + EXPECT_TRUE(ToBuiltinBitCastExpr); +} + INSTANTIATE_TEST_SUITE_P(ParameterizedTests, ASTImporterLookupTableTest, DefaultTestValuesForRunOptions); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits