[PATCH] D50932: [ASTImporter] Add test for C++ casts and fix broken const_cast importing.
Raphael Isemann via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 20 09:20:06 PDT 2018
teemperor updated this revision to Diff 161496.
teemperor added a comment.
- Added comment why we enable RTTI.
https://reviews.llvm.org/D50932
Files:
lib/AST/ASTImporter.cpp
test/Import/cxx-casts/Inputs/F.cpp
test/Import/cxx-casts/test.cpp
tools/clang-import-test/clang-import-test.cpp
Index: tools/clang-import-test/clang-import-test.cpp
===================================================================
--- tools/clang-import-test/clang-import-test.cpp
+++ 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: test/Import/cxx-casts/test.cpp
===================================================================
--- /dev/null
+++ 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: test/Import/cxx-casts/Inputs/F.cpp
===================================================================
--- /dev/null
+++ 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: lib/AST/ASTImporter.cpp
===================================================================
--- lib/AST/ASTImporter.cpp
+++ 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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50932.161496.patch
Type: text/x-patch
Size: 2343 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180820/63394b17/attachment.bin>
More information about the cfe-commits
mailing list