1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

DebugInfo: preparation to implement DW_AT_alignment

- Add alignment attribute to DIVariable family
 - Modify bitcode format to match new DIVariable representation
 - Update tests to match these changes (also add bitcode upgrade test)
 - Expect that frontend passes non-zero align value only when it is not default
   (was forcibly aligned by alignas()/_Alignas()/__atribute__(aligned())

Differential Revision: https://reviews.llvm.org/D25073

llvm-svn: 284678
This commit is contained in:
Victor Leschuk 2016-10-20 00:13:12 +00:00
parent 2b46636b65
commit dc86c51611
22 changed files with 329 additions and 188 deletions

View File

@ -120,10 +120,9 @@ namespace llvm {
/// type. /// type.
/// \param Name Type name. /// \param Name Type name.
/// \param SizeInBits Size of the type. /// \param SizeInBits Size of the type.
/// \param AlignInBits Type alignment.
/// \param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float. /// \param Encoding DWARF encoding code, e.g. dwarf::DW_ATE_float.
DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits, DIBasicType *createBasicType(StringRef Name, uint64_t SizeInBits,
uint32_t AlignInBits, unsigned Encoding); unsigned Encoding);
/// Create debugging information entry for a qualified /// Create debugging information entry for a qualified
/// type, e.g. 'const int'. /// type, e.g. 'const int'.
@ -209,7 +208,7 @@ namespace llvm {
/// \param Ty Parent type. /// \param Ty Parent type.
DIDerivedType *createBitFieldMemberType( DIDerivedType *createBitFieldMemberType(
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo, DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNo,
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, uint64_t SizeInBits, uint64_t OffsetInBits,
uint64_t StorageOffsetInBits, DINode::DIFlags Flags, DIType *Ty); uint64_t StorageOffsetInBits, DINode::DIFlags Flags, DIType *Ty);
/// Create debugging information entry for a /// Create debugging information entry for a
@ -221,10 +220,12 @@ namespace llvm {
/// \param Ty Type of the static member. /// \param Ty Type of the static member.
/// \param Flags Flags to encode member attribute, e.g. private. /// \param Flags Flags to encode member attribute, e.g. private.
/// \param Val Const initializer of the member. /// \param Val Const initializer of the member.
/// \param AlignInBits Member alignment.
DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name, DIDerivedType *createStaticMemberType(DIScope *Scope, StringRef Name,
DIFile *File, unsigned LineNo, DIFile *File, unsigned LineNo,
DIType *Ty, DINode::DIFlags Flags, DIType *Ty, DINode::DIFlags Flags,
llvm::Constant *Val); llvm::Constant *Val,
uint32_t AlignInBits = 0);
/// Create debugging information entry for Objective-C /// Create debugging information entry for Objective-C
/// instance variable. /// instance variable.
@ -458,19 +459,22 @@ namespace llvm {
/// \param Expr The location of the global relative to the attached /// \param Expr The location of the global relative to the attached
/// GlobalVariable. /// GlobalVariable.
/// \param Decl Reference to the corresponding declaration. /// \param Decl Reference to the corresponding declaration.
/// \param AlignInBits Variable alignment(or 0 if no alignment attr was
/// specified)
DIGlobalVariable *createGlobalVariable(DIScope *Context, StringRef Name, DIGlobalVariable *createGlobalVariable(DIScope *Context, StringRef Name,
StringRef LinkageName, DIFile *File, StringRef LinkageName, DIFile *File,
unsigned LineNo, DIType *Ty, unsigned LineNo, DIType *Ty,
bool isLocalToUnit, bool isLocalToUnit,
DIExpression *Expr = nullptr, DIExpression *Expr = nullptr,
MDNode *Decl = nullptr); MDNode *Decl = nullptr,
uint32_t AlignInBits = 0);
/// Identical to createGlobalVariable /// Identical to createGlobalVariable
/// except that the resulting DbgNode is temporary and meant to be RAUWed. /// except that the resulting DbgNode is temporary and meant to be RAUWed.
DIGlobalVariable *createTempGlobalVariableFwdDecl( DIGlobalVariable *createTempGlobalVariableFwdDecl(
DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File,
unsigned LineNo, DIType *Ty, bool isLocalToUnit, DIExpression *Expr, unsigned LineNo, DIType *Ty, bool isLocalToUnit, DIExpression *Expr,
MDNode *Decl = nullptr); MDNode *Decl = nullptr, uint32_t AlignInBits = 0);
/// Create a new descriptor for an auto variable. This is a local variable /// Create a new descriptor for an auto variable. This is a local variable
/// that is not a subprogram parameter. /// that is not a subprogram parameter.
@ -483,7 +487,8 @@ namespace llvm {
DILocalVariable * DILocalVariable *
createAutoVariable(DIScope *Scope, StringRef Name, DIFile *File, createAutoVariable(DIScope *Scope, StringRef Name, DIFile *File,
unsigned LineNo, DIType *Ty, bool AlwaysPreserve = false, unsigned LineNo, DIType *Ty, bool AlwaysPreserve = false,
DINode::DIFlags Flags = DINode::FlagZero); DINode::DIFlags Flags = DINode::FlagZero,
uint32_t AlignInBits = 0);
/// Create a new descriptor for a parameter variable. /// Create a new descriptor for a parameter variable.
/// ///

View File

@ -549,7 +549,8 @@ public:
unsigned getLine() const { return Line; } unsigned getLine() const { return Line; }
uint64_t getSizeInBits() const { return SizeInBits; } uint64_t getSizeInBits() const { return SizeInBits; }
uint64_t getAlignInBits() const { return AlignInBits; } uint32_t getAlignInBits() const { return AlignInBits; }
uint32_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
uint64_t getOffsetInBits() const { return OffsetInBits; } uint64_t getOffsetInBits() const { return OffsetInBits; }
DIFlags getFlags() const { return Flags; } DIFlags getFlags() const { return Flags; }
@ -1826,11 +1827,13 @@ public:
/// \brief Base class for variables. /// \brief Base class for variables.
class DIVariable : public DINode { class DIVariable : public DINode {
unsigned Line; unsigned Line;
uint64_t AlignInBits;
protected: protected:
DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Line, DIVariable(LLVMContext &C, unsigned ID, StorageType Storage, unsigned Line,
ArrayRef<Metadata *> Ops) ArrayRef<Metadata *> Ops, uint64_t AlignInBits = 0)
: DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line) {} : DINode(C, ID, Storage, dwarf::DW_TAG_variable, Ops), Line(Line),
AlignInBits(AlignInBits) {}
~DIVariable() = default; ~DIVariable() = default;
public: public:
@ -1839,6 +1842,8 @@ public:
StringRef getName() const { return getStringOperand(1); } StringRef getName() const { return getStringOperand(1); }
DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); } DIFile *getFile() const { return cast_or_null<DIFile>(getRawFile()); }
DITypeRef getType() const { return DITypeRef(getRawType()); } DITypeRef getType() const { return DITypeRef(getRawType()); }
uint64_t getAlignInBits() const { return AlignInBits; }
uint64_t getAlignInBytes() const { return getAlignInBits() / CHAR_BIT; }
StringRef getFilename() const { StringRef getFilename() const {
if (auto *F = getFile()) if (auto *F = getFile())
@ -2026,9 +2031,9 @@ class DIGlobalVariable : public DIVariable {
bool IsDefinition; bool IsDefinition;
DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line, DIGlobalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
bool IsLocalToUnit, bool IsDefinition, bool IsLocalToUnit, bool IsDefinition, uint64_t AlignInBits,
ArrayRef<Metadata *> Ops) ArrayRef<Metadata *> Ops)
: DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops), : DIVariable(C, DIGlobalVariableKind, Storage, Line, Ops, AlignInBits),
IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {} IsLocalToUnit(IsLocalToUnit), IsDefinition(IsDefinition) {}
~DIGlobalVariable() = default; ~DIGlobalVariable() = default;
@ -2036,42 +2041,48 @@ class DIGlobalVariable : public DIVariable {
getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name, getImpl(LLVMContext &Context, DIScope *Scope, StringRef Name,
StringRef LinkageName, DIFile *File, unsigned Line, DITypeRef Type, StringRef LinkageName, DIFile *File, unsigned Line, DITypeRef Type,
bool IsLocalToUnit, bool IsDefinition, DIExpression *Expr, bool IsLocalToUnit, bool IsDefinition, DIExpression *Expr,
DIDerivedType *StaticDataMemberDeclaration, StorageType Storage, DIDerivedType *StaticDataMemberDeclaration, uint64_t AlignInBits,
bool ShouldCreate = true) { StorageType Storage, bool ShouldCreate = true) {
return getImpl(Context, Scope, getCanonicalMDString(Context, Name), return getImpl(Context, Scope, getCanonicalMDString(Context, Name),
getCanonicalMDString(Context, LinkageName), File, Line, Type, getCanonicalMDString(Context, LinkageName), File, Line, Type,
IsLocalToUnit, IsDefinition, Expr, IsLocalToUnit, IsDefinition, Expr,
StaticDataMemberDeclaration, Storage, ShouldCreate); StaticDataMemberDeclaration, AlignInBits, Storage,
ShouldCreate);
} }
static DIGlobalVariable * static DIGlobalVariable *
getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name, getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type, MDString *LinkageName, Metadata *File, unsigned Line, Metadata *Type,
bool IsLocalToUnit, bool IsDefinition, Metadata *Expr, bool IsLocalToUnit, bool IsDefinition, Metadata *Expr,
Metadata *StaticDataMemberDeclaration, StorageType Storage, Metadata *StaticDataMemberDeclaration, uint64_t AlignInBits,
bool ShouldCreate = true); StorageType Storage, bool ShouldCreate = true);
TempDIGlobalVariable cloneImpl() const { TempDIGlobalVariable cloneImpl() const {
return getTemporary(getContext(), getScope(), getName(), getLinkageName(), return getTemporary(getContext(), getScope(), getName(), getLinkageName(),
getFile(), getLine(), getType(), isLocalToUnit(), getFile(), getLine(), getType(), isLocalToUnit(),
isDefinition(), getExpr(), isDefinition(), getExpr(),
getStaticDataMemberDeclaration()); getStaticDataMemberDeclaration(), getAlignInBits());
} }
public: public:
DEFINE_MDNODE_GET(DIGlobalVariable, DEFINE_MDNODE_GET(DIGlobalVariable,
(DIScope * Scope, StringRef Name, StringRef LinkageName, (DIScope * Scope, StringRef Name, StringRef LinkageName,
DIFile *File, unsigned Line, DITypeRef Type, DIFile *File, unsigned Line, DITypeRef Type,
bool IsLocalToUnit, bool IsDefinition, DIExpression *Expr, bool IsLocalToUnit, bool IsDefinition,
DIDerivedType *StaticDataMemberDeclaration), DIExpression *Expr,
DIDerivedType *StaticDataMemberDeclaration,
uint64_t AlignInBits),
(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
IsDefinition, Expr, StaticDataMemberDeclaration)) IsDefinition, Expr, StaticDataMemberDeclaration,
AlignInBits))
DEFINE_MDNODE_GET(DIGlobalVariable, DEFINE_MDNODE_GET(DIGlobalVariable,
(Metadata * Scope, MDString *Name, MDString *LinkageName, (Metadata * Scope, MDString *Name, MDString *LinkageName,
Metadata *File, unsigned Line, Metadata *Type, Metadata *File, unsigned Line, Metadata *Type,
bool IsLocalToUnit, bool IsDefinition, Metadata *Expr, bool IsLocalToUnit, bool IsDefinition,
Metadata *StaticDataMemberDeclaration), Metadata *Expr, Metadata *StaticDataMemberDeclaration,
uint64_t AlignInBits),
(Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit, (Scope, Name, LinkageName, File, Line, Type, IsLocalToUnit,
IsDefinition, Expr, StaticDataMemberDeclaration)) IsDefinition, Expr, StaticDataMemberDeclaration,
AlignInBits))
TempDIGlobalVariable clone() const { return cloneImpl(); } TempDIGlobalVariable clone() const { return cloneImpl(); }
@ -2109,9 +2120,10 @@ class DILocalVariable : public DIVariable {
DIFlags Flags; DIFlags Flags;
DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line, DILocalVariable(LLVMContext &C, StorageType Storage, unsigned Line,
unsigned Arg, DIFlags Flags, ArrayRef<Metadata *> Ops) unsigned Arg, DIFlags Flags, uint64_t AlignInBits,
: DIVariable(C, DILocalVariableKind, Storage, Line, Ops), Arg(Arg), ArrayRef<Metadata *> Ops)
Flags(Flags) { : DIVariable(C, DILocalVariableKind, Storage, Line, Ops, AlignInBits),
Arg(Arg), Flags(Flags) {
assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range"); assert(Arg < (1 << 16) && "DILocalVariable: Arg out of range");
} }
~DILocalVariable() = default; ~DILocalVariable() = default;
@ -2119,33 +2131,34 @@ class DILocalVariable : public DIVariable {
static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope, static DILocalVariable *getImpl(LLVMContext &Context, DIScope *Scope,
StringRef Name, DIFile *File, unsigned Line, StringRef Name, DIFile *File, unsigned Line,
DITypeRef Type, unsigned Arg, DIFlags Flags, DITypeRef Type, unsigned Arg, DIFlags Flags,
StorageType Storage, uint64_t AlignInBits, StorageType Storage,
bool ShouldCreate = true) { bool ShouldCreate = true) {
return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File, return getImpl(Context, Scope, getCanonicalMDString(Context, Name), File,
Line, Type, Arg, Flags, Storage, ShouldCreate); Line, Type, Arg, Flags, AlignInBits, Storage, ShouldCreate);
} }
static DILocalVariable *getImpl(LLVMContext &Context, Metadata *Scope, static DILocalVariable *getImpl(LLVMContext &Context, Metadata *Scope,
MDString *Name, Metadata *File, unsigned Line, MDString *Name, Metadata *File, unsigned Line,
Metadata *Type, unsigned Arg, DIFlags Flags, Metadata *Type, unsigned Arg, DIFlags Flags,
StorageType Storage, uint64_t AlignInBits, StorageType Storage,
bool ShouldCreate = true); bool ShouldCreate = true);
TempDILocalVariable cloneImpl() const { TempDILocalVariable cloneImpl() const {
return getTemporary(getContext(), getScope(), getName(), getFile(), return getTemporary(getContext(), getScope(), getName(), getFile(),
getLine(), getType(), getArg(), getFlags()); getLine(), getType(), getArg(), getFlags(),
getAlignInBits());
} }
public: public:
DEFINE_MDNODE_GET(DILocalVariable, DEFINE_MDNODE_GET(DILocalVariable,
(DILocalScope * Scope, StringRef Name, DIFile *File, (DILocalScope * Scope, StringRef Name, DIFile *File,
unsigned Line, DITypeRef Type, unsigned Arg, unsigned Line, DITypeRef Type, unsigned Arg,
DIFlags Flags), DIFlags Flags, uint64_t AlignInBits),
(Scope, Name, File, Line, Type, Arg, Flags)) (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
DEFINE_MDNODE_GET(DILocalVariable, DEFINE_MDNODE_GET(DILocalVariable,
(Metadata * Scope, MDString *Name, Metadata *File, (Metadata * Scope, MDString *Name, Metadata *File,
unsigned Line, Metadata *Type, unsigned Arg, unsigned Line, Metadata *Type, unsigned Arg,
DIFlags Flags), DIFlags Flags, uint64_t AlignInBits),
(Scope, Name, File, Line, Type, Arg, Flags)) (Scope, Name, File, Line, Type, Arg, Flags, AlignInBits))
TempDILocalVariable clone() const { return cloneImpl(); } TempDILocalVariable clone() const { return cloneImpl(); }

View File

@ -4186,7 +4186,7 @@ bool LLParser::ParseDITemplateValueParameter(MDNode *&Result, bool IsDistinct) {
/// ::= !DIGlobalVariable(scope: !0, name: "foo", linkageName: "foo", /// ::= !DIGlobalVariable(scope: !0, name: "foo", linkageName: "foo",
/// file: !1, line: 7, type: !2, isLocal: false, /// file: !1, line: 7, type: !2, isLocal: false,
/// isDefinition: true, variable: i32* @foo, /// isDefinition: true, variable: i32* @foo,
/// declaration: !3) /// declaration: !3, align: 8)
bool LLParser::ParseDIGlobalVariable(MDNode *&Result, bool IsDistinct) { bool LLParser::ParseDIGlobalVariable(MDNode *&Result, bool IsDistinct) {
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
REQUIRED(name, MDStringField, (/* AllowEmpty */ false)); \ REQUIRED(name, MDStringField, (/* AllowEmpty */ false)); \
@ -4198,22 +4198,26 @@ bool LLParser::ParseDIGlobalVariable(MDNode *&Result, bool IsDistinct) {
OPTIONAL(isLocal, MDBoolField, ); \ OPTIONAL(isLocal, MDBoolField, ); \
OPTIONAL(isDefinition, MDBoolField, (true)); \ OPTIONAL(isDefinition, MDBoolField, (true)); \
OPTIONAL(expr, MDField, ); \ OPTIONAL(expr, MDField, ); \
OPTIONAL(declaration, MDField, ); OPTIONAL(declaration, MDField, ); \
OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX));
PARSE_MD_FIELDS(); PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS #undef VISIT_MD_FIELDS
Result = GET_OR_DISTINCT(DIGlobalVariable, Result = GET_OR_DISTINCT(DIGlobalVariable,
(Context, scope.Val, name.Val, linkageName.Val, (Context, scope.Val, name.Val, linkageName.Val,
file.Val, line.Val, type.Val, isLocal.Val, file.Val, line.Val, type.Val, isLocal.Val,
isDefinition.Val, expr.Val, declaration.Val)); isDefinition.Val, expr.Val, declaration.Val,
align.Val));
return false; return false;
} }
/// ParseDILocalVariable: /// ParseDILocalVariable:
/// ::= !DILocalVariable(arg: 7, scope: !0, name: "foo", /// ::= !DILocalVariable(arg: 7, scope: !0, name: "foo",
/// file: !1, line: 7, type: !2, arg: 2, flags: 7) /// file: !1, line: 7, type: !2, arg: 2, flags: 7,
/// align: 8)
/// ::= !DILocalVariable(scope: !0, name: "foo", /// ::= !DILocalVariable(scope: !0, name: "foo",
/// file: !1, line: 7, type: !2, arg: 2, flags: 7) /// file: !1, line: 7, type: !2, arg: 2, flags: 7,
/// align: 8)
bool LLParser::ParseDILocalVariable(MDNode *&Result, bool IsDistinct) { bool LLParser::ParseDILocalVariable(MDNode *&Result, bool IsDistinct) {
#define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \
REQUIRED(scope, MDField, (/* AllowNull */ false)); \ REQUIRED(scope, MDField, (/* AllowNull */ false)); \
@ -4222,13 +4226,14 @@ bool LLParser::ParseDILocalVariable(MDNode *&Result, bool IsDistinct) {
OPTIONAL(file, MDField, ); \ OPTIONAL(file, MDField, ); \
OPTIONAL(line, LineField, ); \ OPTIONAL(line, LineField, ); \
OPTIONAL(type, MDField, ); \ OPTIONAL(type, MDField, ); \
OPTIONAL(flags, DIFlagField, ); OPTIONAL(flags, DIFlagField, ); \
OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX));
PARSE_MD_FIELDS(); PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS #undef VISIT_MD_FIELDS
Result = GET_OR_DISTINCT(DILocalVariable, Result = GET_OR_DISTINCT(DILocalVariable,
(Context, scope.Val, name.Val, file.Val, line.Val, (Context, scope.Val, name.Val, file.Val, line.Val,
type.Val, arg.Val, flags.Val)); type.Val, arg.Val, flags.Val, align.Val));
return false; return false;
} }

View File

@ -2734,7 +2734,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
break; break;
} }
case bitc::METADATA_GLOBAL_VAR: { case bitc::METADATA_GLOBAL_VAR: {
if (Record.size() != 11) if (Record.size() < 11 || Record.size() > 12)
return error("Invalid record"); return error("Invalid record");
IsDistinct = Record[0]; IsDistinct = Record[0];
@ -2742,6 +2742,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
// Upgrade old metadata, which stored a global variable reference or a // Upgrade old metadata, which stored a global variable reference or a
// ConstantInt here. // ConstantInt here.
Metadata *Expr = getMDOrNull(Record[9]); Metadata *Expr = getMDOrNull(Record[9]);
uint64_t AlignInBits = (Record.size() > 11) ? Record[11] : 0;
GlobalVariable *Attach = nullptr; GlobalVariable *Attach = nullptr;
if (auto *CMD = dyn_cast_or_null<ConstantAsMetadata>(Expr)) { if (auto *CMD = dyn_cast_or_null<ConstantAsMetadata>(Expr)) {
if (auto *GV = dyn_cast<GlobalVariable>(CMD->getValue())) { if (auto *GV = dyn_cast<GlobalVariable>(CMD->getValue())) {
@ -2761,7 +2762,7 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
(Context, getMDOrNull(Record[1]), getMDString(Record[2]), (Context, getMDOrNull(Record[1]), getMDString(Record[2]),
getMDString(Record[3]), getMDOrNull(Record[4]), Record[5], getMDString(Record[3]), getMDOrNull(Record[4]), Record[5],
getDITypeRefOrNull(Record[6]), Record[7], Record[8], Expr, getDITypeRefOrNull(Record[6]), Record[7], Record[8], Expr,
getMDOrNull(Record[10]))); getMDOrNull(Record[10]), AlignInBits));
MetadataList.assignValue(DGV, NextMetadataNo++); MetadataList.assignValue(DGV, NextMetadataNo++);
if (Attach) if (Attach)
@ -2774,18 +2775,21 @@ std::error_code BitcodeReader::parseMetadata(bool ModuleLevel) {
if (Record.size() < 8 || Record.size() > 10) if (Record.size() < 8 || Record.size() > 10)
return error("Invalid record"); return error("Invalid record");
IsDistinct = Record[0] & 1;
bool HasAlignment = Record[0] & 2;
// 2nd field used to be an artificial tag, either DW_TAG_auto_variable or // 2nd field used to be an artificial tag, either DW_TAG_auto_variable or
// DW_TAG_arg_variable. // DW_TAG_arg_variable, if we have alignment flag encoded it means, that
IsDistinct = Record[0]; // this is newer version of record which doesn't have artifical tag.
bool HasTag = Record.size() > 8; bool HasTag = !HasAlignment && Record.size() > 8;
DINode::DIFlags Flags = static_cast<DINode::DIFlags>(Record[7 + HasTag]); DINode::DIFlags Flags = static_cast<DINode::DIFlags>(Record[7 + HasTag]);
uint64_t AlignInBits = HasAlignment ? Record[8 + HasTag] : 0;
MetadataList.assignValue( MetadataList.assignValue(
GET_OR_DISTINCT(DILocalVariable, GET_OR_DISTINCT(DILocalVariable,
(Context, getMDOrNull(Record[1 + HasTag]), (Context, getMDOrNull(Record[1 + HasTag]),
getMDString(Record[2 + HasTag]), getMDString(Record[2 + HasTag]),
getMDOrNull(Record[3 + HasTag]), Record[4 + HasTag], getMDOrNull(Record[3 + HasTag]), Record[4 + HasTag],
getDITypeRefOrNull(Record[5 + HasTag]), getDITypeRefOrNull(Record[5 + HasTag]),
Record[6 + HasTag], Flags)), Record[6 + HasTag], Flags, AlignInBits)),
NextMetadataNo++); NextMetadataNo++);
break; break;
} }

View File

@ -1712,6 +1712,7 @@ void ModuleBitcodeWriter::writeDIGlobalVariable(
Record.push_back(N->isDefinition()); Record.push_back(N->isDefinition());
Record.push_back(VE.getMetadataOrNullID(N->getRawExpr())); Record.push_back(VE.getMetadataOrNullID(N->getRawExpr()));
Record.push_back(VE.getMetadataOrNullID(N->getStaticDataMemberDeclaration())); Record.push_back(VE.getMetadataOrNullID(N->getStaticDataMemberDeclaration()));
Record.push_back(N->getAlignInBits());
Stream.EmitRecord(bitc::METADATA_GLOBAL_VAR, Record, Abbrev); Stream.EmitRecord(bitc::METADATA_GLOBAL_VAR, Record, Abbrev);
Record.clear(); Record.clear();
@ -1720,7 +1721,21 @@ void ModuleBitcodeWriter::writeDIGlobalVariable(
void ModuleBitcodeWriter::writeDILocalVariable( void ModuleBitcodeWriter::writeDILocalVariable(
const DILocalVariable *N, SmallVectorImpl<uint64_t> &Record, const DILocalVariable *N, SmallVectorImpl<uint64_t> &Record,
unsigned Abbrev) { unsigned Abbrev) {
Record.push_back(N->isDistinct()); // In order to support all possible bitcode formats in BitcodeReader we need
// to distiguish the following cases:
// 1) Record has no artificial tag (Record[1]),
// has no obsolete inlinedAt field (Record[9]).
// In this case Record size will be 8, HasAlignment flag is false.
// 2) Record has artificial tag (Record[1]),
// has no obsolete inlignedAt field (Record[9]).
// In this case Record size will be 9, HasAlignment flag is false.
// 3) Record has both artificial tag (Record[1]) and
// obsolete inlignedAt field (Record[9]).
// In this case Record size will be 10, HasAlignment flag is false.
// 4) Record has neither artificial tag, nor inlignedAt field, but
// HasAlignment flag is true and Record[8] contains alignment value.
const uint64_t HasAlignmentFlag = 1 << 1;
Record.push_back(N->isDistinct() | HasAlignmentFlag);
Record.push_back(VE.getMetadataOrNullID(N->getScope())); Record.push_back(VE.getMetadataOrNullID(N->getScope()));
Record.push_back(VE.getMetadataOrNullID(N->getRawName())); Record.push_back(VE.getMetadataOrNullID(N->getRawName()));
Record.push_back(VE.getMetadataOrNullID(N->getFile())); Record.push_back(VE.getMetadataOrNullID(N->getFile()));
@ -1728,6 +1743,7 @@ void ModuleBitcodeWriter::writeDILocalVariable(
Record.push_back(VE.getMetadataOrNullID(N->getType())); Record.push_back(VE.getMetadataOrNullID(N->getType()));
Record.push_back(N->getArg()); Record.push_back(N->getArg());
Record.push_back(N->getFlags()); Record.push_back(N->getFlags());
Record.push_back(N->getAlignInBits());
Stream.EmitRecord(bitc::METADATA_LOCAL_VAR, Record, Abbrev); Stream.EmitRecord(bitc::METADATA_LOCAL_VAR, Record, Abbrev);
Record.clear(); Record.clear();

View File

@ -1404,9 +1404,11 @@ void DwarfUnit::constructMemberDIE(DIE &Buffer, const DIDerivedType *DT) {
addUInt(MemberDie, dwarf::DW_AT_bit_size, None, Size); addUInt(MemberDie, dwarf::DW_AT_bit_size, None, Size);
uint64_t Offset = DT->getOffsetInBits(); uint64_t Offset = DT->getOffsetInBits();
uint32_t Align = DT->getAlignInBits() ? DT->getAlignInBits() // We can't use DT->getAlignInBits() here: AlignInBits for member type
: FieldSize; // is non-zero if and only if alignment was forced (e.g. _Alignas()),
uint32_t AlignMask = ~(Align - 1); // which can't be done with bitfields. Thus we use FieldSize here.
uint32_t AlignInBits = FieldSize;
uint32_t AlignMask = ~(AlignInBits - 1);
// The bits from the start of the storage unit to the start of the field. // The bits from the start of the storage unit to the start of the field.
uint64_t StartBitOffset = Offset - (Offset & AlignMask); uint64_t StartBitOffset = Offset - (Offset & AlignMask);
// The byte offset of the field's aligned storage unit inside the struct. // The byte offset of the field's aligned storage unit inside the struct.

View File

@ -1822,6 +1822,7 @@ static void writeDIGlobalVariable(raw_ostream &Out, const DIGlobalVariable *N,
Printer.printBool("isDefinition", N->isDefinition()); Printer.printBool("isDefinition", N->isDefinition());
Printer.printMetadata("expr", N->getExpr()); Printer.printMetadata("expr", N->getExpr());
Printer.printMetadata("declaration", N->getRawStaticDataMemberDeclaration()); Printer.printMetadata("declaration", N->getRawStaticDataMemberDeclaration());
Printer.printInt("align", N->getAlignInBits());
Out << ")"; Out << ")";
} }
@ -1837,6 +1838,7 @@ static void writeDILocalVariable(raw_ostream &Out, const DILocalVariable *N,
Printer.printInt("line", N->getLine()); Printer.printInt("line", N->getLine());
Printer.printMetadata("type", N->getRawType()); Printer.printMetadata("type", N->getRawType());
Printer.printDIFlags("flags", N->getFlags()); Printer.printDIFlags("flags", N->getFlags());
Printer.printInt("align", N->getAlignInBits());
Out << ")"; Out << ")";
} }

View File

@ -195,11 +195,10 @@ DIBasicType *DIBuilder::createNullPtrType() {
} }
DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits,
uint32_t AlignInBits,
unsigned Encoding) { unsigned Encoding) {
assert(!Name.empty() && "Unable to create type without name"); assert(!Name.empty() && "Unable to create type without name");
return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits, return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits,
AlignInBits, Encoding); 0, Encoding);
} }
DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) { DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) {
@ -277,24 +276,26 @@ static ConstantAsMetadata *getConstantOrNull(Constant *C) {
DIDerivedType *DIBuilder::createBitFieldMemberType( DIDerivedType *DIBuilder::createBitFieldMemberType(
DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber,
uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits,
uint64_t StorageOffsetInBits, DINode::DIFlags Flags, DIType *Ty) { DINode::DIFlags Flags, DIType *Ty) {
Flags |= DINode::FlagBitField; Flags |= DINode::FlagBitField;
return DIDerivedType::get( return DIDerivedType::get(
VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, VMContext, dwarf::DW_TAG_member, Name, File, LineNumber,
getNonCompileUnitScope(Scope), Ty, SizeInBits, AlignInBits, OffsetInBits, getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0,
Flags, ConstantAsMetadata::get(ConstantInt::get( OffsetInBits, Flags,
IntegerType::get(VMContext, 64), StorageOffsetInBits))); ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64),
StorageOffsetInBits)));
} }
DIDerivedType * DIDerivedType *
DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File, DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File,
unsigned LineNumber, DIType *Ty, unsigned LineNumber, DIType *Ty,
DINode::DIFlags Flags, llvm::Constant *Val) { DINode::DIFlags Flags, llvm::Constant *Val,
uint32_t AlignInBits) {
Flags |= DINode::FlagStaticMember; Flags |= DINode::FlagStaticMember;
return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File,
LineNumber, getNonCompileUnitScope(Scope), Ty, 0, 0, LineNumber, getNonCompileUnitScope(Scope), Ty, 0,
0, Flags, getConstantOrNull(Val)); AlignInBits, 0, Flags, getConstantOrNull(Val));
} }
DIDerivedType * DIDerivedType *
@ -535,28 +536,28 @@ static void checkGlobalVariableScope(DIScope *Context) {
DIGlobalVariable *DIBuilder::createGlobalVariable( DIGlobalVariable *DIBuilder::createGlobalVariable(
DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr, unsigned LineNumber, DIType *Ty, bool isLocalToUnit,
MDNode *Decl) { DIExpression *Expr, MDNode *Decl, uint32_t AlignInBits) {
checkGlobalVariableScope(Context); checkGlobalVariableScope(Context);
auto *N = DIGlobalVariable::getDistinct( auto *N = DIGlobalVariable::getDistinct(
VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
LineNumber, Ty, isLocalToUnit, true, Expr, LineNumber, Ty, isLocalToUnit, true, Expr,
cast_or_null<DIDerivedType>(Decl)); cast_or_null<DIDerivedType>(Decl), AlignInBits);
AllGVs.push_back(N); AllGVs.push_back(N);
return N; return N;
} }
DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl( DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl(
DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F,
unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr, unsigned LineNumber, DIType *Ty, bool isLocalToUnit,
MDNode *Decl) { DIExpression *Expr, MDNode *Decl, uint32_t AlignInBits) {
checkGlobalVariableScope(Context); checkGlobalVariableScope(Context);
return DIGlobalVariable::getTemporary( return DIGlobalVariable::getTemporary(
VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F,
LineNumber, Ty, isLocalToUnit, false, Expr, LineNumber, Ty, isLocalToUnit, false, Expr,
cast_or_null<DIDerivedType>(Decl)) cast_or_null<DIDerivedType>(Decl), AlignInBits)
.release(); .release();
} }
@ -564,7 +565,8 @@ static DILocalVariable *createLocalVariable(
LLVMContext &VMContext, LLVMContext &VMContext,
DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables, DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables,
DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File,
unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) { unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags,
uint32_t AlignInBits) {
// FIXME: Why getNonCompileUnitScope()? // FIXME: Why getNonCompileUnitScope()?
// FIXME: Why is "!Context" okay here? // FIXME: Why is "!Context" okay here?
// FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT
@ -573,7 +575,7 @@ static DILocalVariable *createLocalVariable(
auto *Node = auto *Node =
DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name, DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name,
File, LineNo, Ty, ArgNo, Flags); File, LineNo, Ty, ArgNo, Flags, AlignInBits);
if (AlwaysPreserve) { if (AlwaysPreserve) {
// The optimizer may remove local variables. If there is an interest // The optimizer may remove local variables. If there is an interest
// to preserve variable info in such situation then stash it in a // to preserve variable info in such situation then stash it in a
@ -588,10 +590,11 @@ static DILocalVariable *createLocalVariable(
DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name, DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name,
DIFile *File, unsigned LineNo, DIFile *File, unsigned LineNo,
DIType *Ty, bool AlwaysPreserve, DIType *Ty, bool AlwaysPreserve,
DINode::DIFlags Flags) { DINode::DIFlags Flags,
uint32_t AlignInBits) {
return createLocalVariable(VMContext, PreservedVariables, Scope, Name, return createLocalVariable(VMContext, PreservedVariables, Scope, Name,
/* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve,
Flags); Flags, AlignInBits);
} }
DILocalVariable *DIBuilder::createParameterVariable( DILocalVariable *DIBuilder::createParameterVariable(
@ -599,7 +602,8 @@ DILocalVariable *DIBuilder::createParameterVariable(
unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) { unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) {
assert(ArgNo && "Expected non-zero argument number for parameter"); assert(ArgNo && "Expected non-zero argument number for parameter");
return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo, return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo,
File, LineNo, Ty, AlwaysPreserve, Flags); File, LineNo, Ty, AlwaysPreserve, Flags,
/* AlignInBits */0);
} }
DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) { DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) {

View File

@ -510,16 +510,18 @@ DIGlobalVariable::getImpl(LLVMContext &Context, Metadata *Scope, MDString *Name,
Metadata *Type, bool IsLocalToUnit, bool IsDefinition, Metadata *Type, bool IsLocalToUnit, bool IsDefinition,
Metadata *Variable, Metadata *Variable,
Metadata *StaticDataMemberDeclaration, Metadata *StaticDataMemberDeclaration,
uint64_t AlignInBits,
StorageType Storage, bool ShouldCreate) { StorageType Storage, bool ShouldCreate) {
assert(isCanonical(Name) && "Expected canonical MDString"); assert(isCanonical(Name) && "Expected canonical MDString");
assert(isCanonical(LinkageName) && "Expected canonical MDString"); assert(isCanonical(LinkageName) && "Expected canonical MDString");
DEFINE_GETIMPL_LOOKUP(DIGlobalVariable, DEFINE_GETIMPL_LOOKUP(DIGlobalVariable,
(Scope, Name, LinkageName, File, Line, Type, (Scope, Name, LinkageName, File, Line, Type,
IsLocalToUnit, IsDefinition, Variable, IsLocalToUnit, IsDefinition, Variable,
StaticDataMemberDeclaration)); StaticDataMemberDeclaration, AlignInBits));
Metadata *Ops[] = {Scope, Name, File, Type, Metadata *Ops[] = {Scope, Name, File, Type,
Name, LinkageName, Variable, StaticDataMemberDeclaration}; Name, LinkageName, Variable, StaticDataMemberDeclaration};
DEFINE_GETIMPL_STORE(DIGlobalVariable, (Line, IsLocalToUnit, IsDefinition), DEFINE_GETIMPL_STORE(DIGlobalVariable,
(Line, IsLocalToUnit, IsDefinition, AlignInBits),
Ops); Ops);
} }
@ -527,6 +529,7 @@ DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
MDString *Name, Metadata *File, MDString *Name, Metadata *File,
unsigned Line, Metadata *Type, unsigned Line, Metadata *Type,
unsigned Arg, DIFlags Flags, unsigned Arg, DIFlags Flags,
uint64_t AlignInBits,
StorageType Storage, StorageType Storage,
bool ShouldCreate) { bool ShouldCreate) {
// 64K ought to be enough for any frontend. // 64K ought to be enough for any frontend.
@ -535,9 +538,10 @@ DILocalVariable *DILocalVariable::getImpl(LLVMContext &Context, Metadata *Scope,
assert(Scope && "Expected scope"); assert(Scope && "Expected scope");
assert(isCanonical(Name) && "Expected canonical MDString"); assert(isCanonical(Name) && "Expected canonical MDString");
DEFINE_GETIMPL_LOOKUP(DILocalVariable, DEFINE_GETIMPL_LOOKUP(DILocalVariable,
(Scope, Name, File, Line, Type, Arg, Flags)); (Scope, Name, File, Line, Type, Arg, Flags,
AlignInBits));
Metadata *Ops[] = {Scope, Name, File, Type}; Metadata *Ops[] = {Scope, Name, File, Type};
DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags), Ops); DEFINE_GETIMPL_STORE(DILocalVariable, (Line, Arg, Flags, AlignInBits), Ops);
} }
DIExpression *DIExpression::getImpl(LLVMContext &Context, DIExpression *DIExpression::getImpl(LLVMContext &Context,

View File

@ -761,22 +761,26 @@ template <> struct MDNodeKeyImpl<DIGlobalVariable> {
bool IsDefinition; bool IsDefinition;
Metadata *Expr; Metadata *Expr;
Metadata *StaticDataMemberDeclaration; Metadata *StaticDataMemberDeclaration;
uint64_t AlignInBits;
MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName, MDNodeKeyImpl(Metadata *Scope, MDString *Name, MDString *LinkageName,
Metadata *File, unsigned Line, Metadata *Type, Metadata *File, unsigned Line, Metadata *Type,
bool IsLocalToUnit, bool IsDefinition, Metadata *Expr, bool IsLocalToUnit, bool IsDefinition,
Metadata *StaticDataMemberDeclaration) Metadata *Expr, Metadata *StaticDataMemberDeclaration,
uint64_t AlignInBits)
: Scope(Scope), Name(Name), LinkageName(LinkageName), File(File), : Scope(Scope), Name(Name), LinkageName(LinkageName), File(File),
Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit), Line(Line), Type(Type), IsLocalToUnit(IsLocalToUnit),
IsDefinition(IsDefinition), Expr(Expr), IsDefinition(IsDefinition), Expr(Expr),
StaticDataMemberDeclaration(StaticDataMemberDeclaration) {} StaticDataMemberDeclaration(StaticDataMemberDeclaration),
AlignInBits(AlignInBits) {}
MDNodeKeyImpl(const DIGlobalVariable *N) MDNodeKeyImpl(const DIGlobalVariable *N)
: Scope(N->getRawScope()), Name(N->getRawName()), : Scope(N->getRawScope()), Name(N->getRawName()),
LinkageName(N->getRawLinkageName()), File(N->getRawFile()), LinkageName(N->getRawLinkageName()), File(N->getRawFile()),
Line(N->getLine()), Type(N->getRawType()), Line(N->getLine()), Type(N->getRawType()),
IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()), IsLocalToUnit(N->isLocalToUnit()), IsDefinition(N->isDefinition()),
Expr(N->getRawExpr()), Expr(N->getRawExpr()),
StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()) {} StaticDataMemberDeclaration(N->getRawStaticDataMemberDeclaration()),
AlignInBits(N->getAlignInBits()) {}
bool isKeyOf(const DIGlobalVariable *RHS) const { bool isKeyOf(const DIGlobalVariable *RHS) const {
return Scope == RHS->getRawScope() && Name == RHS->getRawName() && return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
@ -786,11 +790,19 @@ template <> struct MDNodeKeyImpl<DIGlobalVariable> {
IsDefinition == RHS->isDefinition() && IsDefinition == RHS->isDefinition() &&
Expr == RHS->getRawExpr() && Expr == RHS->getRawExpr() &&
StaticDataMemberDeclaration == StaticDataMemberDeclaration ==
RHS->getRawStaticDataMemberDeclaration(); RHS->getRawStaticDataMemberDeclaration() &&
AlignInBits == RHS->getAlignInBits();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
// We do not use AlignInBits in hashing function here on purpose:
// in most cases this param for local variable is zero (for function param
// it is always zero). This leads to lots of hash collisions and errors on
// cases with lots of similar variables.
// clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
// generated IR is random for each run and test fails with Align included.
// TODO: make hashing work fine with such situations
return hash_combine(Scope, Name, LinkageName, File, Line, Type, return hash_combine(Scope, Name, LinkageName, File, Line, Type,
IsLocalToUnit, IsDefinition, Expr, IsLocalToUnit, IsDefinition, /* AlignInBits, */ Expr,
StaticDataMemberDeclaration); StaticDataMemberDeclaration);
} }
}; };
@ -803,23 +815,32 @@ template <> struct MDNodeKeyImpl<DILocalVariable> {
Metadata *Type; Metadata *Type;
unsigned Arg; unsigned Arg;
unsigned Flags; unsigned Flags;
uint64_t AlignInBits;
MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line, MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line,
Metadata *Type, unsigned Arg, unsigned Flags) Metadata *Type, unsigned Arg, unsigned Flags,
uint64_t AlignInBits)
: Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg), : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg),
Flags(Flags) {} Flags(Flags), AlignInBits(AlignInBits) {}
MDNodeKeyImpl(const DILocalVariable *N) MDNodeKeyImpl(const DILocalVariable *N)
: Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()), : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()),
Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()), Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()),
Flags(N->getFlags()) {} Flags(N->getFlags()), AlignInBits(N->getAlignInBits()) {}
bool isKeyOf(const DILocalVariable *RHS) const { bool isKeyOf(const DILocalVariable *RHS) const {
return Scope == RHS->getRawScope() && Name == RHS->getRawName() && return Scope == RHS->getRawScope() && Name == RHS->getRawName() &&
File == RHS->getRawFile() && Line == RHS->getLine() && File == RHS->getRawFile() && Line == RHS->getLine() &&
Type == RHS->getRawType() && Arg == RHS->getArg() && Type == RHS->getRawType() && Arg == RHS->getArg() &&
Flags == RHS->getFlags(); Flags == RHS->getFlags() && AlignInBits == RHS->getAlignInBits();
} }
unsigned getHashValue() const { unsigned getHashValue() const {
// We do not use AlignInBits in hashing function here on purpose:
// in most cases this param for local variable is zero (for function param
// it is always zero). This leads to lots of hash collisions and errors on
// cases with lots of similar variables.
// clang/test/CodeGen/debug-info-257-args.c is an example of this problem,
// generated IR is random for each run and test fails with Align included.
// TODO: make hashing work fine with such situations
return hash_combine(Scope, Name, File, Line, Type, Arg, Flags); return hash_combine(Scope, Name, File, Line, Type, Arg, Flags);
} }
}; };

