vleschuk retitled this revision from "DebugInfo: use 
llvm::DINode::FlagAlignment to mark forcibly aligned data" to "DebugInfo: Pass 
non-zero alignment to DIBuilder only if aligment was forced".
vleschuk updated the summary for this revision.
vleschuk updated this revision to Diff 70965.
vleschuk added a comment.

Got rid of DINode::FlagAlignment. Check for forced alignment (alignas(), 
_Alignas(), __attribute(aligned (N))))) when creating DI* objects with 
DIBuilder. If alignment was not forced pass zero, otherwise pass actual 
alignment value. Updated related tests according to new behavior.


https://reviews.llvm.org/D24426

Files:
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CGDebugInfo.h
  test/CodeGen/debug-info-packed-struct.c
  test/CodeGen/debug-info-vector.c
  test/CodeGenCXX/debug-info-calling-conventions.cpp
  test/CodeGenCXX/debug-info-enum-class.cpp
  test/CodeGenCXX/debug-info-indirect-field-decl.cpp
  test/CodeGenCXX/debug-info-ms-bitfields.cpp
  test/CodeGenCXX/debug-info-ms-ptr-to-member.cpp
  test/CodeGenCXX/debug-info-rvalue-ref.cpp
  test/CodeGenCXX/debug-info-template-quals.cpp
  test/CodeGenCXX/debug-info-template.cpp
  test/CodeGenCXX/debug-info-union.cpp
  test/CodeGenCXX/debug-info-uuid.cpp
  test/CodeGenCXX/debug-info-vla.cpp
  test/CodeGenCXX/debug-info-zero-length-arrays.cpp
  test/CodeGenCXX/debug-info.cpp
  test/CodeGenCXX/debug-lambda-this.cpp
  test/CodeGenObjC/block-byref-debuginfo.m
  test/CodeGenObjC/debug-info-block-type.m
  test/CodeGenObjC/debug-info-ivars-extension.m
  test/CodeGenObjC/debug-info-ivars-private.m
  test/CodeGenObjC/debug-info-ivars.m
  test/CodeGenObjCXX/debug-info-cyclic.mm

Index: test/CodeGenObjCXX/debug-info-cyclic.mm
===================================================================
--- test/CodeGenObjCXX/debug-info-cyclic.mm
+++ test/CodeGenObjCXX/debug-info-cyclic.mm
@@ -3,7 +3,7 @@
 struct B {
 // CHECK: ![[B:[0-9]+]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "B"
 // CHECK-SAME:                             line: [[@LINE-2]],
-// CHECK-SAME:                             size: 8, align: 8,
+// CHECK-SAME:                             size: 8,
 // CHECK-NOT:                              offset:
 // CHECK-NOT:                              DIFlagFwdDecl
 // CHECK-SAME:                             elements: ![[BMEMBERS:[0-9]+]]
Index: test/CodeGenObjC/debug-info-ivars.m
===================================================================
--- test/CodeGenObjC/debug-info-ivars.m
+++ test/CodeGenObjC/debug-info-ivars.m
@@ -21,24 +21,24 @@
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "i"
 // CHECK-SAME:           line: 10
 // CHECK-SAME:           baseType: ![[INT:[0-9]+]]
-// CHECK-SAME:           size: 32, align: 32,
+// CHECK-SAME:           size: 32,
 // CHECK-NOT:            offset:
 // CHECK-SAME:           flags: DIFlagProtected
 // CHECK: ![[INT]] = !DIBasicType(name: "int"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_1"
 // CHECK-SAME:           line: 11
 // CHECK-SAME:           baseType: ![[UNSIGNED:[0-9]+]]
-// CHECK-SAME:           size: 9, align: 32,
+// CHECK-SAME:           size: 9,
 // CHECK-NOT:            offset:
 // CHECK-SAME:           flags: DIFlagProtected
 // CHECK: ![[UNSIGNED]] = !DIBasicType(name: "unsigned int"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_2"
 // CHECK-SAME:           line: 12
 // CHECK-SAME:           baseType: ![[UNSIGNED]]
-// CHECK-SAME:           size: 9, align: 32, offset: 1,
+// CHECK-SAME:           size: 9, offset: 1,
 // CHECK-SAME:           flags: DIFlagProtected
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "flag_3"
 // CHECK-SAME:           line: 14
 // CHECK-SAME:           baseType: ![[UNSIGNED]]
-// CHECK-SAME:           size: 9, align: 32, offset: 3,
+// CHECK-SAME:           size: 9, offset: 3,
 // CHECK-SAME:           flags: DIFlagProtected
Index: test/CodeGenObjC/debug-info-ivars-private.m
===================================================================
--- test/CodeGenObjC/debug-info-ivars-private.m
+++ test/CodeGenObjC/debug-info-ivars-private.m
@@ -35,13 +35,13 @@
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "foo"
 // CHECK-SAME:           line: 14
 // CHECK-SAME:           baseType: ![[INT:[0-9]+]]
-// CHECK-SAME:           size: 32, align: 32,
+// CHECK-SAME:           size: 32,
 // CHECK-NOT:            offset:
 // CHECK-SAME:           flags: DIFlagProtected
 // CHECK: ![[INT]] = !DIBasicType(name: "int"
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "bar"
 // CHECK-SAME:           line: 27
 // CHECK-SAME:           baseType: ![[INT:[0-9]+]]
-// CHECK-SAME:           size: 32, align: 32,
+// CHECK-SAME:           size: 32,
 // CHECK-NOT:            offset:
 // CHECK-SAME:           flags: DIFlagPrivate
Index: test/CodeGenObjC/debug-info-ivars-extension.m
===================================================================
--- test/CodeGenObjC/debug-info-ivars-extension.m
+++ test/CodeGenObjC/debug-info-ivars-extension.m
@@ -30,7 +30,7 @@
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "a"
 // CHECK-SAME:           line: 7
 // CHECK-SAME:           baseType: ![[INT:[0-9]+]]
-// CHECK-SAME:           size: 32, align: 32
+// CHECK-SAME:           size: 32
 // CHECK-NOT:            offset:
 // CHECK-SAME:           flags: DIFlagPublic
 // CHECK: ![[INT]] = !DIBasicType(name: "int"
@@ -42,6 +42,6 @@
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "b"
 // CHECK-SAME:           line: 18
 // CHECK-SAME:           baseType: ![[INT]]
-// CHECK-SAME:           size: 32, align: 32
+// CHECK-SAME:           size: 32
 // CHECK-NOT:            offset:
 // CHECK-SAME:           flags: DIFlagPublic
Index: test/CodeGenObjC/debug-info-block-type.m
===================================================================
--- test/CodeGenObjC/debug-info-block-type.m
+++ test/CodeGenObjC/debug-info-block-type.m
@@ -17,6 +17,6 @@
   SomeKindOfPredicate p = ^BOOL(id obj) { return obj != nil; };
   // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "__FuncPtr",
   // CHECK-SAME:           line: [[@LINE-2]]
-  // CHECK-SAME:           size: 64, align: 64, offset: 128,
+  // CHECK-SAME:           size: 64, offset: 128,
   return p(nil);
 }
