diff options
| author | Filipe Cabecinhas <me@filcab.net> | 2013-08-08 01:08:17 +0000 |
|---|---|---|
| committer | Filipe Cabecinhas <me@filcab.net> | 2013-08-08 01:08:17 +0000 |
| commit | 8593e7821c02bd429964d2daf7a6acccb8040fb2 (patch) | |
| tree | fa39a2b77123c40610cab1b4c4a07c0f25f1354d /lib/CodeGen/CGExprScalar.cpp | |
| parent | b3574796d7cc0113e54b6516fc16e17ca09459fb (diff) | |
| download | clang-8593e7821c02bd429964d2daf7a6acccb8040fb2.tar.gz clang-8593e7821c02bd429964d2daf7a6acccb8040fb2.tar.bz2 clang-8593e7821c02bd429964d2daf7a6acccb8040fb2.tar.xz | |
UBSan: Fix alignment checks emitted in downcasts.
Summary:
UBSan was checking for alignment of the derived class on the pointer to
the base class, before converting. With some class hierarchies, this could
generate false positives.
Added test-case.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@187948 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprScalar.cpp')
| -rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index b6bda28471..287dc6c023 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -1234,15 +1234,18 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) { llvm::Value *V = Visit(E); + llvm::Value *Derived = + CGF.GetAddressOfDerivedClass(V, DerivedClassDecl, + CE->path_begin(), CE->path_end(), + ShouldNullCheckClassCastValue(CE)); + // C++11 [expr.static.cast]p11: Behavior is undefined if a downcast is // performed and the object is not of the derived type. if (CGF.SanitizePerformTypeCheck) CGF.EmitTypeCheck(CodeGenFunction::TCK_DowncastPointer, CE->getExprLoc(), - V, DestTy->getPointeeType()); + Derived, DestTy->getPointeeType()); - return CGF.GetAddressOfDerivedClass(V, DerivedClassDecl, - CE->path_begin(), CE->path_end(), - ShouldNullCheckClassCastValue(CE)); + return Derived; } case CK_UncheckedDerivedToBase: case CK_DerivedToBase: { |
