aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/CGExpr.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-12-18 00:22:45 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-12-18 00:22:45 +0000
commit073fec91b73f08ba86ad46573141be14c7a0d262 (patch)
tree29c7fbb678c7e7d428e293d7c8b9721377247422 /lib/CodeGen/CGExpr.cpp
parent372df4548267ce5d6ecf1da68902f0d793271a4f (diff)
Rein ubsan's vptr sanitizer back a bit. Per core issue 453, binding a reference
to an object outside its lifetime does not have undefined behavior. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170387 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExpr.cpp')
-rw-r--r--lib/CodeGen/CGExpr.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index 0be483a907..19109d7b01 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -538,8 +538,15 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
// If possible, check that the vptr indicates that there is a subobject of
// type Ty at offset zero within this object.
+ //
+ // C++11 [basic.life]p5,6:
+ // [For storage which does not refer to an object within its lifetime]
+ // The program has undefined behavior if:
+ // -- the [pointer or glvalue] is used to access a non-static data member
+ // or call a non-stastic member function
CXXRecordDecl *RD = Ty->getAsCXXRecordDecl();
- if (getLangOpts().SanitizeVptr && TCK != TCK_ConstructorCall &&
+ if (getLangOpts().SanitizeVptr &&
+ (TCK == TCK_MemberAccess || TCK == TCK_MemberCall) &&
RD && RD->hasDefinition() && RD->isDynamicClass()) {
// Compute a hash of the mangled name of the type.
//