diff options
| author | Piotr Padlewski <piotr.padlewski@gmail.com> | 2018-07-02 19:21:36 +0000 |
|---|---|---|
| committer | Piotr Padlewski <piotr.padlewski@gmail.com> | 2018-07-02 19:21:36 +0000 |
| commit | ddb77a4e35a61b758922bc15fb68c8ca224655e5 (patch) | |
| tree | 17223f63d3773bc76095be51cb4e27d7100e8a16 /lib/CodeGen/CGExpr.cpp | |
| parent | 4084c9e30339676a7bea9cca1496101f0b191a3f (diff) | |
| download | clang-ddb77a4e35a61b758922bc15fb68c8ca224655e5.tar.gz | |
[CodeGenCXX] Emit strip.invariant.group with -fstrict-vtable-pointers
Summary:
Emmiting new intrinsic that strips invariant.groups to make
devirtulization sound, as described in RFC: Devirtualization v2.
Reviewers: rjmccall, rsmith, amharc, kuhar
Subscribers: llvm-commits, cfe-commits
Differential Revision: https://reviews.llvm.org/D47299
Co-authored-by: Krzysztof Pszeniczny <krzysztof.pszeniczny@gmail.com>
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336137 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
| -rw-r--r-- | lib/CodeGen/CGExpr.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp index 12b30936dc..3097caacb3 100644 --- a/lib/CodeGen/CGExpr.cpp +++ b/lib/CodeGen/CGExpr.cpp @@ -3870,6 +3870,18 @@ LValue CodeGenFunction::EmitLValueForField(LValue base, } Address addr = base.getAddress(); + if (auto *ClassDef = dyn_cast<CXXRecordDecl>(rec)) { + if (CGM.getCodeGenOpts().StrictVTablePointers && + ClassDef->isDynamicClass()) { + // Getting to any field of dynamic object requires stripping dynamic + // information provided by invariant.group. This is because accessing + // fields may leak the real address of dynamic object, which could result + // in miscompilation when leaked pointer would be compared. + auto *stripped = Builder.CreateStripInvariantGroup(addr.getPointer()); + addr = Address(stripped, addr.getAlignment()); + } + } + unsigned RecordCVR = base.getVRQualifiers(); if (rec->isUnion()) { // For unions, there is no pointer adjustment. |
