This revision was automatically updated to reflect the committed changes. Closed by commit rL340182: [ASTImporter] Add test for C++ casts and fix broken const_cast importing. (authored by teemperor, committed by ). Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D50932?vs=161496&id=161498#toc Repository: rL LLVM https://reviews.llvm.org/D50932 Files: cfe/trunk/lib/AST/ASTImporter.cpp cfe/trunk/test/Import/cxx-casts/Inputs/F.cpp cfe/trunk/test/Import/cxx-casts/test.cpp cfe/trunk/tools/clang-import-test/clang-import-test.cpp Index: cfe/trunk/lib/AST/ASTImporter.cpp =================================================================== --- cfe/trunk/lib/AST/ASTImporter.cpp +++ cfe/trunk/lib/AST/ASTImporter.cpp @@ -6897,6 +6897,10 @@ 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; } Index: cfe/trunk/tools/clang-import-test/clang-import-test.cpp =================================================================== --- cfe/trunk/tools/clang-import-test/clang-import-test.cpp +++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp @@ -194,6 +194,8 @@ 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(); Index: cfe/trunk/test/Import/cxx-casts/Inputs/F.cpp =================================================================== --- cfe/trunk/test/Import/cxx-casts/Inputs/F.cpp +++ cfe/trunk/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); +} Index: cfe/trunk/test/Import/cxx-casts/test.cpp =================================================================== --- cfe/trunk/test/Import/cxx-casts/test.cpp +++ cfe/trunk/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(); +}
Index: cfe/trunk/lib/AST/ASTImporter.cpp =================================================================== --- cfe/trunk/lib/AST/ASTImporter.cpp +++ cfe/trunk/lib/AST/ASTImporter.cpp @@ -6897,6 +6897,10 @@ 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; } Index: cfe/trunk/tools/clang-import-test/clang-import-test.cpp =================================================================== --- cfe/trunk/tools/clang-import-test/clang-import-test.cpp +++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp @@ -194,6 +194,8 @@ 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(); Index: cfe/trunk/test/Import/cxx-casts/Inputs/F.cpp =================================================================== --- cfe/trunk/test/Import/cxx-casts/Inputs/F.cpp +++ cfe/trunk/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); +} Index: cfe/trunk/test/Import/cxx-casts/test.cpp =================================================================== --- cfe/trunk/test/Import/cxx-casts/test.cpp +++ cfe/trunk/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(); +}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits