Verifier: Check composite type template params

Add missing checks for `templateParams:` in `MDCompositeType`.  Pull the
current check for `MDSubprogram` to reduce duplicated code and fix it up
to print a good message when the immediate operand isn't an `MDTuple`
(as a drive-by, make the same fix to `variables:` in `MDSubprogram`).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234177 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan P. N. Exon Smith 2015-04-06 17:04:58 +00:00
parent b508daa9c2
commit fe42afc0e5
4 changed files with 45 additions and 15 deletions

View File

@ -307,6 +307,8 @@ private:
void visitMDLexicalBlockBase(const MDLexicalBlockBase &N); void visitMDLexicalBlockBase(const MDLexicalBlockBase &N);
void visitMDTemplateParameter(const MDTemplateParameter &N); void visitMDTemplateParameter(const MDTemplateParameter &N);
void visitTemplateParams(const MDNode &N, const Metadata &RawParams);
/// \brief Check for a valid string-based type reference. /// \brief Check for a valid string-based type reference.
/// ///
/// Checks if \c MD is a string-based type reference. If it is, keeps track /// Checks if \c MD is a string-based type reference. If it is, keeps track
@ -826,6 +828,15 @@ static bool hasConflictingReferenceFlags(unsigned Flags) {
(Flags & DebugNode::FlagRValueReference); (Flags & DebugNode::FlagRValueReference);
} }
void Verifier::visitTemplateParams(const MDNode &N, const Metadata &RawParams) {
auto *Params = dyn_cast<MDTuple>(&RawParams);
Assert(Params, "invalid template params", &N, &RawParams);
for (Metadata *Op : Params->operands()) {
Assert(Op && isa<MDTemplateParameter>(Op), "invalid template parameter", &N,
Params, Op);
}
}
void Verifier::visitMDCompositeType(const MDCompositeType &N) { void Verifier::visitMDCompositeType(const MDCompositeType &N) {
// Common derived type checks. // Common derived type checks.
visitMDDerivedTypeBase(N); visitMDDerivedTypeBase(N);
@ -846,6 +857,8 @@ void Verifier::visitMDCompositeType(const MDCompositeType &N) {
"invalid composite elements", &N, N.getRawElements()); "invalid composite elements", &N, N.getRawElements());
Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags", Assert(!hasConflictingReferenceFlags(N.getFlags()), "invalid reference flags",
&N); &N);
if (auto *Params = N.getRawTemplateParams())
visitTemplateParams(N, *Params);
} }
void Verifier::visitMDSubroutineType(const MDSubroutineType &N) { void Verifier::visitMDSubroutineType(const MDSubroutineType &N) {
@ -924,21 +937,15 @@ void Verifier::visitMDSubprogram(const MDSubprogram &N) {
Assert(F && FT && isa<FunctionType>(FT->getElementType()), Assert(F && FT && isa<FunctionType>(FT->getElementType()),
"invalid function", &N, F, FT); "invalid function", &N, F, FT);
} }
if (N.getRawTemplateParams()) { if (auto *Params = N.getRawTemplateParams())
auto *Params = dyn_cast<MDTuple>(N.getRawTemplateParams()); visitTemplateParams(N, *Params);
Assert(Params, "invalid template params", &N, Params);
for (Metadata *Op : Params->operands()) {
Assert(Op && isa<MDTemplateParameter>(Op), "invalid template parameter",
&N, Params, Op);
}
}
if (auto *S = N.getRawDeclaration()) { if (auto *S = N.getRawDeclaration()) {
Assert(isa<MDSubprogram>(S) && !cast<MDSubprogram>(S)->isDefinition(), Assert(isa<MDSubprogram>(S) && !cast<MDSubprogram>(S)->isDefinition(),
"invalid subprogram declaration", &N, S); "invalid subprogram declaration", &N, S);
} }
if (N.getRawVariables()) { if (auto *RawVars = N.getRawVariables()) {
auto *Vars = dyn_cast<MDTuple>(N.getRawVariables()); auto *Vars = dyn_cast<MDTuple>(RawVars);
Assert(Vars, "invalid variable list", &N, Vars); Assert(Vars, "invalid variable list", &N, RawVars);
for (Metadata *Op : Vars->operands()) { for (Metadata *Op : Vars->operands()) {
Assert(Op && isa<MDLocalVariable>(Op), "invalid local variable", &N, Vars, Assert(Op && isa<MDLocalVariable>(Op), "invalid local variable", &N, Vars,
Op); Op);

View File

@ -28,11 +28,11 @@
!9 = !MDBasicType() !9 = !MDBasicType()
!10 = !MDBasicType(tag: DW_TAG_base_type, name: "", size: 0, align: 0, encoding: 0) !10 = !MDBasicType(tag: DW_TAG_base_type, name: "", size: 0, align: 0, encoding: 0)
; CHECK-NEXT: !9 = distinct !{} ; CHECK-NEXT: !9 = !MDTemplateTypeParameter(type: !6)
; CHECK-NEXT: !10 = !MDFile(filename: "path/to/file", directory: "/path/to/dir") ; CHECK-NEXT: !10 = !MDFile(filename: "path/to/file", directory: "/path/to/dir")
; CHECK-NEXT: !11 = distinct !{} ; CHECK-NEXT: !11 = distinct !{}
; CHECK-NEXT: !12 = !MDFile(filename: "", directory: "") ; CHECK-NEXT: !12 = !MDFile(filename: "", directory: "")
!11 = distinct !{} !11 = !MDTemplateTypeParameter(type: !7)
!12 = !MDFile(filename: "path/to/file", directory: "/path/to/dir") !12 = !MDFile(filename: "path/to/file", directory: "/path/to/dir")
!13 = distinct !{} !13 = distinct !{}
!14 = !MDFile(filename: "", directory: "") !14 = !MDFile(filename: "", directory: "")
@ -44,7 +44,7 @@
; CHECK-NEXT: !15 = distinct !MDCompositeType(tag: DW_TAG_structure_type, name: "Base", scope: !14, file: !10, line: 3, size: 128, align: 32, offset: 64, flags: DIFlagPublic, elements: !16, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !15, templateParams: !18, identifier: "MangledBase") ; CHECK-NEXT: !15 = distinct !MDCompositeType(tag: DW_TAG_structure_type, name: "Base", scope: !14, file: !10, line: 3, size: 128, align: 32, offset: 64, flags: DIFlagPublic, elements: !16, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !15, templateParams: !18, identifier: "MangledBase")
; CHECK-NEXT: !16 = !{!17} ; CHECK-NEXT: !16 = !{!17}
; CHECK-NEXT: !17 = !MDDerivedType(tag: DW_TAG_member, name: "field", scope: !15, file: !10, line: 4, baseType: !6, size: 32, align: 32, offset: 32, flags: DIFlagPublic) ; CHECK-NEXT: !17 = !MDDerivedType(tag: DW_TAG_member, name: "field", scope: !15, file: !10, line: 4, baseType: !6, size: 32, align: 32, offset: 32, flags: DIFlagPublic)
; CHECK-NEXT: !18 = !{!6} ; CHECK-NEXT: !18 = !{!9}
; CHECK-NEXT: !19 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Derived", scope: !14, file: !10, line: 3, baseType: !15, size: 128, align: 32, offset: 64, flags: DIFlagPublic, elements: !20, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !15, templateParams: !18, identifier: "MangledBase") ; CHECK-NEXT: !19 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Derived", scope: !14, file: !10, line: 3, baseType: !15, size: 128, align: 32, offset: 64, flags: DIFlagPublic, elements: !20, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !15, templateParams: !18, identifier: "MangledBase")
; CHECK-NEXT: !20 = !{!21} ; CHECK-NEXT: !20 = !{!21}
; CHECK-NEXT: !21 = !MDDerivedType(tag: DW_TAG_inheritance, scope: !19, baseType: !15) ; CHECK-NEXT: !21 = !MDDerivedType(tag: DW_TAG_inheritance, scope: !19, baseType: !15)
@ -55,7 +55,7 @@
!17 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Base", scope: !16, file: !12, line: 3, size: 128, align: 32, offset: 64, flags: DIFlagPublic, elements: !18, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !17, templateParams: !20, identifier: "MangledBase") !17 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Base", scope: !16, file: !12, line: 3, size: 128, align: 32, offset: 64, flags: DIFlagPublic, elements: !18, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !17, templateParams: !20, identifier: "MangledBase")
!18 = !{!19} !18 = !{!19}
!19 = !MDDerivedType(tag: DW_TAG_member, name: "field", scope: !17, file: !12, line: 4, baseType: !7, size: 32, align: 32, offset: 32, flags: DIFlagPublic) !19 = !MDDerivedType(tag: DW_TAG_member, name: "field", scope: !17, file: !12, line: 4, baseType: !7, size: 32, align: 32, offset: 32, flags: DIFlagPublic)
!20 = !{!7} !20 = !{!11}
!21 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Derived", scope: !16, file: !12, line: 3, baseType: !17, size: 128, align: 32, offset: 64, flags: DIFlagPublic, elements: !22, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !17, templateParams: !20, identifier: "MangledBase") !21 = !MDCompositeType(tag: DW_TAG_structure_type, name: "Derived", scope: !16, file: !12, line: 3, baseType: !17, size: 128, align: 32, offset: 64, flags: DIFlagPublic, elements: !22, runtimeLang: DW_LANG_C_plus_plus_11, vtableHolder: !17, templateParams: !20, identifier: "MangledBase")
!22 = !{!23} !22 = !{!23}
!23 = !MDDerivedType(tag: DW_TAG_inheritance, scope: !21, baseType: !17) !23 = !MDDerivedType(tag: DW_TAG_inheritance, scope: !21, baseType: !17)

View File

@ -0,0 +1,11 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
; CHECK: invalid template params
; CHECK-NEXT: !2 = !MDCompositeType(
; CHECK-SAME: templateParams: !1
; CHECK-NEXT: !1 = !MDTemplateTypeParameter(
!named = !{!0, !1, !2}
!0 = !MDBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!1 = !MDTemplateTypeParameter(name: "T", type: !0)
!2 = !MDCompositeType(tag: DW_TAG_structure_type, name: "IntTy", size: 32, align: 32, templateParams: !1)

View File

@ -0,0 +1,12 @@
; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
; CHECK: invalid template parameter
; CHECK-NEXT: !2 = !MDCompositeType(
; CHECK-SAME: templateParams: !1
; CHECK-NEXT: !1 = !{!0}
; CHECK-NEXT: !0 = !MDBasicType(
!named = !{!0, !1, !2}
!0 = !MDBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!1 = !{!0}
!2 = !MDCompositeType(tag: DW_TAG_structure_type, name: "IntTy", size: 32, align: 32, templateParams: !1)