Index: test/CodeGenObjC/block-byref-debuginfo.m
===================================================================
--- test/CodeGenObjC/block-byref-debuginfo.m
+++ test/CodeGenObjC/block-byref-debuginfo.m
@@ -5,7 +5,6 @@
 // expression (256) that locates it inside of the byref descriptor:
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "foo",
 // CHECK-NOT:            line:
-// CHECK-SAME:           align: 64
 // CHECK-SAME:           offset: 256
 
 struct Foo {
Index: test/CodeGenCXX/debug-lambda-this.cpp
===================================================================
--- test/CodeGenCXX/debug-lambda-this.cpp
+++ test/CodeGenCXX/debug-lambda-this.cpp
@@ -13,10 +13,10 @@
 }
 
 // CHECK: ![[D:[0-9]+]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "D",
-// CHECK: ![[POINTER:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[D]], size: 64, align: 64)
+// CHECK: ![[POINTER:.*]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[D]], size: 64)
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "this",
 // CHECK-SAME:           line: 11
 // CHECK-SAME:           baseType: ![[POINTER]]
-// CHECK-SAME:           size: 64, align: 64
+// CHECK-SAME:           size: 64
 // CHECK-NOT:            offset: 0
 // CHECK-SAME:           ){{$}}
Index: test/CodeGenCXX/debug-info.cpp
===================================================================
--- test/CodeGenCXX/debug-info.cpp
+++ test/CodeGenCXX/debug-info.cpp
@@ -67,8 +67,8 @@
   struct A { int a; };
   struct B : virtual A { int b; };
 // BOTH: ![[VBASE_B:[0-9]+]] ={{.*}}!DICompositeType(tag: DW_TAG_structure_type, name: "B",{{.*}} line: [[@LINE-1]],
-// MSVC-SAME:                                        size: 96, align: 32
-// CHECK-SAME:                                       size: 128, align: 64,
+// MSVC-SAME:                                        size: 96
+// CHECK-SAME:                                       size: 128,
 // BOTH-NOT:                                         offset:
 // BOTH-NOT:                                         DIFlagFwdDecl
 // BOTH-SAME:                                        elements: [[VBASE_B_DEF:![0-9]+]]
Index: test/CodeGenCXX/debug-info-zero-length-arrays.cpp
===================================================================
--- test/CodeGenCXX/debug-info-zero-length-arrays.cpp
+++ test/CodeGenCXX/debug-info-zero-length-arrays.cpp
@@ -10,7 +10,6 @@
 // CHECK-SAME:           baseType: [[ARRAY_TYPE:![0-9]+]]
 // CHECK: [[ARRAY_TYPE]] = !DICompositeType(tag: DW_TAG_array_type,
 // CHECK-NOT:                               size:
-// CHECK-SAME:                              align: 32
 // CHECK-SAME:                              elements: [[ELEM_TYPE:![0-9]+]]
 // CHECK: [[ELEM_TYPE]] = !{[[SUBRANGE:.*]]}
 // CHECK: [[SUBRANGE]] = !DISubrange(count: -1)
Index: test/CodeGenCXX/debug-info-vla.cpp
===================================================================
--- test/CodeGenCXX/debug-info-vla.cpp
+++ test/CodeGenCXX/debug-info-vla.cpp
@@ -7,7 +7,6 @@
 
 // CHECK: !DICompositeType(tag: DW_TAG_array_type,
 // CHECK-NOT:                               size:
-// CHECK-SAME:                              align: 32
 // CHECK-SAME:                              elements: [[ELEM_TYPE:![0-9]+]]
 // CHECK: [[ELEM_TYPE]] = !{[[SUB1:.*]], [[SUB2:.*]]}
 // CHECK: [[SUB1]] = !DISubrange(count: 3)
Index: test/CodeGenCXX/debug-info-uuid.cpp
===================================================================
--- test/CodeGenCXX/debug-info-uuid.cpp
+++ test/CodeGenCXX/debug-info-uuid.cpp
@@ -10,7 +10,6 @@
 // CHECK: [[CONST_GUID_PTR]] = !DIDerivedType(tag: DW_TAG_pointer_type
 // CHECK-SAME:                                baseType: [[CONST_GUID:![0-9]*]]
 // CHECK-SAME:                                size: 64
-// CHECK-SAME:                                align: 64
 // CHECK: [[CONST_GUID]] = !DIDerivedType(tag: DW_TAG_const_type
 // CHECK-SAME:                            baseType: [[GUID:![0-9]*]]
 // CHECK: [[GUID]] = !DICompositeType(tag: DW_TAG_structure_type, name: "_GUID"
Index: test/CodeGenCXX/debug-info-union.cpp
===================================================================
--- test/CodeGenCXX/debug-info-union.cpp
+++ test/CodeGenCXX/debug-info-union.cpp
@@ -12,7 +12,7 @@
 
 // CHECK: !DICompositeType(tag: DW_TAG_union_type, name: "E"
 // CHECK-SAME:             line: 3
-// CHECK-SAME:             size: 32, align: 32
+// CHECK-SAME:             size: 32
 // CHECK-NOT:              offset:
 // CHECK-SAME:             {{$}}
 // CHECK: !DISubprogram(name: "bb"{{.*}}, line: 6
