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/CGExpr.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/CGExpr.cpp')
| -rw-r--r-- | lib/CodeGen/CGExpr.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 73824afc17..0e87d8311c 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -2764,18 +2764,18 @@ LValue CodeGenFunction::EmitCastLValue(const CastExpr *E) { LValue LV = EmitLValue(E->getSubExpr()); - // C++11 [expr.static.cast]p2: Behavior is undefined if a downcast is - // performed and the object is not of the derived type. - if (SanitizePerformTypeCheck) - EmitTypeCheck(TCK_DowncastReference, E->getExprLoc(), - LV.getAddress(), E->getType()); - // Perform the base-to-derived conversion llvm::Value *Derived = GetAddressOfDerivedClass(LV.getAddress(), DerivedClassDecl, E->path_begin(), E->path_end(), /*NullCheckValue=*/false); + // C++11 [expr.static.cast]p2: Behavior is undefined if a downcast is + // performed and the object is not of the derived type. + if (SanitizePerformTypeCheck) + EmitTypeCheck(TCK_DowncastReference, E->getExprLoc(), + Derived, E->getType()); + return MakeAddrLValue(Derived, E->getType()); } case CK_LValueBitCast: { |