View File

@ -12,10 +12,10 @@
!3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!4 = distinct !{} !4 = distinct !{}
; CHECK: !5 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !0, file: !2, line: 7, type: !3, isLocal: true, isDefinition: false) ; CHECK: !5 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !0, file: !2, line: 7, type: !3, isLocal: true, isDefinition: false, align: 32)
!5 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !0, !5 = !DIGlobalVariable(name: "foo", linkageName: "foo", scope: !0,
file: !2, line: 7, type: !3, isLocal: true, file: !2, line: 7, type: !3, isLocal: true,
isDefinition: false) isDefinition: false, align: 32)
; CHECK: !6 = !DIGlobalVariable(name: "foo", scope: !0, isLocal: false, isDefinition: true, expr: !7) ; CHECK: !6 = !DIGlobalVariable(name: "foo", scope: !0, isLocal: false, isDefinition: true, expr: !7)
; CHECK: !7 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value) ; CHECK: !7 = !DIExpression(DW_OP_constu, 42, DW_OP_stack_value)

View File

@ -18,11 +18,11 @@
!3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!4 = !DILocation(scope: !0) !4 = !DILocation(scope: !0)
; CHECK: !5 = !DILocalVariable(name: "foo", arg: 3, scope: !0, file: !2, line: 7, type: !3, flags: DIFlagArtificial) ; CHECK: !5 = !DILocalVariable(name: "foo", arg: 3, scope: !0, file: !2, line: 7, type: !3, flags: DIFlagArtificial, align: 32)
; CHECK: !6 = !DILocalVariable(name: "foo", scope: !0, file: !2, line: 7, type: !3, flags: DIFlagArtificial) ; CHECK: !6 = !DILocalVariable(name: "foo", scope: !0, file: !2, line: 7, type: !3, flags: DIFlagArtificial)
!5 = !DILocalVariable(name: "foo", arg: 3, !5 = !DILocalVariable(name: "foo", arg: 3,
scope: !0, file: !2, line: 7, type: !3, scope: !0, file: !2, line: 7, type: !3,
flags: DIFlagArtificial) flags: DIFlagArtificial, align: 32)
!6 = !DILocalVariable(name: "foo", scope: !0, !6 = !DILocalVariable(name: "foo", scope: !0,
file: !2, line: 7, type: !3, flags: DIFlagArtificial) file: !2, line: 7, type: !3, flags: DIFlagArtificial)