Index: test/CodeGenCXX/debug-info-template.cpp
===================================================================
--- test/CodeGenCXX/debug-info-template.cpp
+++ test/CodeGenCXX/debug-info-template.cpp
@@ -59,7 +59,7 @@
 // CHECK: [[FARG1]] = !DIDerivedType(tag: DW_TAG_pointer_type,
 // CHECK-SAME:                       baseType: ![[FOO]]
 // CHECK-NOT:                        line:
-// CHECK-SAME:                       size: 64, align: 64
+// CHECK-SAME:                       size: 64
 // CHECK-NOT:                        offset: 0
 // CHECK-SAME:                       DIFlagArtificial
 // CHECK: [[FUNTYPE:![0-9]*]] = !DISubroutineType(types: [[FUNARGS:![0-9]*]])
@@ -150,7 +150,7 @@
 // CHECK-SAME:             templateParams: [[PTOARGS:![0-9]*]]
 // CHECK: [[PTOARGS]] = !{[[PTOARG1:![0-9]*]]}
 // CHECK: [[PTOARG1]] = !DITemplateValueParameter(type: [[CONST_PADDINGATEND_PTR:![0-9]*]], value: %struct.PaddingAtEnd* @PaddedObj)
-// CHECK: [[CONST_PADDINGATEND_PTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[PADDINGATEND]], size: 64, align: 64)
+// CHECK: [[CONST_PADDINGATEND_PTR]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[PADDINGATEND]], size: 64)
 template <PaddingAtEnd *>
 struct PaddingAtEndTemplate {
 };
Index: test/CodeGenCXX/debug-info-template-quals.cpp
===================================================================
--- test/CodeGenCXX/debug-info-template-quals.cpp
+++ test/CodeGenCXX/debug-info-template-quals.cpp
@@ -17,10 +17,10 @@
 
 // CHECK: [[P:![0-9]*]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: [[CON:![0-9]*]]
 // CHECK: [[CON]] = !DIDerivedType(tag: DW_TAG_const_type, baseType: [[CH:![0-9]*]]
-// CHECK: [[CH]] = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
+// CHECK: [[CH]] = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
 // CHECK: [[BS:.*]] = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "basic_string<char>"
 // CHECK-SAME:                         line: 4
-// CHECK-SAME:                         size: 8, align: 8
+// CHECK-SAME:                         size: 8
 // CHECK: [[TYPE:![0-9]*]] = !DISubroutineType(types: [[ARGS:.*]])
 // CHECK: [[ARGS]] = !{!{{.*}}, !{{.*}}, [[P]], [[R:.*]]}
 
Index: test/CodeGenCXX/debug-info-rvalue-ref.cpp
===================================================================
--- test/CodeGenCXX/debug-info-rvalue-ref.cpp
+++ test/CodeGenCXX/debug-info-rvalue-ref.cpp
@@ -8,5 +8,5 @@
   printf("%d\n", i);
 }
 
-// CHECK: !DIDerivedType(tag: DW_TAG_rvalue_reference_type, baseType: ![[INT:[0-9]+]], size: 64, align: 64)
+// CHECK: !DIDerivedType(tag: DW_TAG_rvalue_reference_type, baseType: ![[INT:[0-9]+]], size: 64)
 // CHECK: ![[INT]] = !DIBasicType(name: "int"
Index: test/CodeGenCXX/debug-info-ms-ptr-to-member.cpp
===================================================================
--- test/CodeGenCXX/debug-info-ms-ptr-to-member.cpp
+++ test/CodeGenCXX/debug-info-ms-ptr-to-member.cpp
@@ -45,8 +45,8 @@
 // CHECK-SAME: ){{$}}
 
 // CHECK: distinct !DIGlobalVariable(name: "ppmd", {{.*}} type: ![[ppmd:[^, ]*]], {{.*}})
-// CHECK: ![[ppmd]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[ppmd2:[^ ]*]], size: 64, align: 64)
+// CHECK: ![[ppmd]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[ppmd2:[^ ]*]], size: 64)
 // CHECK: ![[ppmd2]] = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !{{[0-9]*}}, extraData: !{{[0-9]*}}){{$}}
 // CHECK: distinct !DIGlobalVariable(name: "ppmf", {{.*}} type: ![[ppmf:[^, ]*]], {{.*}})
-// CHECK: ![[ppmf]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[ppmf2:[^ ]*]], size: 64, align: 64)
+// CHECK: ![[ppmf]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[ppmf2:[^ ]*]], size: 64)
 // CHECK: ![[ppmf2]] = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !{{[0-9]*}}, extraData: !{{[0-9]*}}){{$}}
Index: test/CodeGenCXX/debug-info-ms-bitfields.cpp
===================================================================
--- test/CodeGenCXX/debug-info-ms-bitfields.cpp
+++ test/CodeGenCXX/debug-info-ms-bitfields.cpp
@@ -7,4 +7,4 @@
   short x : 8;
 } s;
 
-// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x", {{.*}}, size: 8, align: 16, offset: 16, flags: DIFlagBitField, extraData: i64 8)
+// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x", {{.*}}, size: 8, offset: 16, flags: DIFlagBitField, extraData: i64 8)
Index: test/CodeGenCXX/debug-info-indirect-field-decl.cpp
===================================================================
--- test/CodeGenCXX/debug-info-indirect-field-decl.cpp
+++ test/CodeGenCXX/debug-info-indirect-field-decl.cpp
@@ -11,13 +11,13 @@
   // CHECK: !DIDerivedType(tag: DW_TAG_member, scope:
   // CHECK-SAME:           line: [[@LINE+4]]
   // CHECK-SAME:           baseType: ![[UNION:[0-9]+]]
