[PATCH] D19667: [ubsan] Minimize size of data for type_mismatch

Filipe Cabecinhas via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 28 09:38:37 PDT 2016


filcab created this revision.
filcab added reviewers: kcc, samsonov, rsmith.
filcab added a subscriber: cfe-commits.

This patch makes the type_mismatch static data 7 bytes smaller (and it ends up
being 16 bytes smaller due to alignment restrictions, at least on some x86-64
environments).

Currently, I have no binary compatibility for using an older object file
(compiled before this change) with a newer clang. Depending on the compiler-rt
code review, this patch might be updated to better signal to the library that
this object has this new binary format.

http://reviews.llvm.org/D19667

Files:
  lib/CodeGen/CGExpr.cpp

Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -575,12 +575,12 @@
   }
 
   if (Checks.size() > 0) {
+    // Make sure we're not losing information. Alignment needs to be a power of 2
+    assert(!AlignVal || (uint64_t)1 << llvm::Log2_64(AlignVal) == AlignVal);
     llvm::Constant *StaticData[] = {
-     EmitCheckSourceLocation(Loc),
-      EmitCheckTypeDescriptor(Ty),
-      llvm::ConstantInt::get(SizeTy, AlignVal),
-      llvm::ConstantInt::get(Int8Ty, TCK)
-    };
+        EmitCheckSourceLocation(Loc), EmitCheckTypeDescriptor(Ty),
+        llvm::ConstantInt::get(Int8Ty, llvm::Log2_64(AlignVal)),
+        llvm::ConstantInt::get(Int8Ty, TCK)};
     EmitCheck(Checks, "type_mismatch", StaticData, Ptr);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19667.55428.patch
Type: text/x-patch
Size: 826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160428/9a025f04/attachment.bin>


More information about the cfe-commits mailing list