View File

@ -0,0 +1,43 @@
; RUN: llvm-dis -o - %s.bc | FileCheck %s
; CHECK: !9 = !DILocalVariable(name: "i", scope: !6, file: !1, line: 3, type: !10)
; CHECK: !10 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
source_filename = "test.cpp"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
; Function Attrs: nounwind uwtable
define void @_Z1fv() #0 !dbg !6 {
entry:
%i = alloca i32, align 4
call void @llvm.dbg.declare(metadata i32* %i, metadata !10, metadata !12), !dbg !13
store i32 42, i32* %i, align 4, !dbg !13
ret void, !dbg !14
}
; Function Attrs: nounwind readnone
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
attributes #0 = { nounwind uwtable }
attributes #1 = { nounwind readnone }
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4}
!llvm.ident = !{!5}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.1 (http://llvm.org/git/clang.git c3709e72d22432f53f8e2f14354def31a96734fe)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
!1 = !DIFile(filename: "test.cpp", directory: "/tmp")
!2 = !{}
!3 = !{i32 2, !"Dwarf Version", i32 4}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !{!"clang version 3.9.1 (http://llvm.org/git/clang.git c3709e72d22432f53f8e2f14354def31a96734fe)"}
!6 = distinct !DISubprogram(name: "f", linkageName: "_Z1fv", scope: !7, file: !7, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
!7 = !DIFile(filename: "test.cpp", directory: "/tmp")
!8 = !DISubroutineType(types: !9)
!9 = !{null}
!10 = !DILocalVariable(name: "i", scope: !6, file: !7, line: 3, type: !11)
!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!12 = !DIExpression()
!13 = !DILocation(line: 3, column: 7, scope: !6)
!14 = !DILocation(line: 4, column: 1, scope: !6)

View File

View File

@ -60,13 +60,13 @@ target triple = "aarch64_be--linux-gnu"
!3 = !{!4} !3 = !{!4}
!4 = !DIGlobalVariable(name: "b", scope: !0, file: !5, line: 8, type: !6, isLocal: false, isDefinition: true) !4 = !DIGlobalVariable(name: "b", scope: !0, file: !5, line: 8, type: !6, isLocal: false, isDefinition: true)
!5 = !DIFile(filename: "bitfields.c", directory: "/") !5 = !DIFile(filename: "bitfields.c", directory: "/")
!6 = !DICompositeType(tag: DW_TAG_structure_type, name: "bitfield", file: !5, line: 1, size: 96, align: 32, elements: !7) !6 = !DICompositeType(tag: DW_TAG_structure_type, name: "bitfield", file: !5, line: 1, size: 96, elements: !7)
!7 = !{!8, !10, !11, !12} !7 = !{!8, !10, !11, !12}
!8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !5, line: 2, baseType: !9, size: 2, align: 32) !8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !5, line: 2, baseType: !9, size: 2)
!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !5, line: 3, baseType: !9, size: 32, align: 32, offset: 32) !10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !5, line: 3, baseType: !9, size: 32, offset: 32)
!11 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !6, file: !5, line: 4, baseType: !9, size: 1, align: 32, offset: 64) !11 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !6, file: !5, line: 4, baseType: !9, size: 1, offset: 64)
!12 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !6, file: !5, line: 5, baseType: !9, size: 28, align: 32, offset: 65) !12 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !6, file: !5, line: 5, baseType: !9, size: 28, offset: 65)
!13 = !{i32 2, !"Dwarf Version", i32 2} !13 = !{i32 2, !"Dwarf Version", i32 2}
!14 = !{i32 2, !"Debug Info Version", i32 3} !14 = !{i32 2, !"Debug Info Version", i32 3}
!15 = !{i32 1, !"PIC Level", i32 2} !15 = !{i32 1, !"PIC Level", i32 2}

