On Dec 17, 2012, at 16:22 , Richard Smith <[email protected]> wrote:
> Author: rsmith > Date: Mon Dec 17 18:22:45 2012 > New Revision: 170387 > > URL: http://llvm.org/viewvc/llvm-project?rev=170387&view=rev > Log: > 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. > > Modified: > cfe/trunk/lib/CodeGen/CGExpr.cpp > cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp > > Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=170387&r1=170386&r2=170387&view=diff > ============================================================================== > --- cfe/trunk/lib/CodeGen/CGExpr.cpp (original) > +++ cfe/trunk/lib/CodeGen/CGExpr.cpp Mon Dec 17 18:22:45 2012 > @@ -538,8 +538,15 @@ > > // 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 Typo: stastic > 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. > // > > Modified: cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp?rev=170387&r1=170386&r2=170387&view=diff > ============================================================================== > --- cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp (original) > +++ cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp Mon Dec 17 18:22:45 > 2012 > @@ -1,7 +1,13 @@ > // RUN: %clang_cc1 > -fsanitize=signed-integer-overflow,integer-divide-by-zero,float-divide-by-zero,shift,unreachable,return,vla-bound,alignment,null,vptr,object-size,float-cast-overflow,bool,enum > -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s > > +struct S { > + double d; > + int a, b; > + virtual int f(); > +}; > + > // CHECK: @_Z17reference_binding > -void reference_binding(int *p) { > +void reference_binding(int *p, S *q) { > // C++ core issue 453: If an lvalue to which a reference is directly bound > // designates neither an existing object or function of an appropriate type, > // nor a region of storage of suitable size and alignment to contain an > object > @@ -16,13 +22,11 @@ > // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 3 > // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0 > int &r = *p; > -} > > -struct S { > - double d; > - int a, b; > - virtual int f(); > -}; > + // A reference is not required to refer to an object within its lifetime. > + // CHECK-NOT: __ubsan_handle_dynamic_type_cache_miss > + S &r2 = *q; > +} > > // CHECK: @_Z13member_access > void member_access(S *p) { > > > _______________________________________________ > cfe-commits mailing list > [email protected] > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
