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);
   }
 


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);
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to