View File

@ -23,29 +23,29 @@ target datalayout = "E-m:e-p:32:32-i64:64-v128:64:128-n32-S64"
!2 = !{} !2 = !{}
!3 = !{!4} !3 = !{!4}
!4 = distinct !DIGlobalVariable(name: "s", scope: !0, file: !1, line: 6, type: !5, isLocal: false, isDefinition: true) !4 = distinct !DIGlobalVariable(name: "s", scope: !0, file: !1, line: 6, type: !5, isLocal: false, isDefinition: true)
!5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 1, size: 32, align: 32, elements: !6) !5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 1, size: 32, elements: !6)
!6 = !{!7, !9, !10, !11} !6 = !{!7, !9, !10, !11}
; CHECK: DW_TAG_member ; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name{{.*}}"j" ; CHECK-NEXT: DW_AT_name{{.*}}"j"
; CHECK-NOT: DW_TAG ; CHECK-NOT: DW_TAG
; CHECK: DW_AT_data_bit_offset [DW_FORM_data1] (0x00) ; CHECK: DW_AT_data_bit_offset [DW_FORM_data1] (0x00)
!7 = !DIDerivedType(tag: DW_TAG_member, name: "j", scope: !5, file: !1, line: 2, baseType: !8, size: 5, align: 32) !7 = !DIDerivedType(tag: DW_TAG_member, name: "j", scope: !5, file: !1, line: 2, baseType: !8, size: 5)
!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
; CHECK: DW_TAG_member ; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name{{.*}}"k" ; CHECK-NEXT: DW_AT_name{{.*}}"k"
; CHECK-NOT: DW_TAG ; CHECK-NOT: DW_TAG
; CHECK: DW_AT_data_bit_offset [DW_FORM_data1] (0x05) ; CHECK: DW_AT_data_bit_offset [DW_FORM_data1] (0x05)
!9 = !DIDerivedType(tag: DW_TAG_member, name: "k", scope: !5, file: !1, line: 3, baseType: !8, size: 6, align: 32, offset: 5) !9 = !DIDerivedType(tag: DW_TAG_member, name: "k", scope: !5, file: !1, line: 3, baseType: !8, size: 6, offset: 5)
; CHECK: DW_TAG_member ; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name{{.*}}"m" ; CHECK-NEXT: DW_AT_name{{.*}}"m"
; CHECK-NOT: DW_TAG ; CHECK-NOT: DW_TAG
; CHECK: DW_AT_data_bit_offset [DW_FORM_data1] (0x0b) ; CHECK: DW_AT_data_bit_offset [DW_FORM_data1] (0x0b)
!10 = !DIDerivedType(tag: DW_TAG_member, name: "m", scope: !5, file: !1, line: 4, baseType: !8, size: 5, align: 32, offset: 11) !10 = !DIDerivedType(tag: DW_TAG_member, name: "m", scope: !5, file: !1, line: 4, baseType: !8, size: 5, offset: 11)
; CHECK: DW_TAG_member ; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name{{.*}}"n" ; CHECK-NEXT: DW_AT_name{{.*}}"n"
; CHECK-NOT: DW_TAG ; CHECK-NOT: DW_TAG
; CHECK: DW_AT_data_bit_offset [DW_FORM_data1] (0x10) ; CHECK: DW_AT_data_bit_offset [DW_FORM_data1] (0x10)
!11 = !DIDerivedType(tag: DW_TAG_member, name: "n", scope: !5, file: !1, line: 5, baseType: !8, size: 8, align: 32, offset: 16) !11 = !DIDerivedType(tag: DW_TAG_member, name: "n", scope: !5, file: !1, line: 5, baseType: !8, size: 8, offset: 16)
!12 = !{i32 2, !"Dwarf Version", i32 4} !12 = !{i32 2, !"Dwarf Version", i32 4}
!13 = !{i32 2, !"Debug Info Version", i32 3} !13 = !{i32 2, !"Debug Info Version", i32 3}
!14 = !{i32 1, !"PIC Level", i32 2} !14 = !{i32 1, !"PIC Level", i32 2}