-  // CHECK-SAME:           size: 32, align: 32, offset: 32
+  // CHECK-SAME:           size: 32, offset: 32
   // CHECK: ![[UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,{{.*}} identifier: "_ZTSN3BarUt_E")
   union {
     // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "i2",
     // CHECK-SAME:           line: [[@LINE+5]]
     // CHECK-SAME:           baseType: ![[INT]]
-    // CHECK-SAME:           size: 32, align: 32
+    // CHECK-SAME:           size: 32
     // CHECK-NOT:            offset:
     // CHECK-SAME:           ){{$}}
     int i2;
Index: test/CodeGenCXX/debug-info-enum-class.cpp
===================================================================
--- test/CodeGenCXX/debug-info-enum-class.cpp
+++ test/CodeGenCXX/debug-info-enum-class.cpp
@@ -13,23 +13,23 @@
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "A"
 // CHECK-SAME:             line: 3
 // CHECK-SAME:             baseType: ![[INT:[0-9]+]]
-// CHECK-SAME:             size: 32, align: 32
+// CHECK-SAME:             size: 32
 // CHECK-NOT:              offset:
 // CHECK-NOT:              flags:
 // CHECK-SAME:             ){{$}}
 // CHECK: ![[INT]] = !DIBasicType(name: "int"
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "B"
 // CHECK-SAME:             line: 4
 // CHECK-SAME:             baseType: ![[ULONG:[0-9]+]]
-// CHECK-SAME:             size: 64, align: 64
+// CHECK-SAME:             size: 64
 // CHECK-NOT:              offset:
 // CHECK-NOT:              flags:
 // CHECK-SAME:             ){{$}}
 // CHECK: ![[ULONG]] = !DIBasicType(name: "long unsigned int"
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "C"
 // CHECK-SAME:             line: 5
 // CHECK-NOT:              baseType:
-// CHECK-SAME:             size: 32, align: 32
+// CHECK-SAME:             size: 32
 // CHECK-NOT:              offset:
 // CHECK-NOT:              flags:
 // CHECK-SAME:             ){{$}}
@@ -91,7 +91,7 @@
 
 // CHECK: !DICompositeType(tag: DW_TAG_enumeration_type, name: "D"
 // CHECK-SAME:             line: 6
-// CHECK-SAME:             size: 16, align: 16
+// CHECK-SAME:             size: 16
 // CHECK-NOT:              offset:
 // CHECK-SAME:             flags: DIFlagFwdDecl
 
Index: test/CodeGenCXX/debug-info-calling-conventions.cpp
===================================================================
--- test/CodeGenCXX/debug-info-calling-conventions.cpp
+++ test/CodeGenCXX/debug-info-calling-conventions.cpp
@@ -8,7 +8,7 @@
 // CHECK: !DISubprogram(name: "thiscallcc", {{.*}} type: ![[thiscallty:[^,]*]], {{.*}})
 // CHECK: ![[thiscallty]] = !DISubroutineType(cc: DW_CC_BORLAND_thiscall, types: ![[thisargs:[^,)]*]])
 // CHECK: ![[thisargs]] = !{null, ![[thisptrty:[^,}]*]]}
-// CHECK: ![[thisptrty]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{.*}}, size: 32, align: 32, flags: DIFlagArtificial | DIFlagObjectPointer)
+// CHECK: ![[thisptrty]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !{{.*}}, size: 32, flags: DIFlagArtificial | DIFlagObjectPointer)
 
 void cdeclcc() {}
 void __fastcall fastcallcc() {}
Index: test/CodeGen/debug-info-vector.c
===================================================================
--- test/CodeGen/debug-info-vector.c
+++ test/CodeGen/debug-info-vector.c
@@ -6,6 +6,6 @@
 // Test that we get an array type that's also a vector out of debug.
 // CHECK: !DICompositeType(tag: DW_TAG_array_type,
 // CHECK-SAME:             baseType: ![[INT:[0-9]+]]
-// CHECK-SAME:             size: 128, align: 128
+// CHECK-SAME:             size: 128
 // CHECK-SAME:             DIFlagVector
 // CHECK: ![[INT]] = !DIBasicType(name: "int"
Index: test/CodeGen/debug-info-packed-struct.c
===================================================================
--- test/CodeGen/debug-info-packed-struct.c
+++ test/CodeGen/debug-info-packed-struct.c
@@ -19,9 +19,9 @@
 };
 // CHECK: l0_ofs0
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs8",
-// CHECK-SAME:     {{.*}}size: 64, align: 64, offset: 64)
+// CHECK-SAME:     {{.*}}size: 64, offset: 64)
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs16",
-// CHECK-SAME:     {{.*}}size: 1, align: 32, offset: 128, flags: DIFlagBitField, extraData: i64 128)
+// CHECK-SAME:     {{.*}}size: 1, offset: 128, flags: DIFlagBitField, extraData: i64 128)
 
 
 // ---------------------------------------------------------------------
@@ -38,9 +38,9 @@
 };
 // CHECK: l1_ofs0
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs1",
-// CHECK-SAME:     {{.*}}size: 64, align: 8, offset: 8)
+// CHECK-SAME:     {{.*}}size: 64, offset: 8)
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs9",
-// CHECK-SAME:     {{.*}}size: 1, align: 32, offset: 72, flags: DIFlagBitField, extraData: i64 72)
+// CHECK-SAME:     {{.*}}size: 1, offset: 72, flags: DIFlagBitField, extraData: i64 72)
 
 
 // ---------------------------------------------------------------------
@@ -59,9 +59,9 @@
 #pragma pack()
 // CHECK: l2_ofs0
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs1",
-// CHECK-SAME:     {{.*}}size: 64, align: 8, offset: 8)
+// CHECK-SAME:     {{.*}}size: 64, offset: 8)
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs9",
-// CHECK-SAME:     {{.*}}size: 1, align: 32, offset: 72, flags: DIFlagBitField, extraData: i64 72)
+// CHECK-SAME:     {{.*}}size: 1, offset: 72, flags: DIFlagBitField, extraData: i64 72)
 
 
 
@@ -81,9 +81,9 @@
 #pragma pack()
 // CHECK: l3_ofs0
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs4",
-// CHECK-SAME:     {{.*}}size: 64, align: 32, offset: 32)
+// CHECK-SAME:     {{.*}}size: 64, offset: 32)
 // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs12",
-// CHECK-SAME:     {{.*}}size: 1, align: 32, offset: 96, flags: DIFlagBitField, extraData: i64 96)
+// CHECK-SAME:     {{.*}}size: 1, offset: 96, flags: DIFlagBitField, extraData: i64 96)
 
 struct layout0 l0;
 struct layout1 l1;
Index: lib/CodeGen/CGDebugInfo.h
===================================================================
--- lib/CodeGen/CGDebugInfo.h
+++ lib/CodeGen/CGDebugInfo.h
@@ -238,6 +238,13 @@
                                 llvm::DIScope *scope,
                                 const RecordDecl *RD = nullptr);
 
+  llvm::DIType *createFieldType(StringRef Name, QualType Type,
+                                SourceLocation Loc, uint64_t AlignInBits,
+                                uint64_t OffsetInBits,
+                                llvm::DINode::DIFlags Flags,
+                                llvm::DIFile *TUnit, llvm::DIScope *Scope,
+                                const RecordDecl *RD = nullptr);
+
   /// Create new bit field member.
   llvm::DIType *createBitFieldType(const FieldDecl *BitFieldDecl,
                                    llvm::DIScope *RecordTy,
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -594,9 +594,8 @@
     BTName = BT->getName(CGM.getLangOpts());
     break;
   }
-  // Bit size, align and offset of the type.
   uint64_t Size = CGM.getContext().getTypeSize(BT);
-  uint64_t Align = CGM.getContext().getTypeAlign(BT);
+  uint64_t Align = 0;
   return DBuilder.createBasicType(BTName, Size, Align, Encoding);
 }
 
@@ -607,7 +606,7 @@
     Encoding = llvm::dwarf::DW_ATE_lo_user;
 
   uint64_t Size = CGM.getContext().getTypeSize(Ty);
-  uint64_t Align = CGM.getContext().getTypeAlign(Ty);
+  uint64_t Align = 0;
   return DBuilder.createBasicType("complex", Size, Align, Encoding);
 }
 
@@ -726,7 +725,8 @@
   const RecordDecl *D = RD->getDefinition();
   if (D && D->isCompleteDefinition()) {
     Size = CGM.getContext().getTypeSize(Ty);
-    Align = CGM.getContext().getTypeAlign(Ty);
+    if (D->hasAttr<AlignedAttr>())
+      Align = CGM.getContext().getTypeAlign(Ty);
   }
 
   // Create the type.
@@ -749,7 +749,7 @@
   // because that does not return the correct value for references.
   unsigned AS = CGM.getContext().getTargetAddressSpace(PointeeTy);
   uint64_t Size = CGM.getTarget().getPointerWidth(AS);
-  uint64_t Align = CGM.getContext().getTypeAlign(Ty);
+  uint64_t Align = 0;
 
   if (Tag == llvm::dwarf::DW_TAG_reference_type ||
       Tag == llvm::dwarf::DW_TAG_rvalue_reference_type)
@@ -776,7 +776,7 @@
   SmallVector<llvm::Metadata *, 8> EltTys;
   QualType FType;
   uint64_t FieldSize, FieldOffset;
-  unsigned FieldAlign;
+  uint64_t FieldAlign = 0;
   llvm::DINodeArray Elements;
 
   FieldOffset = 0;
@@ -810,7 +810,6 @@
 
   FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
   FieldSize = CGM.getContext().getTypeSize(Ty);
-  FieldAlign = CGM.getContext().getTypeAlign(Ty);
   EltTys.push_back(DBuilder.createMemberType(
       Unit, "__descriptor", nullptr, LineNo, FieldSize, FieldAlign, FieldOffset,
       llvm::DINode::FlagZero, DescTy));
@@ -965,13 +964,12 @@
       CGM.getTypes().getCGRecordLayout(RD).getBitFieldInfo(BitFieldDecl);
   uint64_t SizeInBits = BitFieldInfo.Size;
   assert(SizeInBits > 0 && "found named 0-width bitfield");
-  unsigned AlignInBits = CGM.getContext().getTypeAlign(Ty);
   uint64_t StorageOffsetInBits =
       CGM.getContext().toBits(BitFieldInfo.StorageOffset);
   uint64_t OffsetInBits = StorageOffsetInBits + BitFieldInfo.Offset;
   llvm::DINode::DIFlags Flags = getAccessFlag(BitFieldDecl->getAccess(), RD);
   return DBuilder.createBitFieldMemberType(
-      RecordTy, Name, File, Line, SizeInBits, AlignInBits, OffsetInBits,
+      RecordTy, Name, File, Line, SizeInBits, OffsetInBits,
       StorageOffsetInBits, Flags, DebugType);
 }
 
@@ -991,14 +989,35 @@
   if (!type->isIncompleteArrayType()) {
     TypeInfo TI = CGM.getContext().getTypeInfo(type);
     SizeInBits = TI.Width;
-    AlignInBits = TI.Align;
   }
 
   llvm::DINode::DIFlags flags = getAccessFlag(AS, RD);
   return DBuilder.createMemberType(scope, name, file, line, SizeInBits,
                                    AlignInBits, offsetInBits, flags, debugType);
 }
 
+llvm::DIType *
+CGDebugInfo::createFieldType(StringRef Name, QualType Type, SourceLocation Loc,
+                             uint64_t AlignInBits, uint64_t OffsetInBits,
+                             llvm::DINode::DIFlags Flags,
+                             llvm::DIFile *TUnit, llvm::DIScope *Scope,
+                             const RecordDecl *RD) {
+  llvm::DIType *DebugType = getOrCreateType(Type, TUnit);
+
+  // Get the location for the field.
+  llvm::DIFile *File = getOrCreateFile(Loc);
+  unsigned Line = getLineNumber(Loc);
+
+  uint64_t SizeInBits = 0;
+  if (!Type->isIncompleteArrayType()) {
+    TypeInfo TI = CGM.getContext().getTypeInfo(Type);
+    SizeInBits = TI.Width;
+  }
+
+  return DBuilder.createMemberType(Scope, Name, File, Line, SizeInBits,
+                                   AlignInBits, OffsetInBits, Flags, DebugType);
+}
+
 void CGDebugInfo::CollectRecordLambdaFields(
     const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements,
     llvm::DIType *RecordTy) {
@@ -1012,15 +1031,20 @@
                                              E = CXXDecl->captures_end();
        I != E; ++I, ++Field, ++fieldno) {
     const LambdaCapture &C = *I;
+    uint64_t AlignInBits = 0;
+    llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
     if (C.capturesVariable()) {
       SourceLocation Loc = C.getLocation();
       assert(!Field->isBitField() && "lambdas don't have bitfield members!");
       VarDecl *V = C.getCapturedVar();
       StringRef VName = V->getName();
+      Flags |= getAccessFlag(Field->getAccess(), CXXDecl);
+      if (V->hasAttr<AlignedAttr>())
+        AlignInBits = V->getMaxAlignment();
       llvm::DIFile *VUnit = getOrCreateFile(Loc);
       llvm::DIType *FieldType = createFieldType(
-          VName, Field->getType(), Loc, Field->getAccess(),
-          layout.getFieldOffset(fieldno), VUnit, RecordTy, CXXDecl);
+          VName, Field->getType(), Loc, AlignInBits,
+          layout.getFieldOffset(fieldno), Flags, VUnit, RecordTy, CXXDecl);
       elements.push_back(FieldType);
     } else if (C.capturesThis()) {
       // TODO: Need to handle 'this' in some way by probably renaming the
@@ -1061,9 +1085,12 @@
     }
   }
 
