diff options
author | Raphael Isemann <teemperor@gmail.com> | 2018-08-20 16:20:01 +0000 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2018-08-20 16:20:01 +0000 |
commit | c705bb840172ce32d90e1b11b887726e338b9df7 (patch) | |
tree | c0a3b091f64cda25bea3d17aac8c8c3f202ae40d | |
parent | 7b1a7bd5bab1dfc1f411daab4761d2842f564fd6 (diff) | |
download | bcm5719-llvm-c705bb840172ce32d90e1b11b887726e338b9df7.tar.gz bcm5719-llvm-c705bb840172ce32d90e1b11b887726e338b9df7.zip |
[ASTImporter] Add test for C++ casts and fix broken const_cast importing.
Summary:
The ASTImporter does currently not handle const_casts. This patch adds the
missing const_cast importer code and the test case that discovered this.
Reviewers: a.sidorin, a_sidorin
Reviewed By: a_sidorin
Subscribers: a_sidorin, martong, cfe-commits
Differential Revision: https://reviews.llvm.org/D50932
llvm-svn: 340182
-rw-r--r-- | clang/lib/AST/ASTImporter.cpp | 4 | ||||
-rw-r--r-- | clang/test/Import/cxx-casts/Inputs/F.cpp | 12 | ||||
-rw-r--r-- | clang/test/Import/cxx-casts/test.cpp | 21 | ||||
-rw-r--r-- | clang/tools/clang-import-test/clang-import-test.cpp | 2 |
4 files changed, 39 insertions, 0 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index c1136c9f428..8a8b3213e25 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6897,6 +6897,10 @@ Expr *ASTNodeImporter::VisitCXXNamedCastExpr(CXXNamedCastExpr *E) { return CXXReinterpretCastExpr::Create( Importer.getToContext(), ToType, VK, CK, ToOp, &BasePath, ToWritten, ToOperatorLoc, ToRParenLoc, ToAngleBrackets); + } else if (isa<CXXConstCastExpr>(E)) { + return CXXConstCastExpr::Create(Importer.getToContext(), ToType, VK, ToOp, + ToWritten, ToOperatorLoc, ToRParenLoc, + ToAngleBrackets); } else { return nullptr; } diff --git a/clang/test/Import/cxx-casts/Inputs/F.cpp b/clang/test/Import/cxx-casts/Inputs/F.cpp new file mode 100644 index 00000000000..79326a7e4b2 --- /dev/null +++ b/clang/test/Import/cxx-casts/Inputs/F.cpp @@ -0,0 +1,12 @@ +struct A { + virtual ~A() {} +}; +struct B : public A {}; + +void f() { + const A *b = new B(); + const B *c1 = dynamic_cast<const B *>(b); + const B *c2 = static_cast<const B *>(b); + const B *c3 = reinterpret_cast<const B *>(b); + A *c4 = const_cast<A *>(b); +} diff --git a/clang/test/Import/cxx-casts/test.cpp b/clang/test/Import/cxx-casts/test.cpp new file mode 100644 index 00000000000..49215ce81c7 --- /dev/null +++ b/clang/test/Import/cxx-casts/test.cpp @@ -0,0 +1,21 @@ +// RUN: clang-import-test -dump-ast -import %S/Inputs/F.cpp -expression %s | FileCheck %s + +// CHECK: CXXDynamicCastExpr +// CHECK-SAME: dynamic_cast +// CHECK-SAME: <Dynamic> + +// CHECK: CXXStaticCastExpr +// CHECK-SAME: static_cast +// CHECK-SAME: <BaseToDerived (A)> + +// CHECK: CXXReinterpretCastExpr +// CHECK-SAME: reinterpret_cast +// CHECK-SAME: <BitCast> + +// CHECK: CXXConstCastExpr +// CHECK-SAME: const_cast +// CHECK-SAME: <NoOp> + +void expr() { + f(); +} diff --git a/clang/tools/clang-import-test/clang-import-test.cpp b/clang/tools/clang-import-test/clang-import-test.cpp index 106f3d1d150..ff14f62574e 100644 --- a/clang/tools/clang-import-test/clang-import-test.cpp +++ b/clang/tools/clang-import-test/clang-import-test.cpp @@ -194,6 +194,8 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance() { Inv->getLangOpts()->ThreadsafeStatics = false; Inv->getLangOpts()->AccessControl = false; Inv->getLangOpts()->DollarIdents = true; + // Needed for testing dynamic_cast. + Inv->getLangOpts()->RTTI = true; Inv->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo); Inv->getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple(); |