View File

@ -195,33 +195,33 @@ target triple = "x86_64-pc-windows-msvc18.0.0"
!3 = !{!4, !10, !29} !3 = !{!4, !10, !29}
!4 = distinct !DIGlobalVariable(name: "s0", scope: !0, file: !5, line: 7, type: !6, isLocal: false, isDefinition: true) !4 = distinct !DIGlobalVariable(name: "s0", scope: !0, file: !5, line: 7, type: !6, isLocal: false, isDefinition: true)
!5 = !DIFile(filename: "<stdin>", directory: "/usr/local/google/home/majnemer/llvm/src") !5 = !DIFile(filename: "<stdin>", directory: "/usr/local/google/home/majnemer/llvm/src")
!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S0", file: !5, line: 3, size: 24, align: 8, elements: !7) !6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S0", file: !5, line: 3, size: 24, elements: !7)
!7 = !{!8} !7 = !{!8}
!8 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !6, file: !5, line: 6, baseType: !9, size: 8, align: 16, offset: 16, flags: DIFlagBitField, extraData: i64 8) !8 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !6, file: !5, line: 6, baseType: !9, size: 8, offset: 16, flags: DIFlagBitField, extraData: i64 8)
!9 = !DIBasicType(name: "short", size: 16, align: 16, encoding: DW_ATE_signed) !9 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed)
!10 = distinct !DIGlobalVariable(name: "s1", scope: !0, file: !5, line: 18, type: !11, isLocal: false, isDefinition: true) !10 = distinct !DIGlobalVariable(name: "s1", scope: !0, file: !5, line: 18, type: !11, isLocal: false, isDefinition: true)
!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S1", file: !5, line: 10, size: 128, align: 8, elements: !12) !11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S1", file: !5, line: 10, size: 128, elements: !12)
!12 = !{!13, !18, !19, !21, !22, !23, !28} !12 = !{!13, !18, !19, !21, !22, !23, !28}
!13 = !DIDerivedType(tag: DW_TAG_member, name: "x1", scope: !11, file: !5, line: 11, baseType: !14, size: 16, align: 8) !13 = !DIDerivedType(tag: DW_TAG_member, name: "x1", scope: !11, file: !5, line: 11, baseType: !14, size: 16)
!14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !15, size: 16, align: 8, elements: !16) !14 = !DICompositeType(tag: DW_TAG_array_type, baseType: !15, size: 16, elements: !16)
!15 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char) !15 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
!16 = !{!17} !16 = !{!17}
!17 = !DISubrange(count: 2) !17 = !DISubrange(count: 2)
!18 = !DIDerivedType(tag: DW_TAG_member, name: "x2", scope: !11, file: !5, line: 12, baseType: !15, size: 8, align: 8, offset: 16) !18 = !DIDerivedType(tag: DW_TAG_member, name: "x2", scope: !11, file: !5, line: 12, baseType: !15, size: 8, offset: 16)
!19 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !11, file: !5, line: 13, baseType: !20, size: 23, align: 32, offset: 24, flags: DIFlagBitField, extraData: i64 24) !19 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !11, file: !5, line: 13, baseType: !20, size: 23, offset: 24, flags: DIFlagBitField, extraData: i64 24)
!20 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !20 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!21 = !DIDerivedType(tag: DW_TAG_member, name: "z", scope: !11, file: !5, line: 14, baseType: !20, size: 23, align: 32, offset: 56, flags: DIFlagBitField, extraData: i64 56) !21 = !DIDerivedType(tag: DW_TAG_member, name: "z", scope: !11, file: !5, line: 14, baseType: !20, size: 23, offset: 56, flags: DIFlagBitField, extraData: i64 56)
!22 = !DIDerivedType(tag: DW_TAG_member, name: "w", scope: !11, file: !5, line: 15, baseType: !20, size: 2, align: 32, offset: 79, flags: DIFlagBitField, extraData: i64 56) !22 = !DIDerivedType(tag: DW_TAG_member, name: "w", scope: !11, file: !5, line: 15, baseType: !20, size: 2, offset: 79, flags: DIFlagBitField, extraData: i64 56)
!23 = !DIDerivedType(tag: DW_TAG_member, name: "v", scope: !11, file: !5, line: 16, baseType: !24, size: 24, align: 8, offset: 88) !23 = !DIDerivedType(tag: DW_TAG_member, name: "v", scope: !11, file: !5, line: 16, baseType: !24, size: 24, offset: 88)
!24 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !11, file: !5, line: 16, size: 24, align: 8, elements: !25) !24 = distinct !DICompositeType(tag: DW_TAG_structure_type, scope: !11, file: !5, line: 16, size: 24, elements: !25)
!25 = !{!26, !27} !25 = !{!26, !27}
!26 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !24, file: !5, line: 16, baseType: !15, size: 8, align: 8) !26 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !24, file: !5, line: 16, baseType: !15, size: 8)
!27 = !DIDerivedType(tag: DW_TAG_member, name: "s", scope: !24, file: !5, line: 16, baseType: !9, size: 16, align: 16, offset: 8) !27 = !DIDerivedType(tag: DW_TAG_member, name: "s", scope: !24, file: !5, line: 16, baseType: !9, size: 16, offset: 8)
!28 = !DIDerivedType(tag: DW_TAG_member, name: "u", scope: !11, file: !5, line: 17, baseType: !9, size: 3, align: 16, offset: 112, flags: DIFlagBitField, extraData: i64 112) !28 = !DIDerivedType(tag: DW_TAG_member, name: "u", scope: !11, file: !5, line: 17, baseType: !9, size: 3, offset: 112, flags: DIFlagBitField, extraData: i64 112)
!29 = distinct !DIGlobalVariable(name: "s2", scope: !0, file: !5, line: 24, type: !30, isLocal: false, isDefinition: true) !29 = distinct !DIGlobalVariable(name: "s2", scope: !0, file: !5, line: 24, type: !30, isLocal: false, isDefinition: true)
!30 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S2", file: !5, line: 21, size: 32, align: 8, elements: !31) !30 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S2", file: !5, line: 21, size: 32, elements: !31)
!31 = !{!32} !31 = !{!32}
!32 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !30, file: !5, line: 23, baseType: !20, size: 1, align: 32, flags: DIFlagBitField, extraData: i64 0) !32 = !DIDerivedType(tag: DW_TAG_member, name: "y", scope: !30, file: !5, line: 23, baseType: !20, size: 1, flags: DIFlagBitField, extraData: i64 0)
!33 = !{i32 2, !"CodeView", i32 1} !33 = !{i32 2, !"CodeView", i32 1}
!34 = !{i32 2, !"Debug Info Version", i32 3} !34 = !{i32 2, !"Debug Info Version", i32 3}
!35 = !{i32 1, !"PIC Level", i32 2} !35 = !{i32 1, !"PIC Level", i32 2}

