jfb created this revision.
Herald added subscribers: cfe-commits, dexonsmith.

Automatic variable initialization was generating default-aligned stores (which 
are deprecated) instead of using the known alignment from the alloca.


Repository:
  rC Clang

https://reviews.llvm.org/D49209

Files:
  lib/CodeGen/CGDecl.cpp


Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -888,15 +888,18 @@
 /// emitStoresForInitAfterMemset - For inits that
 /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar
 /// stores that would be required.
-static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value 
*Loc,
-                                         bool isVolatile, CGBuilderTy 
&Builder) {
+static void emitStoresForInitAfterMemset(CodeGenModule &CGM,
+                                         llvm::Constant *Init, llvm::Value 
*Loc,
+                                         bool isVolatile,
+                                         CGBuilderTy &Builder) {
   assert(!Init->isNullValue() && !isa<llvm::UndefValue>(Init) &&
          "called emitStoresForInitAfterMemset for zero or undef value.");
 
   if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
       isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
       isa<llvm::ConstantExpr>(Init)) {
-    Builder.CreateDefaultAlignedStore(Init, Loc, isVolatile);
+    Builder.CreateAlignedStore(
+        Init, Loc, Loc->getPointerAlignment(CGM.getDataLayout()), isVolatile);
     return;
   }
 
@@ -908,7 +911,7 @@
       // If necessary, get a pointer to the element and emit it.
       if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
         emitStoresForInitAfterMemset(
-            Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
+            CGM, Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
             isVolatile, Builder);
     }
     return;
@@ -923,7 +926,7 @@
     // If necessary, get a pointer to the element and emit it.
     if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
       emitStoresForInitAfterMemset(
-          Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
+          CGM, Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
           isVolatile, Builder);
   }
 }
@@ -1411,8 +1414,8 @@
     if (!constant->isNullValue() && !isa<llvm::UndefValue>(constant)) {
       Loc = Builder.CreateBitCast(Loc,
         constant->getType()->getPointerTo(Loc.getAddressSpace()));
-      emitStoresForInitAfterMemset(constant, Loc.getPointer(),
-                                   isVolatile, Builder);
+      emitStoresForInitAfterMemset(CGM, constant, Loc.getPointer(), isVolatile,
+                                   Builder);
     }
   } else {
     // Otherwise, create a temporary global with the initializer then


Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -888,15 +888,18 @@
 /// emitStoresForInitAfterMemset - For inits that
 /// canEmitInitWithFewStoresAfterMemset returned true for, emit the scalar
 /// stores that would be required.
-static void emitStoresForInitAfterMemset(llvm::Constant *Init, llvm::Value *Loc,
-                                         bool isVolatile, CGBuilderTy &Builder) {
+static void emitStoresForInitAfterMemset(CodeGenModule &CGM,
+                                         llvm::Constant *Init, llvm::Value *Loc,
+                                         bool isVolatile,
+                                         CGBuilderTy &Builder) {
   assert(!Init->isNullValue() && !isa<llvm::UndefValue>(Init) &&
          "called emitStoresForInitAfterMemset for zero or undef value.");
 
   if (isa<llvm::ConstantInt>(Init) || isa<llvm::ConstantFP>(Init) ||
       isa<llvm::ConstantVector>(Init) || isa<llvm::BlockAddress>(Init) ||
       isa<llvm::ConstantExpr>(Init)) {
-    Builder.CreateDefaultAlignedStore(Init, Loc, isVolatile);
+    Builder.CreateAlignedStore(
+        Init, Loc, Loc->getPointerAlignment(CGM.getDataLayout()), isVolatile);
     return;
   }
 
@@ -908,7 +911,7 @@
       // If necessary, get a pointer to the element and emit it.
       if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
         emitStoresForInitAfterMemset(
-            Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
+            CGM, Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
             isVolatile, Builder);
     }
     return;
@@ -923,7 +926,7 @@
     // If necessary, get a pointer to the element and emit it.
     if (!Elt->isNullValue() && !isa<llvm::UndefValue>(Elt))
       emitStoresForInitAfterMemset(
-          Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
+          CGM, Elt, Builder.CreateConstGEP2_32(Init->getType(), Loc, 0, i),
           isVolatile, Builder);
   }
 }
@@ -1411,8 +1414,8 @@
     if (!constant->isNullValue() && !isa<llvm::UndefValue>(constant)) {
       Loc = Builder.CreateBitCast(Loc,
         constant->getType()->getPointerTo(Loc.getAddressSpace()));
-      emitStoresForInitAfterMemset(constant, Loc.getPointer(),
-                                   isVolatile, Builder);
+      emitStoresForInitAfterMemset(CGM, constant, Loc.getPointer(), isVolatile,
+                                   Builder);
     }
   } else {
     // Otherwise, create a temporary global with the initializer then
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to