Commit 423f541c authored by Sourabh Singh Tomar's avatar Sourabh Singh Tomar
Browse files

[DWARF5]Addition of alignment atrribute in typedef DIE.

This patch, adds support for DW_AT_alignment[DWARF5] attribute, to be emitted with typdef DIE.
When explicit alignment is specified.

Patch by Awanish Pandey <Awanish.Pandey@amd.com>

Reviewers: aprantl, dblaikie, jini.susan.george, SouraVX, alok,
deadalinx

Differential Revision: https://reviews.llvm.org/D70111
parent a7f97b02
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -1127,7 +1127,8 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,
  SourceLocation Loc = AliasDecl->getLocation();
  return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),
                                getLineNumber(Loc),
                                getDeclContextDescriptor(AliasDecl));
                                getDeclContextDescriptor(AliasDecl),
                                /* Alignment */ None);
}

llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
@@ -1143,9 +1144,10 @@ llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
  SourceLocation Loc = Ty->getDecl()->getLocation();

  // Typedefs are derived from some other type.
  return DBuilder.createTypedef(Underlying, Ty->getDecl()->getName(),
                                getOrCreateFile(Loc), getLineNumber(Loc),
                                getDeclContextDescriptor(Ty->getDecl()));
  return DBuilder.createTypedef(
      Underlying, Ty->getDecl()->getName(), getOrCreateFile(Loc),
      getLineNumber(Loc), getDeclContextDescriptor(Ty->getDecl()),
      getDeclAlignIfRequired(Ty->getDecl(), CGM.getContext()));
}

static unsigned getDwarfCC(CallingConv CC) {
@@ -2324,7 +2326,8 @@ llvm::DIType *CGDebugInfo::CreateType(const ObjCTypeParamType *Ty,
  return DBuilder.createTypedef(
      getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit),
      Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc),
      getDeclContextDescriptor(Ty->getDecl()));
      getDeclContextDescriptor(Ty->getDecl()),
      /* Alignment */ None);
}

/// \return true if Getter has the default name for the property PD.
+14 −0
Original line number Diff line number Diff line
//  Test for debug info related to DW_AT_alignment attribute in the typedef operator
// Supported: -O0, standalone DI
// RUN: %clang_cc1 -dwarf-version=5  -emit-llvm -triple x86_64-linux-gnu %s -o - \
// RUN:   -O0 -disable-llvm-passes \
// RUN:   -debug-info-kind=standalone \
// RUN: | FileCheck %s

// CHECK: DIDerivedType(tag: DW_TAG_typedef, {{.*}}, align: 512

typedef char __attribute__((__aligned__(64))) alchar;

int main() {
  alchar newChar;
}
+1 −1
Original line number Diff line number Diff line
@@ -875,7 +875,7 @@ LLVMMetadataRef
LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
                           const char *Name, size_t NameLen,
                           LLVMMetadataRef File, unsigned LineNo,
                           LLVMMetadataRef Scope);
                           LLVMMetadataRef Scope, uint32_t AlignInBits);

/**
 * Create debugging information entry to establish inheritance relationship
+3 −1
Original line number Diff line number Diff line
@@ -237,8 +237,10 @@ namespace llvm {
    /// \param File        File where this type is defined.
    /// \param LineNo      Line number.
    /// \param Context     The surrounding context for the typedef.
    /// \param AlignInBits Alignment. (Optional)
    DIDerivedType *createTypedef(DIType *Ty, StringRef Name, DIFile *File,
                                 unsigned LineNo, DIScope *Context);
                                 unsigned LineNo, DIScope *Context,
                                 Optional<unsigned> AlignInBits = {});

    /// Create debugging information entry for a 'friend'.
    DIDerivedType *createFriend(DIType *Ty, DIType *FriendTy);
+9 −0
Original line number Diff line number Diff line
@@ -800,6 +800,15 @@ void DwarfUnit::constructTypeDIE(DIE &Buffer, const DIDerivedType *DTy) {
  if (!Name.empty())
    addString(Buffer, dwarf::DW_AT_name, Name);

  // If alignment is specified for a typedef , create and insert DW_AT_alignment
  // attribute in DW_TAG_typedef DIE.
  if (Tag == dwarf::DW_TAG_typedef && DD->getDwarfVersion() >= 5) {
    uint32_t AlignInBytes = DTy->getAlignInBytes();
    if (AlignInBytes > 0)
      addUInt(Buffer, dwarf::DW_AT_alignment, dwarf::DW_FORM_udata,
              AlignInBytes);
  }

  // Add size if non-zero (derived types might be zero-sized.)
  if (Size && Tag != dwarf::DW_TAG_pointer_type
           && Tag != dwarf::DW_TAG_ptr_to_member_type
Loading