View File

@ -32,7 +32,7 @@ target triple = "x86_64-apple-macosx"
!2 = !{} !2 = !{}
!3 = !{!4} !3 = !{!4}
!4 = distinct !DIGlobalVariable(name: "s", scope: !0, file: !1, line: 8, type: !5, isLocal: false, isDefinition: true) !4 = distinct !DIGlobalVariable(name: "s", scope: !0, file: !1, line: 8, type: !5, isLocal: false, isDefinition: true)
!5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "PackedBits", file: !1, line: 3, size: 40, align: 8, elements: !6) !5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "PackedBits", file: !1, line: 3, size: 40, elements: !6)
!6 = !{!7, !9, !13} !6 = !{!7, !9, !13}
; CHECK: DW_TAG_member ; CHECK: DW_TAG_member
@ -41,9 +41,9 @@ target triple = "x86_64-apple-macosx"
; CHECK-NOT: DW_AT_bit_offset ; CHECK-NOT: DW_AT_bit_offset
; CHECK-NOT: DW_AT_data_bit_offset ; CHECK-NOT: DW_AT_data_bit_offset
; CHECK: DW_AT_data_member_location [DW_FORM_data1] (0x00) ; CHECK: DW_AT_data_member_location [DW_FORM_data1] (0x00)
!7 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !5, file: !1, line: 5, baseType: !8, size: 8, align: 8) !7 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !5, file: !1, line: 5, baseType: !8, size: 8)
!8 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char) !8 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
; CHECK: DW_TAG_member ; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name{{.*}}"b" ; CHECK-NEXT: DW_AT_name{{.*}}"b"
@ -54,11 +54,11 @@ target triple = "x86_64-apple-macosx"
; CHECK-NOT: DW_AT_byte_size ; CHECK-NOT: DW_AT_byte_size
; CHECK-NEXT: DW_AT_data_bit_offset [DW_FORM_data1] (0x08) ; CHECK-NEXT: DW_AT_data_bit_offset [DW_FORM_data1] (0x08)
; CHECK-NOT: DW_AT_data_member_location ; CHECK-NOT: DW_AT_data_member_location
!9 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !5, file: !1, line: 6, baseType: !10, size: 5, align: 32, offset: 8) !9 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !5, file: !1, line: 6, baseType: !10, size: 5, offset: 8)
!10 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint32_t", file: !11, line: 183, baseType: !12) !10 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint32_t", file: !11, line: 183, baseType: !12)
!11 = !DIFile(filename: "/Volumes/Data/llvm/_build.ninja.release/bin/../lib/clang/3.9.0/include/stdint.h", directory: "/Volumes/Data/llvm") !11 = !DIFile(filename: "/Volumes/Data/llvm/_build.ninja.release/bin/../lib/clang/3.9.0/include/stdint.h", directory: "/Volumes/Data/llvm")
!12 = !DIBasicType(name: "unsigned int", size: 32, align: 32, encoding: DW_ATE_unsigned) !12 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
; CHECK: DW_TAG_member ; CHECK: DW_TAG_member
; CHECK-NEXT: DW_AT_name{{.*}}"c" ; CHECK-NEXT: DW_AT_name{{.*}}"c"
@ -69,7 +69,7 @@ target triple = "x86_64-apple-macosx"
; CHECK-NEXT: DW_AT_data_bit_offset [DW_FORM_data1] (0x0d) ; CHECK-NEXT: DW_AT_data_bit_offset [DW_FORM_data1] (0x0d)
; CHECK-NOT: DW_AT_data_member_location ; CHECK-NOT: DW_AT_data_member_location
; CHECK: DW_TAG ; CHECK: DW_TAG
!13 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !5, file: !1, line: 7, baseType: !10, size: 27, align: 32, offset: 13) !13 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !5, file: !1, line: 7, baseType: !10, size: 27, offset: 13)
!14 = !{i32 2, !"Dwarf Version", i32 4} !14 = !{i32 2, !"Dwarf Version", i32 4}
!15 = !{i32 2, !"Debug Info Version", i32 3} !15 = !{i32 2, !"Debug Info Version", i32 3}

View File

@ -60,13 +60,13 @@ target triple = "x86_64-apple-macosx"
!3 = !{!4} !3 = !{!4}
!4 = !DIGlobalVariable(name: "b", scope: !0, file: !5, line: 8, type: !6, isLocal: false, isDefinition: true) !4 = !DIGlobalVariable(name: "b", scope: !0, file: !5, line: 8, type: !6, isLocal: false, isDefinition: true)
!5 = !DIFile(filename: "bitfields.c", directory: "/") !5 = !DIFile(filename: "bitfields.c", directory: "/")
!6 = !DICompositeType(tag: DW_TAG_structure_type, name: "bitfield", file: !5, line: 1, size: 96, align: 32, elements: !7) !6 = !DICompositeType(tag: DW_TAG_structure_type, name: "bitfield", file: !5, line: 1, size: 96, elements: !7)
!7 = !{!8, !10, !11, !12} !7 = !{!8, !10, !11, !12}
!8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !5, line: 2, baseType: !9, size: 2, align: 32) !8 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !6, file: !5, line: 2, baseType: !9, size: 2)
!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !5, line: 3, baseType: !9, size: 32, align: 32, offset: 32) !10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !6, file: !5, line: 3, baseType: !9, size: 32, offset: 32)
!11 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !6, file: !5, line: 4, baseType: !9, size: 1, align: 32, offset: 64) !11 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !6, file: !5, line: 4, baseType: !9, size: 1, offset: 64)
!12 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !6, file: !5, line: 5, baseType: !9, size: 28, align: 32, offset: 65) !12 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !6, file: !5, line: 5, baseType: !9, size: 28, offset: 65)
!13 = !{i32 2, !"Dwarf Version", i32 2} !13 = !{i32 2, !"Dwarf Version", i32 2}
!14 = !{i32 2, !"Debug Info Version", i32 3} !14 = !{i32 2, !"Debug Info Version", i32 3}
!15 = !{i32 1, !"PIC Level", i32 2} !15 = !{i32 1, !"PIC Level", i32 2}

View File

@ -154,45 +154,45 @@ target triple = "x86_64-apple-darwin"
!3 = !{!4, !18, !25, !35} !3 = !{!4, !18, !25, !35}
!4 = !DIGlobalVariable(name: "l0", scope: !0, file: !5, line: 88, type: !6, isLocal: false, isDefinition: true) !4 = !DIGlobalVariable(name: "l0", scope: !0, file: !5, line: 88, type: !6, isLocal: false, isDefinition: true)
!5 = !DIFile(filename: "/llvm/tools/clang/test/CodeGen/debug-info-packed-struct.c", directory: "/llvm/_build.ninja.release") !5 = !DIFile(filename: "/llvm/tools/clang/test/CodeGen/debug-info-packed-struct.c", directory: "/llvm/_build.ninja.release")
!6 = !DICompositeType(tag: DW_TAG_structure_type, name: "layout0", file: !5, line: 15, size: 192, align: 64, elements: !7) !6 = !DICompositeType(tag: DW_TAG_structure_type, name: "layout0", file: !5, line: 15, size: 192, elements: !7)
!7 = !{!8, !10, !17} !7 = !{!8, !10, !17}
!8 = !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs0", scope: !6, file: !5, line: 16, baseType: !9, size: 8, align: 8) !8 = !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs0", scope: !6, file: !5, line: 16, baseType: !9, size: 8)
!9 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char) !9 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
!10 = !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs8", scope: !6, file: !5, line: 17, baseType: !11, size: 64, align: 64, offset: 64) !10 = !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs8", scope: !6, file: !5, line: 17, baseType: !11, size: 64, offset: 64)
!11 = !DICompositeType(tag: DW_TAG_structure_type, name: "size8", file: !5, line: 11, size: 64, align: 64, elements: !12) !11 = !DICompositeType(tag: DW_TAG_structure_type, name: "size8", file: !5, line: 11, size: 64, elements: !12)
!12 = !{!13, !15} !12 = !{!13, !15}
!13 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !11, file: !5, line: 12, baseType: !14, size: 4, align: 32) !13 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !11, file: !5, line: 12, baseType: !14, size: 4)
!14 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!15 = !DIDerivedType(tag: DW_TAG_member, name: "l", scope: !11, file: !5, line: 13, baseType: !16, size: 60, offset: 4) !15 = !DIDerivedType(tag: DW_TAG_member, name: "l", scope: !11, file: !5, line: 13, baseType: !16, size: 60, offset: 4)
!16 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed) !16 = !DIBasicType(name: "long long int", size: 64, encoding: DW_ATE_signed)
!17 = !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs16", scope: !6, file: !5, line: 18, baseType: !14, size: 1, align: 32, offset: 128) !17 = !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs16", scope: !6, file: !5, line: 18, baseType: !14, size: 1, offset: 128)
!18 = !DIGlobalVariable(name: "l1", scope: !0, file: !5, line: 89, type: !19, isLocal: false, isDefinition: true) !18 = !DIGlobalVariable(name: "l1", scope: !0, file: !5, line: 89, type: !19, isLocal: false, isDefinition: true)
!19 = !DICompositeType(tag: DW_TAG_structure_type, name: "layout1", file: !5, line: 34, size: 96, align: 32, elements: !20) !19 = !DICompositeType(tag: DW_TAG_structure_type, name: "layout1", file: !5, line: 34, size: 96, elements: !20)
!20 = !{!21, !22, !24} !20 = !{!21, !22, !24}
!21 = !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs0", scope: !19, file: !5, line: 35, baseType: !9, size: 8, align: 8) !21 = !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs0", scope: !19, file: !5, line: 35, baseType: !9, size: 8)
!22 = !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs1", scope: !19, file: !5, line: 36, baseType: !23, size: 64, align: 8, offset: 8) !22 = !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs1", scope: !19, file: !5, line: 36, baseType: !23, size: 64, offset: 8)
!23 = !DICompositeType(tag: DW_TAG_structure_type, name: "size8_anon", file: !5, line: 30, size: 64, align: 8, elements: !2) !23 = !DICompositeType(tag: DW_TAG_structure_type, name: "size8_anon", file: !5, line: 30, size: 64, elements: !2)
!24 = !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs9", scope: !19, file: !5, line: 37, baseType: !14, size: 1, align: 32, offset: 72) !24 = !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs9", scope: !19, file: !5, line: 37, baseType: !14, size: 1, offset: 72)
!25 = !DIGlobalVariable(name: "l2", scope: !0, file: !5, line: 90, type: !26, isLocal: false, isDefinition: true) !25 = !DIGlobalVariable(name: "l2", scope: !0, file: !5, line: 90, type: !26, isLocal: false, isDefinition: true)
!26 = !DICompositeType(tag: DW_TAG_structure_type, name: "layout2", file: !5, line: 54, size: 80, align: 8, elements: !27) !26 = !DICompositeType(tag: DW_TAG_structure_type, name: "layout2", file: !5, line: 54, size: 80, elements: !27)
!27 = !{!28, !29, !34} !27 = !{!28, !29, !34}
!28 = !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs0", scope: !26, file: !5, line: 55, baseType: !9, size: 8, align: 8) !28 = !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs0", scope: !26, file: !5, line: 55, baseType: !9, size: 8)
!29 = !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs1", scope: !26, file: !5, line: 56, baseType: !30, size: 64, align: 8, offset: 8) !29 = !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs1", scope: !26, file: !5, line: 56, baseType: !30, size: 64, offset: 8)
!30 = !DICompositeType(tag: DW_TAG_structure_type, name: "size8_pack1", file: !5, line: 50, size: 64, align: 8, elements: !31) !30 = !DICompositeType(tag: DW_TAG_structure_type, name: "size8_pack1", file: !5, line: 50, size: 64, elements: !31)
!31 = !{!32, !33} !31 = !{!32, !33}
!32 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !30, file: !5, line: 51, baseType: !14, size: 4, align: 32) !32 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !30, file: !5, line: 51, baseType: !14, size: 4)
!33 = !DIDerivedType(tag: DW_TAG_member, name: "l", scope: !30, file: !5, line: 52, baseType: !16, size: 60, offset: 4) !33 = !DIDerivedType(tag: DW_TAG_member, name: "l", scope: !30, file: !5, line: 52, baseType: !16, size: 60, offset: 4)
!34 = !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs9", scope: !26, file: !5, line: 57, baseType: !14, size: 1, align: 32, offset: 72) !34 = !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs9", scope: !26, file: !5, line: 57, baseType: !14, size: 1, offset: 72)
!35 = !DIGlobalVariable(name: "l3", scope: !0, file: !5, line: 91, type: !36, isLocal: false, isDefinition: true) !35 = !DIGlobalVariable(name: "l3", scope: !0, file: !5, line: 91, type: !36, isLocal: false, isDefinition: true)
!36 = !DICompositeType(tag: DW_TAG_structure_type, name: "layout3", file: !5, line: 76, size: 128, align: 32, elements: !37) !36 = !DICompositeType(tag: DW_TAG_structure_type, name: "layout3", file: !5, line: 76, size: 128, elements: !37)
!37 = !{!38, !39, !44} !37 = !{!38, !39, !44}
!38 = !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs0", scope: !36, file: !5, line: 77, baseType: !9, size: 8, align: 8) !38 = !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs0", scope: !36, file: !5, line: 77, baseType: !9, size: 8)
!39 = !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs4", scope: !36, file: !5, line: 78, baseType: !40, size: 64, align: 32, offset: 32) !39 = !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs4", scope: !36, file: !5, line: 78, baseType: !40, size: 64, offset: 32)
!40 = !DICompositeType(tag: DW_TAG_structure_type, name: "size8_pack4", file: !5, line: 72, size: 64, align: 32, elements: !41) !40 = !DICompositeType(tag: DW_TAG_structure_type, name: "size8_pack4", file: !5, line: 72, size: 64, elements: !41)
!41 = !{!42, !43} !41 = !{!42, !43}
!42 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !40, file: !5, line: 73, baseType: !14, size: 4, align: 32) !42 = !DIDerivedType(tag: DW_TAG_member, name: "i", scope: !40, file: !5, line: 73, baseType: !14, size: 4)
!43 = !DIDerivedType(tag: DW_TAG_member, name: "l", scope: !40, file: !5, line: 74, baseType: !16, size: 60, offset: 4) !43 = !DIDerivedType(tag: DW_TAG_member, name: "l", scope: !40, file: !5, line: 74, baseType: !16, size: 60, offset: 4)
!44 = !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs12", scope: !36, file: !5, line: 79, baseType: !14, size: 1, align: 32, offset: 96) !44 = !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs12", scope: !36, file: !5, line: 79, baseType: !14, size: 1, offset: 96)
!45 = !{i32 2, !"Dwarf Version", i32 2} !45 = !{i32 2, !"Dwarf Version", i32 2}
!46 = !{i32 2, !"Debug Info Version", i32 3} !46 = !{i32 2, !"Debug Info Version", i32 3}
!47 = !{!"clang version 3.7.0 (trunk 240791) (llvm/trunk 240790)"} !47 = !{!"clang version 3.7.0 (trunk 240791) (llvm/trunk 240790)"}

View File