+  uint64_t AlignInBits = 0;
   llvm::DINode::DIFlags Flags = getAccessFlag(Var->getAccess(), RD);
+  if (Var->hasAttr<AlignedAttr>())
+    AlignInBits = Var->getMaxAlignment();
   llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
-      RecordTy, VName, VUnit, LineNumber, VTy, Flags, C);
+      RecordTy, VName, VUnit, LineNumber, VTy, AlignInBits, Flags, C);
   StaticDataMemberCache[Var->getCanonicalDecl()].reset(GV);
   return GV;
 }
@@ -1074,6 +1101,10 @@
     const RecordDecl *RD) {
   StringRef name = field->getName();
   QualType type = field->getType();
+  uint64_t AlignInBits = 0;
+  llvm::DINode::DIFlags Flags = getAccessFlag(field->getAccess(), RD);
+  if (field->hasAttr<AlignedAttr>())
+    AlignInBits = field->getMaxAlignment();
 
   // Ignore unnamed fields unless they're anonymous structs/unions.
   if (name.empty() && !type->isRecordType())
@@ -1084,8 +1115,8 @@
     FieldType = createBitFieldType(field, RecordTy, RD);
   } else {
     FieldType =
-        createFieldType(name, type, field->getLocation(), field->getAccess(),
-                        OffsetInBits, tunit, RecordTy, RD);
+        createFieldType(name, type, field->getLocation(), AlignInBits,
+                        OffsetInBits, Flags, tunit, RecordTy, RD);
   }
 
   elements.push_back(FieldType);
@@ -1181,7 +1212,9 @@
     QualType PointeeTy = ThisPtrTy->getPointeeType();
     unsigned AS = CGM.getContext().getTargetAddressSpace(PointeeTy);
     uint64_t Size = CGM.getTarget().getPointerWidth(AS);
-    uint64_t Align = CGM.getContext().getTypeAlign(ThisPtrTy);
+    uint64_t Align = 0;
+    if (RD->hasAttr<AlignedAttr>())
+      Align = CGM.getContext().getTypeAlign(ThisPtrTy);
     llvm::DIType *PointeeType = getOrCreateType(PointeeTy, Unit);
     llvm::DIType *ThisPtrType =
         DBuilder.createPointerType(PointeeType, Size, Align);
@@ -1967,11 +2000,13 @@
 
   // Bit size, align and offset of the type.
   uint64_t Size = CGM.getContext().getTypeSize(Ty);
-  uint64_t Align = CGM.getContext().getTypeAlign(Ty);
+  uint64_t Align = 0;
 
   llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
   if (ID->getImplementation())
     Flags |= llvm::DINode::FlagObjcClassComplete;
+  if (ID->hasAttr<AlignedAttr>())
+    Align = CGM.getContext().getTypeAlign(Ty);
 
   llvm::DIScope *Mod = getParentModuleOrNull(ID);
   llvm::DICompositeType *RealDecl = DBuilder.createStructType(
@@ -2053,14 +2088,10 @@
     uint64_t FieldSize = 0;
     unsigned FieldAlign = 0;
 
-    if (!FType->isIncompleteArrayType()) {
-
-      // Bit size, align and offset of the type.
+    if (!FType->isIncompleteArrayType())
       FieldSize = Field->isBitField()
                       ? Field->getBitWidthValue(CGM.getContext())
                       : CGM.getContext().getTypeSize(FType);
-      FieldAlign = CGM.getContext().getTypeAlign(FType);
-    }
 
     uint64_t FieldOffset;
     if (CGM.getLangOpts().ObjCRuntime.isNonFragile()) {
@@ -2086,6 +2117,9 @@
     else if (Field->getAccessControl() == ObjCIvarDecl::Public)
       Flags = llvm::DINode::FlagPublic;
 
+    if (Field->hasAttr<AlignedAttr>())
+      FieldAlign = CGM.getContext().getTypeAlign(FType);
+
     llvm::MDNode *PropertyNode = nullptr;
     if (ObjCImplementationDecl *ImpD = ID->getImplementation()) {
       if (ObjCPropertyImplDecl *PImpD =
@@ -2133,34 +2167,19 @@
   llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
 
   uint64_t Size = CGM.getContext().getTypeSize(Ty);
-  uint64_t Align = CGM.getContext().getTypeAlign(Ty);
-
+  uint64_t Align = 0;
   return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
 }
 
 llvm::DIType *CGDebugInfo::CreateType(const ArrayType *Ty, llvm::DIFile *Unit) {
-  uint64_t Size;
-  uint64_t Align;
+  uint64_t Size = 0;
+  uint64_t Align = 0;
 
   // FIXME: make getTypeAlign() aware of VLAs and incomplete array types
-  if (const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
-    Size = 0;
-    Align =
-        CGM.getContext().getTypeAlign(CGM.getContext().getBaseElementType(VAT));
-  } else if (Ty->isIncompleteArrayType()) {
-    Size = 0;
-    if (Ty->getElementType()->isIncompleteType())
-      Align = 0;
-    else
-      Align = CGM.getContext().getTypeAlign(Ty->getElementType());
-  } else if (Ty->isIncompleteType()) {
-    Size = 0;
-    Align = 0;
-  } else {
-    // Size and align of the whole array, not the element type.
+  if (nullptr == dyn_cast<VariableArrayType>(Ty) &&
+      !Ty->isIncompleteArrayType() &&
+      !Ty->isIncompleteType())
     Size = CGM.getContext().getTypeSize(Ty);
-    Align = CGM.getContext().getTypeAlign(Ty);
-  }
 
   // Add the dimensions of the array.  FIXME: This loses CV qualifiers from
   // interior arrays, do we care?  Why aren't nested arrays represented the
@@ -2266,7 +2285,8 @@
   uint64_t Align = 0;
   if (!ED->getTypeForDecl()->isIncompleteType()) {
     Size = CGM.getContext().getTypeSize(ED->getTypeForDecl());
-    Align = CGM.getContext().getTypeAlign(ED->getTypeForDecl());
+      if (ED->hasAttr<AlignedAttr>())
+        Align = CGM.getContext().getTypeAlign(ED->getTypeForDecl());
   }
 
   SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
@@ -2287,12 +2307,13 @@
     llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
     llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
         llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0));
+    llvm::DINode::DIFlags Flags = llvm::DINode::FlagFwdDecl;
 
     unsigned Line = getLineNumber(ED->getLocation());
     StringRef EDName = ED->getName();
     llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
         llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit, Line,
-        0, Size, Align, llvm::DINode::FlagFwdDecl, FullName);
+        0, Size, Align, Flags, FullName);
 
     ReplaceMap.emplace_back(
         std::piecewise_construct, std::make_tuple(Ty),
@@ -2307,9 +2328,11 @@
   const EnumDecl *ED = Ty->getDecl();
   uint64_t Size = 0;
   uint64_t Align = 0;
+  llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
   if (!ED->getTypeForDecl()->isIncompleteType()) {
     Size = CGM.getContext().getTypeSize(ED->getTypeForDecl());
-    Align = CGM.getContext().getTypeAlign(ED->getTypeForDecl());
+    if (ED->hasAttr<AlignedAttr>())
+      Align = CGM.getContext().getTypeAlign(ED->getTypeForDecl());
   }
 
   SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
@@ -2331,8 +2354,8 @@
   llvm::DIType *ClassTy =
       ED->isFixed() ? getOrCreateType(ED->getIntegerType(), DefUnit) : nullptr;
   return DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit,
-                                        Line, Size, Align, EltArray, ClassTy,
-                                        FullName);
+                                        Line, Size, Align, Flags, EltArray,
+                                        ClassTy, FullName);
 }
 
 static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C) {
@@ -2604,13 +2627,16 @@
     return getOrCreateRecordFwdDecl(Ty, RDContext);
 
   uint64_t Size = CGM.getContext().getTypeSize(Ty);
-  uint64_t Align = CGM.getContext().getTypeAlign(Ty);
+  uint64_t Align = 0;
+  llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
+  if (RD->hasAttr<AlignedAttr>())
+    Align = CGM.getContext().getTypeAlign(Ty);
 
   SmallString<256> FullName = getUniqueTagTypeName(Ty, CGM, TheCU);
 
   llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
       getTagForRecord(RD), RDName, RDContext, DefUnit, Line, 0, Size, Align,
-      llvm::DINode::FlagZero, FullName);
+      Flags, FullName);
 
   // Elements of composite types usually have back to the type, creating
   // uniquing cycles.  Distinct nodes are more efficient.
@@ -2673,9 +2699,8 @@
                                             StringRef Name, uint64_t *Offset) {
   llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
   uint64_t FieldSize = CGM.getContext().getTypeSize(FType);
-  unsigned FieldAlign = CGM.getContext().getTypeAlign(FType);
   llvm::DIType *Ty =
-      DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, FieldAlign,
+      DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, /* Align */ 0,
                                 *Offset, llvm::DINode::FlagZero, FieldTy);
   *Offset += FieldSize;
   return Ty;
@@ -2805,11 +2830,16 @@
   llvm::DIFile *Unit = getOrCreateFile(Loc);
   llvm::DIScope *DContext = Unit;
   unsigned Line = getLineNumber(Loc);
+  llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
+  uint64_t AlignInBits = 0;
+
+  if (VD->hasAttr<AlignedAttr>())
+    AlignInBits = VD->getMaxAlignment();
 
   collectVarDeclProps(VD, Unit, Line, T, Name, LinkageName, DContext);
   auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
       DContext, Name, LinkageName, Unit, Line, getOrCreateType(T, Unit),
-      !VD->isExternallyVisible(), nullptr, nullptr);
+      !VD->isExternallyVisible(), AlignInBits, Flags, nullptr, nullptr);
   FwdDeclReplaceMap.emplace_back(
       std::piecewise_construct,
       std::make_tuple(cast<VarDecl>(VD->getCanonicalDecl())),
@@ -3134,7 +3164,7 @@
   SmallVector<llvm::Metadata *, 5> EltTys;
   QualType FType;
   uint64_t FieldSize, FieldOffset;
-  unsigned FieldAlign;
+  uint64_t FieldAlign = 0;
 
   llvm::DIFile *Unit = getOrCreateFile(VD->getLocation());
   QualType Type = VD->getType();
@@ -3184,12 +3214,14 @@
   FType = Type;
   llvm::DIType *FieldTy = getOrCreateType(FType, Unit);
   FieldSize = CGM.getContext().getTypeSize(FType);
-  FieldAlign = CGM.getContext().toBits(Align);
+  llvm::DINode::DIFlags FieldFlags = llvm::DINode::FlagZero;
+  if (VD->hasAttr<AlignedAttr>())
+    FieldAlign = CGM.getContext().toBits(Align);
 
   *XOffset = FieldOffset;
   FieldTy = DBuilder.createMemberType(Unit, VD->getName(), Unit, 0, FieldSize,
-                                      FieldAlign, FieldOffset,
-                                      llvm::DINode::FlagZero, FieldTy);
+                                      FieldAlign, FieldOffset, FieldFlags,
+                                      FieldTy);
   EltTys.push_back(FieldTy);
   FieldOffset += FieldSize;
 
@@ -3235,9 +3267,13 @@
     Column = getColumnNumber(VD->getLocation());
   }
   SmallVector<int64_t, 9> Expr;
