hyd-dev created this revision. hyd-dev added reviewers: erik.pilkington, rsmith. hyd-dev added a project: clang. Herald added subscribers: cfe-commits, dexonsmith. hyd-dev edited the summary of this revision. hyd-dev edited the summary of this revision.
D62825 <https://reviews.llvm.org/D62825> adds the new `BuiltinBitCastExpr`, but does not set the `Code` member of `ASTStmtWriter`. This is not correct and causes an assertion failue (`assert(Code != serialization::STMT_NULL_PTR && "unhandled sub-statement writing AST file")`) in `ASTStmtWriter::emit()` when building PCHs which contain `__builtin_bit_cast`. This patch adds `serialization::EXPR_BUILTIN_BIT_CAST` and handles `ASTStmtWriter::Code` properly. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D80360 Files: clang/include/clang/AST/ExprCXX.h clang/include/clang/Serialization/ASTBitCodes.h clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriterStmt.cpp clang/test/PCH/builtin-bit-cast.cpp Index: clang/test/PCH/builtin-bit-cast.cpp =================================================================== --- /dev/null +++ clang/test/PCH/builtin-bit-cast.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + +#ifndef HEADER +#define HEADER + +template<class T, class U> +constexpr T builtin_bit_cast_wrapper(const U& arg) { + return __builtin_bit_cast(T, arg); +} + +#else + +int main() { + builtin_bit_cast_wrapper<int>(0); + return 0; +} + +#endif Index: clang/lib/Serialization/ASTWriterStmt.cpp =================================================================== --- clang/lib/Serialization/ASTWriterStmt.cpp +++ clang/lib/Serialization/ASTWriterStmt.cpp @@ -1635,6 +1635,7 @@ VisitExplicitCastExpr(E); Record.AddSourceLocation(E->getBeginLoc()); Record.AddSourceLocation(E->getEndLoc()); + Code = serialization::EXPR_BUILTIN_BIT_CAST; } void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) { Index: clang/lib/Serialization/ASTReaderStmt.cpp =================================================================== --- clang/lib/Serialization/ASTReaderStmt.cpp +++ clang/lib/Serialization/ASTReaderStmt.cpp @@ -3593,6 +3593,11 @@ /*PathSize*/ Record[ASTStmtReader::NumExprFields]); break; + case EXPR_BUILTIN_BIT_CAST: + S = new (Context) BuiltinBitCastExpr( + Empty, /*PathSize*/ Record[ASTStmtReader::NumExprFields]); + break; + case EXPR_USER_DEFINED_LITERAL: S = UserDefinedLiteral::CreateEmpty( Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields], Empty); Index: clang/include/clang/Serialization/ASTBitCodes.h =================================================================== --- clang/include/clang/Serialization/ASTBitCodes.h +++ clang/include/clang/Serialization/ASTBitCodes.h @@ -1791,6 +1791,9 @@ /// A CXXFunctionalCastExpr record. EXPR_CXX_FUNCTIONAL_CAST, + /// A BuiltinBitCastExpr record. + EXPR_BUILTIN_BIT_CAST, + /// A UserDefinedLiteral record. EXPR_USER_DEFINED_LITERAL, Index: clang/include/clang/AST/ExprCXX.h =================================================================== --- clang/include/clang/AST/ExprCXX.h +++ clang/include/clang/AST/ExprCXX.h @@ -4785,6 +4785,8 @@ : ExplicitCastExpr(BuiltinBitCastExprClass, T, VK, CK, SrcExpr, 0, DstType), KWLoc(KWLoc), RParenLoc(RParenLoc) {} + BuiltinBitCastExpr(EmptyShell Empty, unsigned PathSize) + : ExplicitCastExpr(BuiltinBitCastExprClass, Empty, PathSize) {} SourceLocation getBeginLoc() const LLVM_READONLY { return KWLoc; } SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
Index: clang/test/PCH/builtin-bit-cast.cpp =================================================================== --- /dev/null +++ clang/test/PCH/builtin-bit-cast.cpp @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -emit-pch -o %t %s +// RUN: %clang_cc1 -include-pch %t -fsyntax-only -verify %s +// expected-no-diagnostics + +#ifndef HEADER +#define HEADER + +template<class T, class U> +constexpr T builtin_bit_cast_wrapper(const U& arg) { + return __builtin_bit_cast(T, arg); +} + +#else + +int main() { + builtin_bit_cast_wrapper<int>(0); + return 0; +} + +#endif Index: clang/lib/Serialization/ASTWriterStmt.cpp =================================================================== --- clang/lib/Serialization/ASTWriterStmt.cpp +++ clang/lib/Serialization/ASTWriterStmt.cpp @@ -1635,6 +1635,7 @@ VisitExplicitCastExpr(E); Record.AddSourceLocation(E->getBeginLoc()); Record.AddSourceLocation(E->getEndLoc()); + Code = serialization::EXPR_BUILTIN_BIT_CAST; } void ASTStmtWriter::VisitUserDefinedLiteral(UserDefinedLiteral *E) { Index: clang/lib/Serialization/ASTReaderStmt.cpp =================================================================== --- clang/lib/Serialization/ASTReaderStmt.cpp +++ clang/lib/Serialization/ASTReaderStmt.cpp @@ -3593,6 +3593,11 @@ /*PathSize*/ Record[ASTStmtReader::NumExprFields]); break; + case EXPR_BUILTIN_BIT_CAST: + S = new (Context) BuiltinBitCastExpr( + Empty, /*PathSize*/ Record[ASTStmtReader::NumExprFields]); + break; + case EXPR_USER_DEFINED_LITERAL: S = UserDefinedLiteral::CreateEmpty( Context, /*NumArgs=*/Record[ASTStmtReader::NumExprFields], Empty); Index: clang/include/clang/Serialization/ASTBitCodes.h =================================================================== --- clang/include/clang/Serialization/ASTBitCodes.h +++ clang/include/clang/Serialization/ASTBitCodes.h @@ -1791,6 +1791,9 @@ /// A CXXFunctionalCastExpr record. EXPR_CXX_FUNCTIONAL_CAST, + /// A BuiltinBitCastExpr record. + EXPR_BUILTIN_BIT_CAST, + /// A UserDefinedLiteral record. EXPR_USER_DEFINED_LITERAL, Index: clang/include/clang/AST/ExprCXX.h =================================================================== --- clang/include/clang/AST/ExprCXX.h +++ clang/include/clang/AST/ExprCXX.h @@ -4785,6 +4785,8 @@ : ExplicitCastExpr(BuiltinBitCastExprClass, T, VK, CK, SrcExpr, 0, DstType), KWLoc(KWLoc), RParenLoc(RParenLoc) {} + BuiltinBitCastExpr(EmptyShell Empty, unsigned PathSize) + : ExplicitCastExpr(BuiltinBitCastExprClass, Empty, PathSize) {} SourceLocation getBeginLoc() const LLVM_READONLY { return KWLoc; } SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits