[clang] 625197d - [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (#74813)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 22 02:07:03 PST 2023
Author: Qizhi Hu
Date: 2023-12-22T18:06:59+08:00
New Revision: 625197d39cf9d56a295f8e6ee2584c825b461db9
URL: https://github.com/llvm/llvm-project/commit/625197d39cf9d56a295f8e6ee2584c825b461db9
DIFF: https://github.com/llvm/llvm-project/commit/625197d39cf9d56a295f8e6ee2584c825b461db9.diff
LOG: [clang][ASTImporter] Support Importer of BuiltinBitCastExpr (#74813)
Since import `ExplicitCastExpr` lacks of processing
`BuiltinBitCastExprClass` type, it would reach to the 'unreachable' code
and produce the crash. This patch aims to fix the
[crash](https://github.com/llvm/llvm-project/issues/74774) and try to
handle `BuiltinBitCastExpr`.
Co-authored-by: huqizhi <836744285 at qq.com>
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 88b8c6abb6d5fd..949310856562cd 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -7826,6 +7826,18 @@ ExpectedStmt ASTNodeImporter::VisitExplicitCastExpr(ExplicitCastExpr *E) {
*ToLParenLocOrErr, OCE->getBridgeKind(), E->getCastKind(),
*ToBridgeKeywordLocOrErr, ToTypeInfoAsWritten, ToSubExpr);
}
+ case Stmt::BuiltinBitCastExprClass: {
+ auto *BBC = cast<BuiltinBitCastExpr>(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>(ASTImportError::UnsupportedConstruct);
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 9fa7660cde6593..6c7b2b64ca2d1d 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<Stmt, BuiltinBitCastExpr>
+ builtinBitCastExpr;
+
+TEST_P(ImportExpr, ImportBuiltinBitCastExpr) {
+ MatchVerifier<Decl> 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<Decl> Verifier;
testImport(
More information about the cfe-commits
mailing list