+  uint64_t AlignInBits = 0;
   llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
   if (VD->isImplicit())
     Flags |= llvm::DINode::FlagArtificial;
+  if (VD->hasAttr<AlignedAttr>())
+    AlignInBits = VD->getMaxAlignment();
+
   // If this is the first argument and it is implicit then
   // give it an object pointer flag.
   // FIXME: There has to be a better way to do this, but for static
@@ -3272,7 +3308,9 @@
                     ? DBuilder.createParameterVariable(Scope, VD->getName(),
                                                        *ArgNo, Unit, Line, Ty)
                     : DBuilder.createAutoVariable(Scope, VD->getName(), Unit,
-                                                  Line, Ty);
+                                                  Line, Ty,
+                                                  /* AlwaysPreserve */ false,
+                                                  AlignInBits, Flags);
 
       // Insert an llvm.dbg.declare into the current block.
       DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
@@ -3304,7 +3342,7 @@
         // Use VarDecl's Tag, Scope and Line number.
         auto *D = DBuilder.createAutoVariable(
             Scope, FieldName, Unit, Line, FieldTy, CGM.getLangOpts().Optimize,
-            Flags | llvm::DINode::FlagArtificial);
+            AlignInBits, Flags | llvm::DINode::FlagArtificial);
 
         // Insert an llvm.dbg.declare into the current block.
         DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
@@ -3321,7 +3359,8 @@
                                              Ty, CGM.getLangOpts().Optimize,
                                              Flags)
           : DBuilder.createAutoVariable(Scope, Name, Unit, Line, Ty,
-                                        CGM.getLangOpts().Optimize, Flags);
+                                        CGM.getLangOpts().Optimize,
+                                        AlignInBits, Flags);
 
   // Insert an llvm.dbg.declare into the current block.
   DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
@@ -3374,6 +3413,11 @@
   unsigned Line = getLineNumber(VD->getLocation());
   unsigned Column = getColumnNumber(VD->getLocation());
 
+  llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
+  uint64_t Align = 0;
+  if (VD->hasAttr<AlignedAttr>())
+    Align = VD->getMaxAlignment();
+
   const llvm::DataLayout &target = CGM.getDataLayout();
 
   CharUnits offset = CharUnits::fromQuantity(
@@ -3402,7 +3446,7 @@
   // Create the descriptor for the variable.
   auto *D = DBuilder.createAutoVariable(
       cast<llvm::DILocalScope>(LexicalBlockStack.back()), VD->getName(), Unit,
-      Line, Ty);
+      Line, Ty, /* AlwaysPreserve */ false, Align, Flags);
 
   // Insert an llvm.dbg.declare into the current block.
   auto DL = llvm::DebugLoc::get(Line, Column, LexicalBlockStack.back());
@@ -3537,7 +3581,7 @@
       fieldType = EmitTypeForVarWithBlocksAttr(variable, &xoffset);
       fieldType = DBuilder.createPointerType(fieldType, PtrInfo.Width);
       fieldType = DBuilder.createMemberType(
-          tunit, name, tunit, line, PtrInfo.Width, PtrInfo.Align, offsetInBits,
+          tunit, name, tunit, line, PtrInfo.Width, /* Align */ 0, offsetInBits,
           llvm::DINode::FlagZero, fieldType);
     } else {
       fieldType = createFieldType(name, variable->getType(), loc, AS_public,
@@ -3555,8 +3599,8 @@
   llvm::DIType *type =
       DBuilder.createStructType(tunit, typeName.str(), tunit, line,
                                 CGM.getContext().toBits(block.BlockSize),
-                                CGM.getContext().toBits(block.BlockAlign),
-                                llvm::DINode::FlagZero, nullptr, fieldsArray);
+                                /* Align */ 0, llvm::DINode::FlagZero, nullptr,
+                                fieldsArray);
   type = DBuilder.createPointerType(type, CGM.PointerWidthInBits);
 
   // Get overall information about the block.
@@ -3615,10 +3659,19 @@
                                     Var, DContext);
       continue;
     }
+
+    llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
+    uint64_t AlignInBits = 0;
+    if (Field->hasAttr<AlignedAttr>()) {
+      auto Q = Var->getAlignment();
+      if (Q)
+        AlignInBits = RD->getASTContext().toBits(CharUnits::fromQuantity(Q));
+    }
+
     // Use VarDecl's Tag, Scope and Line number.
     GV = DBuilder.createGlobalVariable(DContext, FieldName, LinkageName, Unit,
-                                       LineNo, FieldTy,
-                                       Var->hasLocalLinkage(), Var, nullptr);
+                                       LineNo, FieldTy, Var->hasLocalLinkage(),
+                                       AlignInBits, Flags, Var, nullptr);
   }
   return GV;
 }
@@ -3632,6 +3685,10 @@
   llvm::DIFile *Unit = nullptr;
   llvm::DIScope *DContext = nullptr;
   unsigned LineNo;
+  llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
+  uint64_t AlignInBits = 0;
+  if (D->hasAttr<AlignedAttr>())
+    AlignInBits = D->getMaxAlignment();
   StringRef DeclName, LinkageName;
   QualType T;
   collectVarDeclProps(D, Unit, LineNo, T, DeclName, LinkageName, DContext);
@@ -3651,7 +3708,7 @@
   } else {
     GV = DBuilder.createGlobalVariable(
         DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
-        Var->hasLocalLinkage(), Var,
+        Var->hasLocalLinkage(), AlignInBits, Flags, Var,
         getOrCreateStaticDataMemberDeclarationOrNull(D));
   }
   DeclCache[D->getCanonicalDecl()].reset(GV);
@@ -3698,9 +3755,15 @@
   auto &GV = DeclCache[VD];
   if (GV)
     return;
+
+  uint64_t AlignInBits = 0;
+  llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
+  if (VD->hasAttr<AlignedAttr>())
+    AlignInBits = VD->getMaxAlignment();
   GV.reset(DBuilder.createGlobalVariable(
       DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
-      true, Init, getOrCreateStaticDataMemberDeclarationOrNull(VarD)));
+      true, AlignInBits, Flags, Init,
+      getOrCreateStaticDataMemberDeclarationOrNull(VarD)));
 }
 
 llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(const Decl *D) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to