ABataev added reviewers: rjmccall, dblaikie. ABataev updated this revision to Diff 37476. ABataev added a comment.
Update after review http://reviews.llvm.org/D13582 Files: lib/CodeGen/CGExpr.cpp lib/CodeGen/CGExprAgg.cpp lib/CodeGen/CGExprCXX.cpp lib/CodeGen/CGExprComplex.cpp lib/CodeGen/CGExprConstant.cpp lib/CodeGen/CGExprScalar.cpp lib/CodeGen/CodeGenModule.h test/CodeGenCXX/debug-info-explicit-cast.cpp
Index: lib/CodeGen/CGExprCXX.cpp =================================================================== --- lib/CodeGen/CGExprCXX.cpp +++ lib/CodeGen/CGExprCXX.cpp @@ -1806,6 +1806,7 @@ llvm::Value *CodeGenFunction::EmitDynamicCast(Address ThisAddr, const CXXDynamicCastExpr *DCE) { + CGM.EmitExplicitCastExprType(DCE, this); QualType DestTy = DCE->getTypeAsWritten(); if (DCE->isAlwaysNull()) Index: lib/CodeGen/CGExprAgg.cpp =================================================================== --- lib/CodeGen/CGExprAgg.cpp +++ lib/CodeGen/CGExprAgg.cpp @@ -571,6 +571,8 @@ } void AggExprEmitter::VisitCastExpr(CastExpr *E) { + if (const auto *ECE = dyn_cast<ExplicitCastExpr>(E)) + CGF.CGM.EmitExplicitCastExprType(ECE, &CGF); switch (E->getCastKind()) { case CK_Dynamic: { // FIXME: Can this actually happen? We have no test coverage for it. Index: lib/CodeGen/CGExpr.cpp =================================================================== --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -780,6 +780,16 @@ return isPre ? IncVal : InVal; } +void CodeGenModule::EmitExplicitCastExprType(const ExplicitCastExpr *E, + CodeGenFunction *CGF) { + // Bind VLAs in the cast type. + if (CGF && E->getType()->isVariablyModifiedType()) + CGF->EmitVariablyModifiedType(E->getType()); + + if (CGDebugInfo *DI = getModuleDebugInfo()) + DI->EmitExplicitCastType(E->getType()); +} + //===----------------------------------------------------------------------===// // LValue Expression Emission //===----------------------------------------------------------------------===// @@ -795,9 +805,8 @@ // Casts: if (const CastExpr *CE = dyn_cast<CastExpr>(E)) { - // Bind VLAs in the cast type. - if (E->getType()->isVariablyModifiedType()) - EmitVariablyModifiedType(E->getType()); + if (const auto *ECE = dyn_cast<ExplicitCastExpr>(CE)) + CGM.EmitExplicitCastExprType(ECE, this); switch (CE->getCastKind()) { // Non-converting casts (but not C's implicit conversion from void*). @@ -3427,6 +3436,7 @@ // This must be a reinterpret_cast (or c-style equivalent). const auto *CE = cast<ExplicitCastExpr>(E); + CGM.EmitExplicitCastExprType(CE, this); LValue LV = EmitLValue(E->getSubExpr()); Address V = Builder.CreateBitCast(LV.getAddress(), ConvertType(CE->getTypeAsWritten())); Index: lib/CodeGen/CGExprComplex.cpp =================================================================== --- lib/CodeGen/CGExprComplex.cpp +++ lib/CodeGen/CGExprComplex.cpp @@ -154,6 +154,8 @@ return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType()); } ComplexPairTy VisitCastExpr(CastExpr *E) { + if (const auto *ECE = dyn_cast<ExplicitCastExpr>(E)) + CGF.CGM.EmitExplicitCastExprType(ECE, &CGF); return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType()); } ComplexPairTy VisitCallExpr(const CallExpr *E); Index: lib/CodeGen/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -314,12 +314,7 @@ return EmitNullValue(E->getType()); } Value *VisitExplicitCastExpr(ExplicitCastExpr *E) { - if (E->getType()->isVariablyModifiedType()) - CGF.EmitVariablyModifiedType(E->getType()); - - if (CGDebugInfo *DI = CGF.getDebugInfo()) - DI->EmitExplicitCastType(E->getType()); - + CGF.CGM.EmitExplicitCastExprType(E, &CGF); return VisitCastExpr(E); } Value *VisitCastExpr(CastExpr *E); Index: lib/CodeGen/CGExprConstant.cpp =================================================================== --- lib/CodeGen/CGExprConstant.cpp +++ lib/CodeGen/CGExprConstant.cpp @@ -636,6 +636,8 @@ } llvm::Constant *VisitCastExpr(CastExpr* E) { + if (const auto *ECE = dyn_cast<ExplicitCastExpr>(E)) + CGM.EmitExplicitCastExprType(ECE, CGF); Expr *subExpr = E->getSubExpr(); llvm::Constant *C = CGM.EmitConstantExpr(subExpr, subExpr->getType(), CGF); if (!C) return nullptr; Index: lib/CodeGen/CodeGenModule.h =================================================================== --- lib/CodeGen/CodeGenModule.h +++ lib/CodeGen/CodeGenModule.h @@ -923,6 +923,11 @@ QualType DestType, CodeGenFunction *CGF = nullptr); + /// \brief Emit type info if type of an expression is a variably modified + /// type. Also emit proper debug info for cast types. + void EmitExplicitCastExprType(const ExplicitCastExpr *E, + CodeGenFunction *CGF = nullptr); + /// Return the result of value-initializing the given type, i.e. a null /// expression of the given type. This is usually, but not always, an LLVM /// null constant. Index: test/CodeGenCXX/debug-info-explicit-cast.cpp =================================================================== --- test/CodeGenCXX/debug-info-explicit-cast.cpp +++ test/CodeGenCXX/debug-info-explicit-cast.cpp @@ -0,0 +1,46 @@ +// RUN: %clangxx -c -target %itanium_abi_triple -g %s -emit-llvm -S -o - | FileCheck %s +// RUN: %clangxx -c -target %ms_abi_triple -g %s -emit-llvm -S -o - | FileCheck %s + +struct Foo { + int A; + Foo() : A(1){}; +}; + +struct Bar { + int B; + Bar() : B(2){}; +}; + +struct Baz { + int C; + Baz() : C(3){}; +}; + +struct Qux { + int d() { return 4; } + Qux() {}; +}; + +struct Quux { + int E; + Quux() : E(5){}; +}; + +typedef int(Qux::*TD)(); +typedef int(Qux::*TD1)(); +int Val = reinterpret_cast<Baz *>(0)->C; +int main() { + Bar *PB = new Bar; + TD d = &Qux::d; + (void)reinterpret_cast<TD1>(d); + + return reinterpret_cast<Foo *>(PB)->A + reinterpret_cast<Quux *>(0)->E; +} + +// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", +// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "Bar", +// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "Baz", +// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "Qux", +// CHECK-DAG: !DICompositeType(tag: DW_TAG_structure_type, name: "Quux", +// CHECK-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "TD", +// CHECK-DAG: !DIDerivedType(tag: DW_TAG_typedef, name: "TD1",
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits