<div dir="ltr">The code change looks fine to me, but needs a testcase.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jul 7, 2014 at 9:04 AM, Byoungyoung Lee <span dir="ltr"><<a href="mailto:byoungyoung@chromium.org" target="_blank">byoungyoung@chromium.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi samsonov, rsmith, kcc,<br>
<br>
This is a Clang side patch for type-based blacklisting in Ubsan. As this patch is depending on llvm-side patch, please see <a href="http://reviews.llvm.org/D4406" target="_blank">http://reviews.llvm.org/D4406</a> for more details.<br>

<br>
Although the diff looks more complicated than it has to be, this patch only adds a simple branch  ---- if (!CGM.getSanitizerBlacklist().isIn(Out.str())).<br>
<br>
<a href="http://reviews.llvm.org/D4407" target="_blank">http://reviews.llvm.org/D4407</a><br>
<br>
Files:<br>
  lib/CodeGen/CGExpr.cpp<br>
<br>
Index: lib/CodeGen/CGExpr.cpp<br>
===================================================================<br>
--- lib/CodeGen/CGExpr.cpp<br>
+++ lib/CodeGen/CGExpr.cpp<br>
@@ -539,44 +539,47 @@<br>
     llvm::raw_svector_ostream Out(MangledName);<br>
     CGM.getCXXABI().getMangleContext().mangleCXXRTTI(Ty.getUnqualifiedType(),<br>
                                                      Out);<br>
-    llvm::hash_code TypeHash = hash_value(Out.str());<br>
<br>
-    // Load the vptr, and compute hash_16_bytes(TypeHash, vptr).<br>
-    llvm::Value *Low = llvm::ConstantInt::get(Int64Ty, TypeHash);<br>
-    llvm::Type *VPtrTy = llvm::PointerType::get(IntPtrTy, 0);<br>
-    llvm::Value *VPtrAddr = Builder.CreateBitCast(Address, VPtrTy);<br>
-    llvm::Value *VPtrVal = Builder.CreateLoad(VPtrAddr);<br>
-    llvm::Value *High = Builder.CreateZExt(VPtrVal, Int64Ty);<br>
+    // Blacklist based on the mangled types<br>
+    if (!CGM.getSanitizerBlacklist().isIn(Out.str())) {<br>
+      llvm::hash_code TypeHash = hash_value(Out.str());<br>
<br>
-    llvm::Value *Hash = emitHash16Bytes(Builder, Low, High);<br>
-    Hash = Builder.CreateTrunc(Hash, IntPtrTy);<br>
+      // Load the vptr, and compute hash_16_bytes(TypeHash, vptr).<br>
+      llvm::Value *Low = llvm::ConstantInt::get(Int64Ty, TypeHash);<br>
+      llvm::Type *VPtrTy = llvm::PointerType::get(IntPtrTy, 0);<br>
+      llvm::Value *VPtrAddr = Builder.CreateBitCast(Address, VPtrTy);<br>
+      llvm::Value *VPtrVal = Builder.CreateLoad(VPtrAddr);<br>
+      llvm::Value *High = Builder.CreateZExt(VPtrVal, Int64Ty);<br>
<br>
-    // Look the hash up in our cache.<br>
-    const int CacheSize = 128;<br>
-    llvm::Type *HashTable = llvm::ArrayType::get(IntPtrTy, CacheSize);<br>
-    llvm::Value *Cache = CGM.CreateRuntimeVariable(HashTable,<br>
-                                                   "__ubsan_vptr_type_cache");<br>
-    llvm::Value *Slot = Builder.CreateAnd(Hash,<br>
-                                          llvm::ConstantInt::get(IntPtrTy,<br>
-                                                                 CacheSize-1));<br>
-    llvm::Value *Indices[] = { Builder.getInt32(0), Slot };<br>
-    llvm::Value *CacheVal =<br>
-      Builder.CreateLoad(Builder.CreateInBoundsGEP(Cache, Indices));<br>
+      llvm::Value *Hash = emitHash16Bytes(Builder, Low, High);<br>
+      Hash = Builder.CreateTrunc(Hash, IntPtrTy);<br>
<br>
-    // If the hash isn't in the cache, call a runtime handler to perform the<br>
-    // hard work of checking whether the vptr is for an object of the right<br>
-    // type. This will either fill in the cache and return, or produce a<br>
-    // diagnostic.<br>
-    llvm::Constant *StaticData[] = {<br>
-      EmitCheckSourceLocation(Loc),<br>
-      EmitCheckTypeDescriptor(Ty),<br>
-      CGM.GetAddrOfRTTIDescriptor(Ty.getUnqualifiedType()),<br>
-      llvm::ConstantInt::get(Int8Ty, TCK)<br>
-    };<br>
-    llvm::Value *DynamicData[] = { Address, Hash };<br>
-    EmitCheck(Builder.CreateICmpEQ(CacheVal, Hash),<br>
-              "dynamic_type_cache_miss", StaticData, DynamicData,<br>
-              CRK_AlwaysRecoverable);<br>
+      // Look the hash up in our cache.<br>
+      const int CacheSize = 128;<br>
+      llvm::Type *HashTable = llvm::ArrayType::get(IntPtrTy, CacheSize);<br>
+      llvm::Value *Cache = CGM.CreateRuntimeVariable(HashTable,<br>
+                                                     "__ubsan_vptr_type_cache");<br>
+      llvm::Value *Slot =<br>
+        Builder.CreateAnd(Hash,llvm::ConstantInt::get(IntPtrTy, CacheSize-1));<br>
+      llvm::Value *Indices[] = { Builder.getInt32(0), Slot };<br>
+      llvm::Value *CacheVal =<br>
+        Builder.CreateLoad(Builder.CreateInBoundsGEP(Cache, Indices));<br>
+<br>
+      // If the hash isn't in the cache, call a runtime handler to perform the<br>
+      // hard work of checking whether the vptr is for an object of the right<br>
+      // type. This will either fill in the cache and return, or produce a<br>
+      // diagnostic.<br>
+      llvm::Constant *StaticData[] = {<br>
+        EmitCheckSourceLocation(Loc),<br>
+        EmitCheckTypeDescriptor(Ty),<br>
+        CGM.GetAddrOfRTTIDescriptor(Ty.getUnqualifiedType()),<br>
+        llvm::ConstantInt::get(Int8Ty, TCK)<br>
+      };<br>
+      llvm::Value *DynamicData[] = { Address, Hash };<br>
+      EmitCheck(Builder.CreateICmpEQ(CacheVal, Hash),<br>
+                "dynamic_type_cache_miss", StaticData, DynamicData,<br>
+                CRK_AlwaysRecoverable);<br>
+    }<br>
   }<br>
<br>
   if (Done) {<br>
<br>_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br></blockquote></div><br></div>