@ -1824,10 +1824,12 @@ TEST_F(DIGlobalVariableTest, get) {
auto *Expr2 = DIExpression::get(Context, {1, 2, 3}); auto *Expr2 = DIExpression::get(Context, {1, 2, 3});
DIDerivedType *StaticDataMemberDeclaration = DIDerivedType *StaticDataMemberDeclaration =
cast<DIDerivedType>(getDerivedType()); cast<DIDerivedType>(getDerivedType());
uint64_t AlignInBits = 8;
auto *N = DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, auto *N = DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, Type, IsLocalToUnit, IsDefinition,
Expr, StaticDataMemberDeclaration); Expr, StaticDataMemberDeclaration,
AlignInBits);
EXPECT_EQ(dwarf::DW_TAG_variable, N->getTag()); EXPECT_EQ(dwarf::DW_TAG_variable, N->getTag());
EXPECT_EQ(Scope, N->getScope()); EXPECT_EQ(Scope, N->getScope());
EXPECT_EQ(Name, N->getName()); EXPECT_EQ(Name, N->getName());
@ -1839,45 +1841,61 @@ TEST_F(DIGlobalVariableTest, get) {
EXPECT_EQ(IsDefinition, N->isDefinition()); EXPECT_EQ(IsDefinition, N->isDefinition());
EXPECT_EQ(Expr, N->getExpr()); EXPECT_EQ(Expr, N->getExpr());
EXPECT_EQ(StaticDataMemberDeclaration, N->getStaticDataMemberDeclaration()); EXPECT_EQ(StaticDataMemberDeclaration, N->getStaticDataMemberDeclaration());
EXPECT_EQ(AlignInBits, N->getAlignInBits());
EXPECT_EQ(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, EXPECT_EQ(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
Line, Type, IsLocalToUnit, IsDefinition, Line, Type, IsLocalToUnit, IsDefinition,
Expr, StaticDataMemberDeclaration)); Expr, StaticDataMemberDeclaration,
AlignInBits));
EXPECT_NE(N, EXPECT_NE(N,
DIGlobalVariable::get(Context, getSubprogram(), Name, LinkageName, DIGlobalVariable::get(Context, getSubprogram(), Name, LinkageName,
File, Line, Type, IsLocalToUnit, IsDefinition, File, Line, Type, IsLocalToUnit, IsDefinition,
Expr, StaticDataMemberDeclaration)); Expr, StaticDataMemberDeclaration,
AlignInBits));
EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, "other", LinkageName, File, EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, "other", LinkageName, File,
Line, Type, IsLocalToUnit, IsDefinition, Line, Type, IsLocalToUnit, IsDefinition,
Expr, StaticDataMemberDeclaration)); Expr, StaticDataMemberDeclaration,
AlignInBits));
EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, "other", File, Line, EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, "other", File, Line,
Type, IsLocalToUnit, IsDefinition, Expr, Type, IsLocalToUnit, IsDefinition, Expr,
StaticDataMemberDeclaration)); StaticDataMemberDeclaration,
AlignInBits));
EXPECT_NE(N, EXPECT_NE(N,
DIGlobalVariable::get(Context, Scope, Name, LinkageName, getFile(), DIGlobalVariable::get(Context, Scope, Name, LinkageName, getFile(),
Line, Type, IsLocalToUnit, IsDefinition, Expr, Line, Type, IsLocalToUnit, IsDefinition, Expr,
StaticDataMemberDeclaration)); StaticDataMemberDeclaration,
AlignInBits));
EXPECT_NE(N, EXPECT_NE(N,
DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
Line + 1, Type, IsLocalToUnit, IsDefinition, Line + 1, Type, IsLocalToUnit, IsDefinition,
Expr, StaticDataMemberDeclaration)); Expr, StaticDataMemberDeclaration,
AlignInBits));
EXPECT_NE(N, EXPECT_NE(N,
DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
getDerivedType(), IsLocalToUnit, IsDefinition, getDerivedType(), IsLocalToUnit, IsDefinition,
Expr, StaticDataMemberDeclaration)); Expr, StaticDataMemberDeclaration,
AlignInBits));
EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
Line, Type, !IsLocalToUnit, IsDefinition, Line, Type, !IsLocalToUnit, IsDefinition,
Expr, StaticDataMemberDeclaration)); Expr, StaticDataMemberDeclaration,
AlignInBits));
EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
Line, Type, IsLocalToUnit, !IsDefinition, Line, Type, IsLocalToUnit, !IsDefinition,
Expr, StaticDataMemberDeclaration)); Expr, StaticDataMemberDeclaration,
AlignInBits));
EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
Line, Type, IsLocalToUnit, IsDefinition, Line, Type, IsLocalToUnit, IsDefinition,
Expr2, StaticDataMemberDeclaration)); Expr2, StaticDataMemberDeclaration,
AlignInBits));
EXPECT_NE(N, EXPECT_NE(N,
DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File, Line,
Type, IsLocalToUnit, IsDefinition, Expr, Type, IsLocalToUnit, IsDefinition, Expr,
cast<DIDerivedType>(getDerivedType()))); cast<DIDerivedType>(getDerivedType()),
AlignInBits));
EXPECT_NE(N, DIGlobalVariable::get(Context, Scope, Name, LinkageName, File,
Line, Type, IsLocalToUnit, IsDefinition,
Expr, StaticDataMemberDeclaration,
(AlignInBits << 1)));
TempDIGlobalVariable Temp = N->clone(); TempDIGlobalVariable Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
@ -1893,9 +1911,11 @@ TEST_F(DILocalVariableTest, get) {
DIType *Type = getDerivedType(); DIType *Type = getDerivedType();
unsigned Arg = 6; unsigned Arg = 6;
DINode::DIFlags Flags = static_cast<DINode::DIFlags>(7); DINode::DIFlags Flags = static_cast<DINode::DIFlags>(7);
uint64_t AlignInBits = 8;
auto *N = auto *N =
DILocalVariable::get(Context, Scope, Name, File, Line, Type, Arg, Flags); DILocalVariable::get(Context, Scope, Name, File, Line, Type, Arg, Flags,
AlignInBits);
EXPECT_TRUE(N->isParameter()); EXPECT_TRUE(N->isParameter());
EXPECT_EQ(Scope, N->getScope()); EXPECT_EQ(Scope, N->getScope());
EXPECT_EQ(Name, N->getName()); EXPECT_EQ(Name, N->getName());
@ -1904,24 +1924,27 @@ TEST_F(DILocalVariableTest, get) {
EXPECT_EQ(Type, N->getType()); EXPECT_EQ(Type, N->getType());
EXPECT_EQ(Arg, N->getArg()); EXPECT_EQ(Arg, N->getArg());
EXPECT_EQ(Flags, N->getFlags()); EXPECT_EQ(Flags, N->getFlags());
EXPECT_EQ(AlignInBits, N->getAlignInBits());
EXPECT_EQ(N, DILocalVariable::get(Context, Scope, Name, File, Line, Type, Arg, EXPECT_EQ(N, DILocalVariable::get(Context, Scope, Name, File, Line, Type, Arg,
Flags)); Flags, AlignInBits));
EXPECT_FALSE( EXPECT_FALSE(
DILocalVariable::get(Context, Scope, Name, File, Line, Type, 0, Flags) DILocalVariable::get(Context, Scope, Name, File, Line, Type, 0, Flags,
->isParameter()); AlignInBits)->isParameter());
EXPECT_NE(N, DILocalVariable::get(Context, getSubprogram(), Name, File, Line, EXPECT_NE(N, DILocalVariable::get(Context, getSubprogram(), Name, File, Line,
Type, Arg, Flags)); Type, Arg, Flags, AlignInBits));
EXPECT_NE(N, DILocalVariable::get(Context, Scope, "other", File, Line, Type, EXPECT_NE(N, DILocalVariable::get(Context, Scope, "other", File, Line, Type,
Arg, Flags)); Arg, Flags, AlignInBits));
EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, getFile(), Line, Type, EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, getFile(), Line, Type,
Arg, Flags)); Arg, Flags, AlignInBits));
EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line + 1, Type, EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line + 1, Type,
Arg, Flags)); Arg, Flags, AlignInBits));
EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line, EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line,
getDerivedType(), Arg, Flags)); getDerivedType(), Arg, Flags, AlignInBits));
EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line, Type, EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line, Type,
Arg + 1, Flags)); Arg + 1, Flags, AlignInBits));
EXPECT_NE(N, DILocalVariable::get(Context, Scope, Name, File, Line, Type,
Arg, Flags, (AlignInBits << 1)));
TempDILocalVariable Temp = N->clone(); TempDILocalVariable Temp = N->clone();
EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp))); EXPECT_EQ(N, MDNode::replaceWithUniqued(std::move(Temp)));
@ -1929,17 +1952,17 @@ TEST_F(DILocalVariableTest, get) {
TEST_F(DILocalVariableTest, getArg256) { TEST_F(DILocalVariableTest, getArg256) {
EXPECT_EQ(255u, DILocalVariable::get(Context, getSubprogram(), "", getFile(), EXPECT_EQ(255u, DILocalVariable::get(Context, getSubprogram(), "", getFile(),
0, nullptr, 255, DINode::FlagZero) 0, nullptr, 255, DINode::FlagZero, 0)
->getArg()); ->getArg());
EXPECT_EQ(256u, DILocalVariable::get(Context, getSubprogram(), "", getFile(), EXPECT_EQ(256u, DILocalVariable::get(Context, getSubprogram(), "", getFile(),
0, nullptr, 256, DINode::FlagZero) 0, nullptr, 256, DINode::FlagZero, 0)
->getArg()); ->getArg());
EXPECT_EQ(257u, DILocalVariable::get(Context, getSubprogram(), "", getFile(), EXPECT_EQ(257u, DILocalVariable::get(Context, getSubprogram(), "", getFile(),
0, nullptr, 257, DINode::FlagZero) 0, nullptr, 257, DINode::FlagZero, 0)
->getArg()); ->getArg());
unsigned Max = UINT16_MAX; unsigned Max = UINT16_MAX;
EXPECT_EQ(Max, DILocalVariable::get(Context, getSubprogram(), "", getFile(), EXPECT_EQ(Max, DILocalVariable::get(Context, getSubprogram(), "", getFile(),
0, nullptr, Max, DINode::FlagZero) 0, nullptr, Max, DINode::FlagZero, 0)
->getArg()); ->getArg());
} }

View File

@ -253,8 +253,7 @@ protected:
Instruction* Terminator = IBuilder.CreateRetVoid(); Instruction* Terminator = IBuilder.CreateRetVoid();
// Create a local variable around the alloca // Create a local variable around the alloca
auto *IntType = auto *IntType = DBuilder.createBasicType("int", 32, dwarf::DW_ATE_signed);
DBuilder.createBasicType("int", 32, 0, dwarf::DW_ATE_signed);
auto *E = DBuilder.createExpression(); auto *E = DBuilder.createExpression();
auto *Variable = auto *Variable =
DBuilder.createAutoVariable(Subprogram, "x", File, 5, IntType, true); DBuilder.createAutoVariable(Subprogram, "x", File, 5, IntType, true);