[C++2a] Add __builtin_bit_cast, used to implement std::bit_cast
authorErik Pilkington <erik.pilkington@gmail.com>
Tue, 2 Jul 2019 18:28:13 +0000 (18:28 +0000)
committerErik Pilkington <erik.pilkington@gmail.com>
Tue, 2 Jul 2019 18:28:13 +0000 (18:28 +0000)
commiteee944e7f9e60df44714eb547d0b876ee5dc7290
treebfbb77d0b88de0f45c22ce3747d8d214d0f5a0d7
parent5613874947462fd4ceb4f66926c879269609463f
[C++2a] Add __builtin_bit_cast, used to implement std::bit_cast

This commit adds a new builtin, __builtin_bit_cast(T, v), which performs a
bit_cast from a value v to a type T. This expression can be evaluated at
compile time under specific circumstances.

The compile time evaluation currently doesn't support bit-fields, but I'm
planning on fixing this in a follow up (some of the logic for figuring this out
is in CodeGen). I'm also planning follow-ups for supporting some more esoteric
types that the constexpr evaluator supports, as well as extending
__builtin_memcpy constexpr evaluation to use the same infrastructure.

rdar://44987528

Differential revision: https://reviews.llvm.org/D62825

llvm-svn: 364954
41 files changed:
clang/include/clang-c/Index.h
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/OperationKinds.def
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Parse/Parser.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprClassification.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/CodeGen/CGExprComplex.cpp
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Edit/RewriteObjCFoundationAPI.cpp
clang/lib/Lex/PPMacroExpansion.cpp
clang/lib/Parse/ParseExpr.cpp
clang/lib/Parse/ParseExprCXX.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
clang/test/CodeGenCXX/builtin-bit-cast-no-tbaa.cpp [new file with mode: 0644]
clang/test/CodeGenCXX/builtin-bit-cast.cpp [new file with mode: 0644]
clang/test/SemaCXX/builtin-bit-cast.cpp [new file with mode: 0644]
clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp [new file with mode: 0644]
clang/tools/libclang/CIndex.cpp
clang/tools/libclang/CXCursor.cpp
llvm/include/llvm/ADT/APInt.h
llvm/lib/ExecutionEngine/ExecutionEngine.cpp
llvm/lib/Support/APInt.cpp